Skip to content

Commit 642bfd8

Browse files
dtcxzywvitalybuka
andauthored
[Clang][compiler-rt][UBSan] Improve __ubsan_handle_invalid_builtin (#109088)
This patch improves error message, and fixes a copy-paste mistake in GET_REPORT_OPTIONS argument. Address comment #104741 (comment). --------- Co-authored-by: Vitaly Buka <[email protected]>
1 parent 4fc08b6 commit 642bfd8

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

compiler-rt/lib/ubsan/ubsan_handlers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,12 @@ static void handleInvalidBuiltin(InvalidBuiltinData *Data, ReportOptions Opts) {
634634
ScopedReport R(Opts, Loc, ET);
635635

636636
Diag(Loc, DL_Error, ET,
637-
"passing zero to %0, which is not a valid argument")
638-
<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
637+
"passing zero to __builtin_%0(), which is not a valid argument")
638+
<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz" : "clz");
639639
}
640640

641641
void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {
642-
GET_REPORT_OPTIONS(true);
642+
GET_REPORT_OPTIONS(false);
643643
handleInvalidBuiltin(Data, Opts);
644644
}
645645
void __ubsan::__ubsan_handle_invalid_builtin_abort(InvalidBuiltinData *Data) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clangxx -fsanitize=builtin -g0 %s -o %t
2+
3+
// Suppression by symbol name requires the compiler-rt runtime to be able to
4+
// symbolize stack addresses.
5+
// REQUIRES: can-symbolize
6+
// UNSUPPORTED: android
7+
8+
// RUN: echo "invalid-builtin-use:do_ctz" > %t.func-supp
9+
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.func-supp"' %run %t
10+
11+
#include <stdint.h>
12+
13+
extern "C" void do_ctz(int n) { __builtin_ctz(0); }
14+
15+
int main() {
16+
do_ctz(0);
17+
return 0;
18+
}

compiler-rt/test/ubsan/TestCases/Misc/builtins.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
// RUN: not %run %t.abort 2>&1 | FileCheck %s --check-prefix=ABORT
77

88
void check_ctz(int n) {
9-
// ABORT: builtins.cpp:[[@LINE+2]]:17: runtime error: passing zero to ctz(), which is not a valid argument
10-
// RECOVER: builtins.cpp:[[@LINE+1]]:17: runtime error: passing zero to ctz(), which is not a valid argument
9+
// ABORT: builtins.cpp:[[@LINE+2]]:17: runtime error: passing zero to __builtin_ctz(), which is not a valid argument
10+
// RECOVER: builtins.cpp:[[@LINE+1]]:17: runtime error: passing zero to __builtin_ctz(), which is not a valid argument
1111
__builtin_ctz(n);
1212

13-
// RECOVER: builtins.cpp:[[@LINE+1]]:18: runtime error: passing zero to ctz(), which is not a valid argument
13+
// RECOVER: builtins.cpp:[[@LINE+1]]:18: runtime error: passing zero to __builtin_ctz(), which is not a valid argument
1414
__builtin_ctzl(n);
1515

16-
// RECOVER: builtins.cpp:[[@LINE+1]]:19: runtime error: passing zero to ctz(), which is not a valid argument
16+
// RECOVER: builtins.cpp:[[@LINE+1]]:19: runtime error: passing zero to __builtin_ctz(), which is not a valid argument
1717
__builtin_ctzll(n);
1818
}
1919

2020
void check_clz(int n) {
21-
// RECOVER: builtins.cpp:[[@LINE+1]]:17: runtime error: passing zero to clz(), which is not a valid argument
21+
// RECOVER: builtins.cpp:[[@LINE+1]]:17: runtime error: passing zero to __builtin_clz(), which is not a valid argument
2222
__builtin_clz(n);
2323

24-
// RECOVER: builtins.cpp:[[@LINE+1]]:18: runtime error: passing zero to clz(), which is not a valid argument
24+
// RECOVER: builtins.cpp:[[@LINE+1]]:18: runtime error: passing zero to __builtin_clz(), which is not a valid argument
2525
__builtin_clzl(n);
2626

27-
// RECOVER: builtins.cpp:[[@LINE+1]]:19: runtime error: passing zero to clz(), which is not a valid argument
27+
// RECOVER: builtins.cpp:[[@LINE+1]]:19: runtime error: passing zero to __builtin_clz(), which is not a valid argument
2828
__builtin_clzll(n);
2929
}
3030

0 commit comments

Comments
 (0)