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

This commit is contained in:
Johan Engelen 2022-06-26 11:13:33 +02:00 committed by GitHub
parent 421f3d1c0a
commit a2ce3f31b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 11 deletions

View file

@ -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"
@ -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);
}
}

View file

@ -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()

View file

@ -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)

View file

@ -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]);
}