Skip to content
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

Enable output of variable names in ASan and MSan error reporting. #4004

Merged
merged 1 commit into from
Jun 26, 2022
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
8 changes: 6 additions & 2 deletions driver/codegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "dmd/scope.h"
#include "driver/cl_options.h"
#include "driver/cl_options_instrumentation.h"
#include "driver/cl_options_sanitizers.h"
#include "driver/linker.h"
#include "driver/toobj.h"
#include "gen/dynamiccompile.h"
Expand Down Expand Up @@ -195,8 +196,11 @@ CodeGenerator::CodeGenerator(llvm::LLVMContext &context,
mlirContext_(mlirContext),
#endif
moduleCount_(0), singleObj_(singleObj), ir_(nullptr) {
// Set the context to discard value names when not generating textual IR.
if (!global.params.output_ll) {
// Set the context to discard value names when not generating textual IR and
// when ASan or MSan are not enabled.
if (!global.params.output_ll &&
!opts::isSanitizerEnabled(opts::AddressSanitizer |
opts::MemorySanitizer)) {
context_.setDiscardValueNames(true);
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/sanitizers/asan_fiber.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ void foo(int* ptr)
// CHECK-NEXT: #0 {{.*}} in {{.*prefoo.*}} {{.*}}asan_fiber.d:[[@LINE+1]]
void prefoo()
{
int[10] a;
foo(&a[0]);
// CHECK: 'aiaiaiaiaiaiaiaiaiai'{{.*}} <== {{.*}} overflows this variable
int[10] aiaiaiaiaiaiaiaiaiai;
foo(&aiaiaiaiaiaiaiaiaiai[0]);
}

void main()
Expand Down
5 changes: 3 additions & 2 deletions tests/sanitizers/asan_fiber_main.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ void foo(int* arr)
// FAKESTACK: #0 {{.*}} in {{.*main.*}} {{.*}}asan_fiber_main.d:[[@LINE+1]]
void main()
{
int[10] a;
// FAKESTACK: 'abcdabcdabcd'{{.*}} <== {{.*}} overflows this variable
int[10] abcdabcdabcd;
int b;

// Use an extra variable instead of passing `&a[0]` directly to `foo`.
// This is to keep `a` on the stack: `ptr` may be heap allocated because
// it is used in the lambda (delegate).
int* ptr = &a[0];
int* ptr = &abcdabcdabcd[0];
auto fib = new Fiber(() => foo(ptr));
fib.call();
version (BAD_AFTER_YIELD)
Expand Down
9 changes: 4 additions & 5 deletions tests/sanitizers/asan_stackoverflow.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ void foo(int* arr)
// CHECK-NEXT: #0 {{.*}} in {{.*main.*}} {{.*}}asan_stackoverflow.d:[[@LINE+1]]
void main()
{
// TODO: add test for the name of the variable that is overflown. Right now we get this message:
//[32, 72) '' <== Memory access at offset 72 overflows this variable
// C HECK: 'a'{{.*}} <== {{.*}} overflows this variable
int[10] a;
// Test for the name of the variable that is overflown.
// CHECK: 'aiaiaiaiaiaiai'{{.*}} <== {{.*}} overflows this variable
int[10] aiaiaiaiaiaiai;
int b;
foo(&a[0]);
foo(&aiaiaiaiaiaiai[0]);
}