Skip to content

Commit a2ce3f3

Browse files
authored
Enable output of variable names in ASan and MSan error reporting. (#4004)
1 parent 421f3d1 commit a2ce3f3

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

driver/codegenerator.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "dmd/scope.h"
1818
#include "driver/cl_options.h"
1919
#include "driver/cl_options_instrumentation.h"
20+
#include "driver/cl_options_sanitizers.h"
2021
#include "driver/linker.h"
2122
#include "driver/toobj.h"
2223
#include "gen/dynamiccompile.h"
@@ -195,8 +196,11 @@ CodeGenerator::CodeGenerator(llvm::LLVMContext &context,
195196
mlirContext_(mlirContext),
196197
#endif
197198
moduleCount_(0), singleObj_(singleObj), ir_(nullptr) {
198-
// Set the context to discard value names when not generating textual IR.
199-
if (!global.params.output_ll) {
199+
// Set the context to discard value names when not generating textual IR and
200+
// when ASan or MSan are not enabled.
201+
if (!global.params.output_ll &&
202+
!opts::isSanitizerEnabled(opts::AddressSanitizer |
203+
opts::MemorySanitizer)) {
200204
context_.setDiscardValueNames(true);
201205
}
202206
}

tests/sanitizers/asan_fiber.d

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ void foo(int* ptr)
2727
// CHECK-NEXT: #0 {{.*}} in {{.*prefoo.*}} {{.*}}asan_fiber.d:[[@LINE+1]]
2828
void prefoo()
2929
{
30-
int[10] a;
31-
foo(&a[0]);
30+
// CHECK: 'aiaiaiaiaiaiaiaiaiai'{{.*}} <== {{.*}} overflows this variable
31+
int[10] aiaiaiaiaiaiaiaiaiai;
32+
foo(&aiaiaiaiaiaiaiaiaiai[0]);
3233
}
3334

3435
void main()

tests/sanitizers/asan_fiber_main.d

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ void foo(int* arr)
3636
// FAKESTACK: #0 {{.*}} in {{.*main.*}} {{.*}}asan_fiber_main.d:[[@LINE+1]]
3737
void main()
3838
{
39-
int[10] a;
39+
// FAKESTACK: 'abcdabcdabcd'{{.*}} <== {{.*}} overflows this variable
40+
int[10] abcdabcdabcd;
4041
int b;
4142

4243
// Use an extra variable instead of passing `&a[0]` directly to `foo`.
4344
// This is to keep `a` on the stack: `ptr` may be heap allocated because
4445
// it is used in the lambda (delegate).
45-
int* ptr = &a[0];
46+
int* ptr = &abcdabcdabcd[0];
4647
auto fib = new Fiber(() => foo(ptr));
4748
fib.call();
4849
version (BAD_AFTER_YIELD)

tests/sanitizers/asan_stackoverflow.d

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ void foo(int* arr)
1717
// CHECK-NEXT: #0 {{.*}} in {{.*main.*}} {{.*}}asan_stackoverflow.d:[[@LINE+1]]
1818
void main()
1919
{
20-
// TODO: add test for the name of the variable that is overflown. Right now we get this message:
21-
//[32, 72) '' <== Memory access at offset 72 overflows this variable
22-
// C HECK: 'a'{{.*}} <== {{.*}} overflows this variable
23-
int[10] a;
20+
// Test for the name of the variable that is overflown.
21+
// CHECK: 'aiaiaiaiaiaiai'{{.*}} <== {{.*}} overflows this variable
22+
int[10] aiaiaiaiaiaiai;
2423
int b;
25-
foo(&a[0]);
24+
foo(&aiaiaiaiaiaiai[0]);
2625
}

0 commit comments

Comments
 (0)