--- /dev/null
+// RUN: %clang -fcatch-undefined-behavior %s -O3 -o %t
+// RUN: %t 2>&1 | FileCheck %s --check-prefix=CHECK-MINUS-ONE
+// RUN: %t a 2>&1 | FileCheck %s --check-prefix=CHECK-ZERO
+// RUN: %t a b
+
+int main(int argc, char **argv) {
+ // CHECK-MINUS-ONE: vla.c:9:11: fatal error: variable length array bound evaluates to non-positive value -1
+ // CHECK-ZERO: vla.c:9:11: fatal error: variable length array bound evaluates to non-positive value 0
+ int arr[argc - 2];
+ return 0;
+}
"without returning a value");
Die();
}
+
+void __ubsan::__ubsan_handle_vla_bound_not_positive(VLABoundData *Data,
+ ValueHandle Bound) {
+ Diag(Data->Loc, "variable length array bound evaluates to "
+ "non-positive value %0")
+ << Value(Data->Type, Bound);
+ Die();
+}
/// \brief Handle reaching the end of a value-returning function.
extern "C" void __ubsan_handle_missing_return(UnreachableData *Data);
+struct VLABoundData {
+ SourceLocation Loc;
+ const TypeDescriptor &Type;
+};
+
+/// \brief Handle a VLA with a non-positive bound.
+extern "C" void __ubsan_handle_vla_bound_not_positive(VLABoundData *Data,
+ ValueHandle Bound);
+
}
#endif // UBSAN_HANDLERS_H