-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[ASan] Do not instrument catch block parameters on Windows #159618
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
davidmrdavid
merged 22 commits into
llvm:main
from
davidmrdavid:dev/dajusto/dont-asanize-catch-params-on-windows
Oct 17, 2025
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ece2a2b
do not asan-instrument catch parameters on windows
davidmrdavid bff409d
add basic unit test: catches exception 'inline' and in another frame
davidmrdavid 043848d
apply clang-format on `compiler-rt/test/asan/TestCases/Windows/basic_…
davidmrdavid 2326be0
optimization: disable catch-parameter instrumentation via a linear pa…
davidmrdavid 3497540
Merge branch 'main' into dev/dajusto/dont-asanize-catch-params-on-win…
davidmrdavid e4551b1
add IR instrumentation unit test with `opt`
davidmrdavid 9b99935
Merge branch 'dev/dajusto/dont-asanize-catch-params-on-windows' of ht…
davidmrdavid 04956f9
Merge branch 'main' into dev/dajusto/dont-asanize-catch-params-on-win…
davidmrdavid 65f1741
remove unecessary braces in if-statement
davidmrdavid fe312ec
minimize `.ll` test
davidmrdavid a44a340
Merge branch 'dev/dajusto/dont-asanize-catch-params-on-windows' of ht…
davidmrdavid bd511b5
remove braces from the 'for' loop
davidmrdavid c5a0e78
Merge branch 'main' into dev/dajusto/dont-asanize-catch-params-on-win…
davidmrdavid 992a650
Merge branch 'main' into dev/dajusto/dont-asanize-catch-params-on-win…
davidmrdavid 0dec61a
Update llvm/test/Instrumentation/AddressSanitizer/asan-win-dont-instr…
davidmrdavid 112f078
Update llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
davidmrdavid 2f544df
add newline to runtime test
davidmrdavid 980e31d
follow convention: move lit commands to start of backend unit test
davidmrdavid 7d93177
Merge branch 'main' into dev/dajusto/dont-asanize-catch-params-on-win…
davidmrdavid 7fe17b5
Merge branch 'main' into dev/dajusto/dont-asanize-catch-params-on-win…
davidmrdavid 98217a4
Update llvm/test/Instrumentation/AddressSanitizer/asan-win-dont-instr…
davidmrdavid 4b88967
Merge branch 'main' into dev/dajusto/dont-asanize-catch-params-on-win…
davidmrdavid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
compiler-rt/test/asan/TestCases/Windows/basic_exception_handling.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // RUN: %clangxx_asan %s -o %t | ||
davidmrdavid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // RUN: %run %t | FileCheck %s | ||
|
|
||
| // This test tests that declaring a parameter in a catch-block does not produce a false positive | ||
| // ASan error on Windows. | ||
|
|
||
| // This code is based on the repro in https://github.com/google/sanitizers/issues/749 | ||
| #include <cstdio> | ||
| #include <exception> | ||
|
|
||
| void throwInFunction() { throw std::exception("test2"); } | ||
|
|
||
| int main() { | ||
| // case 1: direct throw | ||
| try { | ||
| throw std::exception("test1"); | ||
| } catch (const std::exception &ex) { | ||
| puts(ex.what()); | ||
| // CHECK: test1 | ||
| } | ||
|
|
||
| // case 2: throw in function | ||
| try { | ||
| throwInFunction(); | ||
| } catch (const std::exception &ex) { | ||
| puts(ex.what()); | ||
| // CHECK: test2 | ||
| } | ||
|
|
||
| printf("Success!\n"); | ||
| // CHECK: Success! | ||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
llvm/test/Instrumentation/AddressSanitizer/asan-win-dont-instrument-catchpad.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| ; RUN: opt < %s -passes=asan -S | FileCheck %s | ||
| ; CHECK: %ex = alloca i32, align 4 | ||
| ; CHECK: catchpad within %{{.*}} [ptr @"??_R0H@8", i32 0, ptr %ex] | ||
|
|
||
| ; This test ensures that catch parameters are not instrumented on Windows. | ||
|
|
||
| ; This file was generated using the following source | ||
| ; | ||
| ; ```C++ | ||
| ; #include <exception> | ||
| ; #include <cstdio> | ||
| ; | ||
| ; int main() { | ||
| ; try { | ||
| ; throw 1; | ||
| ; } catch (const int ex) { | ||
| ; printf("%d\n", ex); | ||
| ; return -1; | ||
| ; } | ||
| ; return 0; | ||
| ; } | ||
| ; | ||
| ; ``` | ||
| ; then running the following sequence of commands | ||
| ; | ||
| ; ``` | ||
| ; clang.exe -g0 -O0 -emit-llvm -c main.cpp -o main.bc | ||
| ; llvm-extract.exe -func=main main.bc -o main_func.bc | ||
| ; llvm-dis.exe main_func.bc -o main_func_dis.ll | ||
| ; ``` | ||
| ; and finally manually trimming the resulting `.ll` file to remove | ||
| ; unnecessary metadata, and manually adding the `sanitize_address` annotation; | ||
| ; needed for the ASan pass to run. | ||
|
|
||
| target triple = "x86_64-pc-windows-msvc" | ||
|
|
||
| @"??_R0H@8" = external global ptr | ||
|
|
||
| ; Function Attrs: sanitize_address | ||
| define i32 @main() sanitize_address personality ptr @__CxxFrameHandler3 { | ||
| entry: | ||
| %ex = alloca i32, align 4 | ||
| invoke void @throw() | ||
| to label %unreachable unwind label %catch.dispatch | ||
|
|
||
| catch.dispatch: ; preds = %entry | ||
| %0 = catchswitch within none [label %catch] unwind to caller | ||
|
|
||
| catch: ; preds = %catch.dispatch | ||
| %1 = catchpad within %0 [ptr @"??_R0H@8", i32 0, ptr %ex] | ||
| call void @opaque() [ "funclet"(token %1) ] | ||
| catchret from %1 to label %return | ||
|
|
||
| return: ; preds = %catch | ||
| ret i32 0 | ||
|
|
||
| unreachable: ; preds = %entry | ||
| unreachable | ||
| } | ||
|
|
||
| declare void @throw() noreturn | ||
| declare void @opaque() | ||
| declare i32 @__CxxFrameHandler3(...) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.