-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[msan] Add experimental '-mllvm -msan-embed-faulting-instruction' and MSAN_OPTIONS=print_faulting_instruction #136539
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
Open
thurstond
wants to merge
27
commits into
llvm:main
Choose a base branch
from
thurstond:msan_print_faulting_inst
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
cb98d98
[msan] Add experimental '-mllvm -msan-print-faulting-instruction'
thurstond 39a5ab9
Separate out embedding the instruction vs. printing the faulting
thurstond cacf9f2
clang-format
thurstond e539a52
Address Florian's feedback
thurstond 2f2f248
Address one other piece of feedback
thurstond 5ac8339
Reword comment
thurstond 3dec04f
Rename CANT_PRINT_FAULTING_INSTRUCTION to WARN_IF_PRINT_FAULTING_INST…
thurstond 97f827b
Revert scope level change because it causes use-after-scope
thurstond f41479c
Move maybeBuf to higher scope too
thurstond 19fd6df
Rename IRB0 -> IRB since there is no longer name collision
thurstond 97bece2
Add newline (and restart CI)
thurstond 069356d
Rerun CI
thurstond e244b02
Fix rename
thurstond 84728f1
Refactor to minimize code duplication between x() and x_instname()
thurstond f2ac5c7
clang-format
thurstond 12f1a08
Typo
thurstond c639c69
Rerun CI
thurstond 44ca7d0
Use FunctionType::get to reduce duplication for creating _instname
thurstond cdf5671
More simplification with FunctionType::get
thurstond 1ef2ac5
Refactor to use getWarningFnName
thurstond 91bd6bd
clang-format
thurstond c8c0762
Format getWarningFnName
thurstond 7b9cebb
Change macro to function
thurstond 277467f
PrintFaultingInstruction -> PrintFaultingInstructionIfRequested
thurstond 973c7c2
Fix function declaration
thurstond 9907618
Smaller SmallVectors
thurstond 2ebd231
Really fix function declaration
thurstond 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
There are no files selected for viewing
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
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
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
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,93 @@ | ||
// Try parameter '0' (program runs cleanly) | ||
// ------------------------------------------------------- | ||
// RUN: %clangxx_msan -g %s -o %t && env MSAN_OPTIONS=print_faulting_instruction=true %run %t 0 | ||
|
||
// Try parameter '1' | ||
// ------------------------------------------------------- | ||
// RUN: %clangxx_msan -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 1 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefix STORE-CHECK %s < %t.out | ||
|
||
// RUN: %clangxx_msan -mllvm -msan-embed-faulting-instruction=none -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 1 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefix STORE-CHECK %s < %t.out | ||
|
||
// RUN: %clangxx_msan -mllvm -msan-embed-faulting-instruction=name -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 1 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefixes VERBOSE-STORE-CHECK,STORE-CHECK %s < %t.out | ||
|
||
// RUN: %clangxx_msan -mllvm -msan-embed-faulting-instruction=full -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 1 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefixes VERY-VERBOSE-STORE-CHECK,STORE-CHECK %s < %t.out | ||
|
||
// Try parameter '2', with -fsanitize-memory-param-retval | ||
// ------------------------------------------------------- | ||
// RUN: %clangxx_msan -fsanitize-memory-param-retval -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 2 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefix PARAM-CHECK %s < %t.out | ||
|
||
// RUN: %clangxx_msan -fsanitize-memory-param-retval -mllvm -msan-embed-faulting-instruction=none -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 2 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefix PARAM-CHECK %s < %t.out | ||
|
||
// RUN: %clangxx_msan -fsanitize-memory-param-retval -mllvm -msan-embed-faulting-instruction=name -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 2 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefixes VERBOSE-PARAM-CHECK,PARAM-CHECK %s < %t.out | ||
|
||
// RUN: %clangxx_msan -fsanitize-memory-param-retval -mllvm -msan-embed-faulting-instruction=full -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 2 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefixes VERY-VERBOSE-PARAM-CHECK,PARAM-CHECK %s < %t.out | ||
|
||
// Try parameter '2', with -fno-sanitize-memory-param-retval | ||
// ------------------------------------------------------- | ||
// RUN: %clangxx_msan -fno-sanitize-memory-param-retval -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 2 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefix NO-PARAM-CHECK %s < %t.out | ||
|
||
// RUN: %clangxx_msan -fno-sanitize-memory-param-retval -mllvm -msan-embed-faulting-instruction=none -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 2 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefix NO-PARAM-CHECK %s < %t.out | ||
|
||
// RUN: %clangxx_msan -fno-sanitize-memory-param-retval -mllvm -msan-embed-faulting-instruction=name -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 2 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefixes VERBOSE-NO-PARAM-CHECK,NO-PARAM-CHECK %s < %t.out | ||
|
||
// RUN: %clangxx_msan -fno-sanitize-memory-param-retval -mllvm -msan-embed-faulting-instruction=full -g %s -o %t && not env MSAN_OPTIONS=print_faulting_instruction=true %run %t 2 >%t.out 2>&1 | ||
// RUN: FileCheck --check-prefixes VERY-VERBOSE-NO-PARAM-CHECK,NO-PARAM-CHECK %s < %t.out | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define THRICE(o, t) twice(o, t) | ||
|
||
__attribute__((noinline)) extern "C" int twice(int o, int t) { | ||
return o + t < 3; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
int buf[100]; | ||
buf[0] = 42; | ||
buf[1] = 43; | ||
|
||
if (argc != 2) { | ||
printf("Usage: %s index\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
int index = atoi(argv[1]); | ||
int val = buf[index]; | ||
|
||
printf("index %d, abs(val) %d, THRICE(val,5) %d\n", index, abs(val), | ||
THRICE(val, 5)); | ||
// VERY-VERBOSE-PARAM-CHECK: Instruction that failed the shadow check: %{{.*}} = call noundef i32 @twice(i32 noundef %{{.*}}, i32 noundef 5) | ||
// VERBOSE-PARAM-CHECK: Instruction that failed the shadow check: call twice | ||
// PARAM-CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value | ||
// PARAM-CHECK: {{#0 0x.* in main .*print_faulting_inst.cpp:}}[[@LINE-4]] | ||
|
||
if (val) | ||
// VERY-VERBOSE-NO-PARAM-CHECK: Instruction that failed the shadow check: br i1 %{{.*}}, label %{{.*}}, label %{{.*}} | ||
// VERBOSE-NO-PARAM-CHECK: Instruction that failed the shadow check: br | ||
// NO-PARAM-CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value | ||
// NO-PARAM-CHECK: {{#0 0x.* in main .*print_faulting_inst.cpp:}}[[@LINE-4]] | ||
printf("Variable is non-zero\n"); | ||
else | ||
printf("Variable is zero\n"); | ||
|
||
int nextval = buf[index + 1]; | ||
buf[nextval + abs(index)] = twice(index, 6); | ||
// VERY-VERBOSE-STORE-CHECK: Instruction that failed the shadow check: store i32 %{{.*}}, ptr %{{.*}} | ||
// VERBOSE-STORE-CHECK: Instruction that failed the shadow check: store | ||
// STORE-CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value | ||
// STORE-CHECK: {{#0 0x.* in main .*print_faulting_inst.cpp:}}[[@LINE-4]] | ||
|
||
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
Oops, something went wrong.
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.