[llvm-commits] [compiler-rt] r165582 - in /compiler-rt/trunk/lib/ubsan: lit_tests/Misc/vla.c ubsan_handlers.cc ubsan_handlers.h

Richard Smith richard-llvm at metafoo.co.uk
Tue Oct 9 18:11:00 PDT 2012


Author: rsmith
Date: Tue Oct  9 20:10:59 2012
New Revision: 165582

URL: http://llvm.org/viewvc/llvm-project?rev=165582&view=rev
Log:
-fcatch-undefined-behavior: handler for VLA bound which evaluates to a non-positive value.

Added:
    compiler-rt/trunk/lib/ubsan/lit_tests/Misc/vla.c
Modified:
    compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
    compiler-rt/trunk/lib/ubsan/ubsan_handlers.h

Added: compiler-rt/trunk/lib/ubsan/lit_tests/Misc/vla.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/lit_tests/Misc/vla.c?rev=165582&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/lit_tests/Misc/vla.c (added)
+++ compiler-rt/trunk/lib/ubsan/lit_tests/Misc/vla.c Tue Oct  9 20:10:59 2012
@@ -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;
+}

Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc?rev=165582&r1=165581&r2=165582&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc Tue Oct  9 20:10:59 2012
@@ -126,3 +126,11 @@
                   "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();
+}

Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers.h?rev=165582&r1=165581&r2=165582&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.h Tue Oct  9 20:10:59 2012
@@ -76,6 +76,15 @@
 /// \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





More information about the llvm-commits mailing list