summaryrefslogtreecommitdiff
path: root/lib/ubsan
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-10-10 01:10:59 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-10-10 01:10:59 +0000
commitb04caf1385a4279a7b95d41c3ccefc61842c3633 (patch)
treec784b00b058e7ac16887758d4bde5af8c882d4e6 /lib/ubsan
parented81c21984efb8c1f96c82de1dd5dbcea5d7aa65 (diff)
-fcatch-undefined-behavior: handler for VLA bound which evaluates to a non-positive value.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@165582 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ubsan')
-rw-r--r--lib/ubsan/lit_tests/Misc/vla.c11
-rw-r--r--lib/ubsan/ubsan_handlers.cc8
-rw-r--r--lib/ubsan/ubsan_handlers.h9
3 files changed, 28 insertions, 0 deletions
diff --git a/lib/ubsan/lit_tests/Misc/vla.c b/lib/ubsan/lit_tests/Misc/vla.c
new file mode 100644
index 000000000..4137e804e
--- /dev/null
+++ b/lib/ubsan/lit_tests/Misc/vla.c
@@ -0,0 +1,11 @@
+// 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;
+}
diff --git a/lib/ubsan/ubsan_handlers.cc b/lib/ubsan/ubsan_handlers.cc
index 8aec335b8..fa3c1e0fc 100644
--- a/lib/ubsan/ubsan_handlers.cc
+++ b/lib/ubsan/ubsan_handlers.cc
@@ -126,3 +126,11 @@ void __ubsan::__ubsan_handle_missing_return(UnreachableData *Data) {
"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();
+}
diff --git a/lib/ubsan/ubsan_handlers.h b/lib/ubsan/ubsan_handlers.h
index 8b12bd845..484ffa517 100644
--- a/lib/ubsan/ubsan_handlers.h
+++ b/lib/ubsan/ubsan_handlers.h
@@ -76,6 +76,15 @@ extern "C" void __ubsan_handle_builtin_unreachable(UnreachableData *Data);
/// \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