Skip to content

[Clang][compiler-rt][UBSan] Improve __ubsan_handle_invalid_builtin #109088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler-rt/lib/ubsan/ubsan_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,12 @@ static void handleInvalidBuiltin(InvalidBuiltinData *Data, ReportOptions Opts) {
ScopedReport R(Opts, Loc, ET);

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

void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {
GET_REPORT_OPTIONS(true);
GET_REPORT_OPTIONS(false);
handleInvalidBuiltin(Data, Opts);
}
void __ubsan::__ubsan_handle_invalid_builtin_abort(InvalidBuiltinData *Data) {
Expand Down
18 changes: 18 additions & 0 deletions compiler-rt/test/ubsan/TestCases/Integer/suppressions-builtin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %clangxx -fsanitize=builtin -g0 %s -o %t

// Suppression by symbol name requires the compiler-rt runtime to be able to
// symbolize stack addresses.
// REQUIRES: can-symbolize
// UNSUPPORTED: android

// RUN: echo "invalid-builtin-use:do_ctz" > %t.func-supp
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.func-supp"' %run %t

#include <stdint.h>

extern "C" void do_ctz(int n) { __builtin_ctz(0); }

int main() {
do_ctz(0);
return 0;
}
14 changes: 7 additions & 7 deletions compiler-rt/test/ubsan/TestCases/Misc/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
// RUN: not %run %t.abort 2>&1 | FileCheck %s --check-prefix=ABORT

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

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

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

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

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

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

Expand Down
Loading