[llvm-commits] [compiler-rt] r170107 - in /compiler-rt/trunk/lib/ubsan: ubsan_handlers.cc ubsan_handlers.h

Richard Smith richard-llvm at metafoo.co.uk
Wed Dec 12 23:00:14 PST 2012


Author: rsmith
Date: Thu Dec 13 01:00:14 2012
New Revision: 170107

URL: http://llvm.org/viewvc/llvm-project?rev=170107&view=rev
Log:
ubsan: Add -fsanitize=bool and -fsanitize=enum, which check for loads of
bit-patterns which are not valid values for enumerated or boolean types.
These checks are the ubsan analogue of !range metadata.

Modified:
    compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
    compiler-rt/trunk/lib/ubsan/ubsan_handlers.h

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=170107&r1=170106&r2=170107&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc Thu Dec 13 01:00:14 2012
@@ -179,3 +179,15 @@
   __ubsan_handle_float_cast_overflow(Data, From);
   Die();
 }
+
+void __ubsan::__ubsan_handle_load_invalid_value(InvalidValueData *Data,
+                                                ValueHandle Val) {
+  Diag(SourceLocation(), "load of value %0, which is not a valid value for "
+                         "type %1")
+    << Value(Data->Type, Val) << Data->Type;
+}
+void __ubsan::__ubsan_handle_load_invalid_value_abort(InvalidValueData *Data,
+                                                      ValueHandle Val) {
+  __ubsan_handle_load_invalid_value(Data, Val);
+  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=170107&r1=170106&r2=170107&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.h Thu Dec 13 01:00:14 2012
@@ -91,6 +91,14 @@
 /// \brief Handle overflow in a conversion to or from a floating-point type.
 RECOVERABLE(float_cast_overflow, FloatCastOverflowData *Data, ValueHandle From)
 
+struct InvalidValueData {
+  // FIXME: SourceLocation Loc;
+  const TypeDescriptor &Type;
+};
+
+/// \brief Handle a load of an invalid value for the type.
+RECOVERABLE(load_invalid_value, InvalidValueData *Data, ValueHandle Val)
+
 }
 
 #endif // UBSAN_HANDLERS_H





More information about the llvm-commits mailing list