diff --git a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cc b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cc index 97f7ae7b2a65..dac127bc281c 100644 --- a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cc +++ b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cc @@ -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 // @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-overflow") 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") diff --git a/compiler-rt/test/ubsan_minimal/TestCases/recover-dedup.cpp b/compiler-rt/test/ubsan_minimal/TestCases/recover-dedup.cpp index 744471c66a71..4dfd6991ef11 100644 --- a/compiler-rt/test/ubsan_minimal/TestCases/recover-dedup.cpp +++ b/compiler-rt/test/ubsan_minimal/TestCases/recover-dedup.cpp @@ -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 +#include + +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);