From: David Blaikie Date: Wed, 10 Dec 2014 01:03:48 +0000 (+0000) Subject: DebugInfo: Correct the location of array accesses X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2800de7e3967f5225c67e4b3fb5ba4da75ebfa83;p=clang DebugInfo: Correct the location of array accesses Especially relevant to ASan when dealing with complex expressions containing multiple array accesses. See PR21737. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223872 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 5eb04a4ddf..e7caf835ce 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -2459,6 +2459,8 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, } else { // The base must be a pointer, which is not an aggregate. Emit it. llvm::Value *Base = EmitScalarExpr(E->getBase()); + if (auto *DI = getDebugInfo()) + DI->EmitLocation(Builder, E->getLocStart()); if (getLangOpts().isSignedOverflowDefined()) Address = Builder.CreateGEP(Base, Idx, "arrayidx"); else diff --git a/test/CodeGenCXX/debug-info-line.cpp b/test/CodeGenCXX/debug-info-line.cpp index 878c3ac33f..396a3f7750 100644 --- a/test/CodeGenCXX/debug-info-line.cpp +++ b/test/CodeGenCXX/debug-info-line.cpp @@ -72,6 +72,15 @@ void f6() { = agg_src(); } +// CHECK-LABEL: define +void f7() { + int *src1(); + int src2(); +#line 800 + int x = ( // CHECK: load {{.*}} !dbg [[DBG_F7:!.*]] + src1())[src2()]; +} + // CHECK: [[DBG_F1]] = metadata !{i32 100, // CHECK: [[DBG_FOO_VALUE]] = metadata !{i32 200, // CHECK: [[DBG_FOO_REF]] = metadata !{i32 202, @@ -81,3 +90,4 @@ void f6() { // CHECK: [[DBG_F4]] = metadata !{i32 500, // CHECK: [[DBG_F5]] = metadata !{i32 600, // CHECK: [[DBG_F6]] = metadata !{i32 700, +// CHECK: [[DBG_F7]] = metadata !{i32 800,