[compiler-rt] r313614 - [ubsan-minimal] Make the interface more compatible with RTUBSan

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 23:46:36 PDT 2017


Author: vedantk
Date: Mon Sep 18 23:46:36 2017
New Revision: 313614

URL: http://llvm.org/viewvc/llvm-project?rev=313614&view=rev
Log:
[ubsan-minimal] Make the interface more compatible with RTUBSan

This eliminates a few inconsistencies between the symbol sets exported
by RTUBSan and RTUBSan_minimal:

  * Handlers for nonnull_return were missing from the minimal RT, and
    are now added in.

  * The minimal runtime exported recoverable handlers for
    builtin_unreachable and missing_return. These are not supposed to
    exist, and are now removed.

Modified:
    compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc
    compiler-rt/trunk/test/ubsan_minimal/TestCases/recover-dedup.cpp

Modified: compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc?rev=313614&r1=313613&r2=313614&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc (original)
+++ compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc Mon Sep 18 23:46:36 2017
@@ -57,17 +57,22 @@ static void abort_with_message(const cha
 
 // FIXME: add caller pc to the error message (possibly as "ubsan: error-type
 // @1234ABCD").
-#define HANDLER(name, msg)                                       \
+#define HANDLER_RECOVER(name, msg)                               \
   INTERFACE void __ubsan_handle_##name##_minimal() {             \
     if (!report_this_error(__builtin_return_address(0))) return; \
     message("ubsan: " msg "\n");                                 \
-  }                                                              \
-                                                                 \
+  }
+
+#define HANDLER_NORECOVER(name, msg)                             \
   INTERFACE void __ubsan_handle_##name##_minimal_abort() {       \
     message("ubsan: " msg "\n");                                 \
     abort_with_message("ubsan: " msg);                           \
   }
 
+#define HANDLER(name, msg)                                       \
+  HANDLER_RECOVER(name, msg)                                     \
+  HANDLER_NORECOVER(name, msg)
+
 HANDLER(type_mismatch, "type-mismatch")
 HANDLER(add_overflow, "add-overflow")
 HANDLER(sub_overflow, "sub-overflow")
@@ -76,14 +81,16 @@ HANDLER(negate_overflow, "negate-overflo
 HANDLER(divrem_overflow, "divrem-overflow")
 HANDLER(shift_out_of_bounds, "shift-out-of-bounds")
 HANDLER(out_of_bounds, "out-of-bounds")
-HANDLER(builtin_unreachable, "builtin-unreachable")
-HANDLER(missing_return, "missing-return")
+HANDLER_RECOVER(builtin_unreachable, "builtin-unreachable")
+HANDLER_RECOVER(missing_return, "missing-return")
 HANDLER(vla_bound_not_positive, "vla-bound-not-positive")
 HANDLER(float_cast_overflow, "float-cast-overflow")
 HANDLER(load_invalid_value, "load-invalid-value")
 HANDLER(invalid_builtin, "invalid-builtin")
 HANDLER(function_type_mismatch, "function-type-mismatch")
 HANDLER(nonnull_arg, "nonnull-arg")
+HANDLER(nonnull_return, "nonnull-return")
 HANDLER(nullability_arg, "nullability-arg")
+HANDLER(nullability_return, "nullability-return")
 HANDLER(pointer_overflow, "pointer-overflow")
 HANDLER(cfi_check_fail, "cfi-check-fail")

Modified: compiler-rt/trunk/test/ubsan_minimal/TestCases/recover-dedup.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan_minimal/TestCases/recover-dedup.cpp?rev=313614&r1=313613&r2=313614&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan_minimal/TestCases/recover-dedup.cpp (original)
+++ compiler-rt/trunk/test/ubsan_minimal/TestCases/recover-dedup.cpp Mon Sep 18 23:46:36 2017
@@ -1,6 +1,18 @@
-// RUN: %clangxx -fsanitize=signed-integer-overflow -fsanitize-recover=all %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx -w -fsanitize=signed-integer-overflow,nullability-return,returns-nonnull-attribute -fsanitize-recover=all %s -o %t && %run %t 2>&1 | FileCheck %s
 
 #include <stdint.h>
+#include <stdio.h>
+
+int *_Nonnull h() {
+  // CHECK: nullability-return
+  return NULL;
+}
+
+__attribute__((returns_nonnull))
+int *i() {
+  // CHECK: nonnull-return
+  return NULL;
+}
 
 __attribute__((noinline))
 int f(int x, int y) {
@@ -15,6 +27,8 @@ int g(int x, int y) {
 }
 
 int main() {
+  h();
+  i();
   int x = 2;
   for (int i = 0; i < 10; ++i)
     x = f(x, x);




More information about the llvm-commits mailing list