[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.

llvm-svn: 313614
This commit is contained in:
Vedant Kumar 2017-09-19 06:46:36 +00:00
parent 6f8fbf4b86
commit c539795bc3
2 changed files with 27 additions and 6 deletions

View File

@ -57,17 +57,22 @@ static void abort_with_message(const char *) { abort(); }
// FIXME: add caller pc to the error message (possibly as "ubsan: error-type // FIXME: add caller pc to the error message (possibly as "ubsan: error-type
// @1234ABCD"). // @1234ABCD").
#define HANDLER(name, msg) \ #define HANDLER_RECOVER(name, msg) \
INTERFACE void __ubsan_handle_##name##_minimal() { \ INTERFACE void __ubsan_handle_##name##_minimal() { \
if (!report_this_error(__builtin_return_address(0))) return; \ if (!report_this_error(__builtin_return_address(0))) return; \
message("ubsan: " msg "\n"); \ message("ubsan: " msg "\n"); \
} \ }
\
#define HANDLER_NORECOVER(name, msg) \
INTERFACE void __ubsan_handle_##name##_minimal_abort() { \ INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
message("ubsan: " msg "\n"); \ message("ubsan: " msg "\n"); \
abort_with_message("ubsan: " msg); \ abort_with_message("ubsan: " msg); \
} }
#define HANDLER(name, msg) \
HANDLER_RECOVER(name, msg) \
HANDLER_NORECOVER(name, msg)
HANDLER(type_mismatch, "type-mismatch") HANDLER(type_mismatch, "type-mismatch")
HANDLER(add_overflow, "add-overflow") HANDLER(add_overflow, "add-overflow")
HANDLER(sub_overflow, "sub-overflow") HANDLER(sub_overflow, "sub-overflow")
@ -76,14 +81,16 @@ HANDLER(negate_overflow, "negate-overflow")
HANDLER(divrem_overflow, "divrem-overflow") HANDLER(divrem_overflow, "divrem-overflow")
HANDLER(shift_out_of_bounds, "shift-out-of-bounds") HANDLER(shift_out_of_bounds, "shift-out-of-bounds")
HANDLER(out_of_bounds, "out-of-bounds") HANDLER(out_of_bounds, "out-of-bounds")
HANDLER(builtin_unreachable, "builtin-unreachable") HANDLER_RECOVER(builtin_unreachable, "builtin-unreachable")
HANDLER(missing_return, "missing-return") HANDLER_RECOVER(missing_return, "missing-return")
HANDLER(vla_bound_not_positive, "vla-bound-not-positive") HANDLER(vla_bound_not_positive, "vla-bound-not-positive")
HANDLER(float_cast_overflow, "float-cast-overflow") HANDLER(float_cast_overflow, "float-cast-overflow")
HANDLER(load_invalid_value, "load-invalid-value") HANDLER(load_invalid_value, "load-invalid-value")
HANDLER(invalid_builtin, "invalid-builtin") HANDLER(invalid_builtin, "invalid-builtin")
HANDLER(function_type_mismatch, "function-type-mismatch") HANDLER(function_type_mismatch, "function-type-mismatch")
HANDLER(nonnull_arg, "nonnull-arg") HANDLER(nonnull_arg, "nonnull-arg")
HANDLER(nonnull_return, "nonnull-return")
HANDLER(nullability_arg, "nullability-arg") HANDLER(nullability_arg, "nullability-arg")
HANDLER(nullability_return, "nullability-return")
HANDLER(pointer_overflow, "pointer-overflow") HANDLER(pointer_overflow, "pointer-overflow")
HANDLER(cfi_check_fail, "cfi-check-fail") HANDLER(cfi_check_fail, "cfi-check-fail")

View File

@ -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 <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)) __attribute__((noinline))
int f(int x, int y) { int f(int x, int y) {
@ -15,6 +27,8 @@ int g(int x, int y) {
} }
int main() { int main() {
h();
i();
int x = 2; int x = 2;
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
x = f(x, x); x = f(x, x);