mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-10 21:06:33 +03:00
Enable output of variable names in ASan and MSan error reporting. (#4004)
This commit is contained in:
parent
421f3d1c0a
commit
a2ce3f31b2
4 changed files with 16 additions and 11 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include "dmd/scope.h"
|
#include "dmd/scope.h"
|
||||||
#include "driver/cl_options.h"
|
#include "driver/cl_options.h"
|
||||||
#include "driver/cl_options_instrumentation.h"
|
#include "driver/cl_options_instrumentation.h"
|
||||||
|
#include "driver/cl_options_sanitizers.h"
|
||||||
#include "driver/linker.h"
|
#include "driver/linker.h"
|
||||||
#include "driver/toobj.h"
|
#include "driver/toobj.h"
|
||||||
#include "gen/dynamiccompile.h"
|
#include "gen/dynamiccompile.h"
|
||||||
|
@ -195,8 +196,11 @@ CodeGenerator::CodeGenerator(llvm::LLVMContext &context,
|
||||||
mlirContext_(mlirContext),
|
mlirContext_(mlirContext),
|
||||||
#endif
|
#endif
|
||||||
moduleCount_(0), singleObj_(singleObj), ir_(nullptr) {
|
moduleCount_(0), singleObj_(singleObj), ir_(nullptr) {
|
||||||
// Set the context to discard value names when not generating textual IR.
|
// Set the context to discard value names when not generating textual IR and
|
||||||
if (!global.params.output_ll) {
|
// when ASan or MSan are not enabled.
|
||||||
|
if (!global.params.output_ll &&
|
||||||
|
!opts::isSanitizerEnabled(opts::AddressSanitizer |
|
||||||
|
opts::MemorySanitizer)) {
|
||||||
context_.setDiscardValueNames(true);
|
context_.setDiscardValueNames(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,9 @@ void foo(int* ptr)
|
||||||
// CHECK-NEXT: #0 {{.*}} in {{.*prefoo.*}} {{.*}}asan_fiber.d:[[@LINE+1]]
|
// CHECK-NEXT: #0 {{.*}} in {{.*prefoo.*}} {{.*}}asan_fiber.d:[[@LINE+1]]
|
||||||
void prefoo()
|
void prefoo()
|
||||||
{
|
{
|
||||||
int[10] a;
|
// CHECK: 'aiaiaiaiaiaiaiaiaiai'{{.*}} <== {{.*}} overflows this variable
|
||||||
foo(&a[0]);
|
int[10] aiaiaiaiaiaiaiaiaiai;
|
||||||
|
foo(&aiaiaiaiaiaiaiaiaiai[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
|
|
@ -36,13 +36,14 @@ void foo(int* arr)
|
||||||
// FAKESTACK: #0 {{.*}} in {{.*main.*}} {{.*}}asan_fiber_main.d:[[@LINE+1]]
|
// FAKESTACK: #0 {{.*}} in {{.*main.*}} {{.*}}asan_fiber_main.d:[[@LINE+1]]
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
int[10] a;
|
// FAKESTACK: 'abcdabcdabcd'{{.*}} <== {{.*}} overflows this variable
|
||||||
|
int[10] abcdabcdabcd;
|
||||||
int b;
|
int b;
|
||||||
|
|
||||||
// Use an extra variable instead of passing `&a[0]` directly to `foo`.
|
// 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
|
// This is to keep `a` on the stack: `ptr` may be heap allocated because
|
||||||
// it is used in the lambda (delegate).
|
// it is used in the lambda (delegate).
|
||||||
int* ptr = &a[0];
|
int* ptr = &abcdabcdabcd[0];
|
||||||
auto fib = new Fiber(() => foo(ptr));
|
auto fib = new Fiber(() => foo(ptr));
|
||||||
fib.call();
|
fib.call();
|
||||||
version (BAD_AFTER_YIELD)
|
version (BAD_AFTER_YIELD)
|
||||||
|
|
|
@ -17,10 +17,9 @@ void foo(int* arr)
|
||||||
// CHECK-NEXT: #0 {{.*}} in {{.*main.*}} {{.*}}asan_stackoverflow.d:[[@LINE+1]]
|
// CHECK-NEXT: #0 {{.*}} in {{.*main.*}} {{.*}}asan_stackoverflow.d:[[@LINE+1]]
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// TODO: add test for the name of the variable that is overflown. Right now we get this message:
|
// Test for the name of the variable that is overflown.
|
||||||
//[32, 72) '' <== Memory access at offset 72 overflows this variable
|
// CHECK: 'aiaiaiaiaiaiai'{{.*}} <== {{.*}} overflows this variable
|
||||||
// C HECK: 'a'{{.*}} <== {{.*}} overflows this variable
|
int[10] aiaiaiaiaiaiai;
|
||||||
int[10] a;
|
|
||||||
int b;
|
int b;
|
||||||
foo(&a[0]);
|
foo(&aiaiaiaiaiaiai[0]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue