]> granicus.if.org Git - clang/commitdiff
[DebugInfo] Don't emit incorrect descriptions of thunk params (PR42627)
authorVedant Kumar <vsk@apple.com>
Mon, 29 Jul 2019 22:49:55 +0000 (22:49 +0000)
committerVedant Kumar <vsk@apple.com>
Mon, 29 Jul 2019 22:49:55 +0000 (22:49 +0000)
The `this` parameter of a thunk requires adjustment. Stop emitting an
incorrect dbg.declare pointing to the unadjusted pointer.

We could describe the adjusted value instead, but there may not be much
benefit in doing so as users tend not to debug thunks.

Robert O'Callahan reports that this matches gcc's behavior.

Fixes PR42627.

Differential Revision: https://reviews.llvm.org/D65035

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@367269 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
test/CodeGenCXX/thunks.cpp

index 6ad43cefc4d291f6b91acb829f57eacd82daa79d..c6c2ff57e1cf282f8cc276254496388ff69d3aff 100644 (file)
@@ -2496,10 +2496,11 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
 
   setAddrOfLocalVar(&D, DeclPtr);
 
-  // Emit debug info for param declaration.
+  // Emit debug info for param declarations in non-thunk functions.
   if (CGDebugInfo *DI = getDebugInfo()) {
     if (CGM.getCodeGenOpts().getDebugInfo() >=
-        codegenoptions::LimitedDebugInfo) {
+            codegenoptions::LimitedDebugInfo &&
+        !CurFuncIsThunk) {
       DI->EmitDeclareOfArgVariable(&D, DeclPtr.getPointer(), ArgNo, Builder);
     }
   }
index b4a0f9072e6c67f0b7821b603a834f27f169fddb..cc4b5e8d2f17becbc09a4658037d90dd2f626cb9 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-NONOPT %s
+// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -debug-info-kind=standalone -dwarf-version=5 -munwind-tables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-NONOPT --check-prefix=CHECK-DBG %s
 // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes | FileCheck --check-prefix=CHECK --check-prefix=CHECK-OPT %s
 
 namespace Test1 {
@@ -20,6 +21,8 @@ struct C : A, B {
 };
 
 // CHECK-LABEL: define void @_ZThn8_N5Test11C1fEv(
+// CHECK-DBG-NOT: dbg.declare
+// CHECK: ret void
 void C::f() { }
 
 }
@@ -38,6 +41,8 @@ struct B : virtual A {
 };
 
 // CHECK-LABEL: define void @_ZTv0_n24_N5Test21B1fEv(
+// CHECK-DBG-NOT: dbg.declare
+// CHECK: ret void
 void B::f() { }
 
 }
@@ -83,6 +88,8 @@ struct __attribute__((visibility("protected"))) C : A, B {
 };
 
 // CHECK-LABEL: define protected void @_ZThn8_N5Test41C1fEv(
+// CHECK-DBG-NOT: dbg.declare
+// CHECK: ret void
 void C::f() { }
 
 }
@@ -166,6 +173,7 @@ namespace Test6 {
   };
 
   // CHECK-LABEL: define void @_ZThn16_N5Test66Thunks1fEv
+       // CHECK-DBG-NOT: dbg.declare
   // CHECK-NOT: memcpy
   // CHECK: {{call void @_ZN5Test66Thunks1fEv.*sret}}
   // CHECK: ret void
@@ -212,6 +220,7 @@ namespace Test7 {
   void D::baz(X, X&, _Complex float, Small, Small&, Large) { }
 
   // CHECK-LABEL: define void @_ZThn8_N5Test71D3bazENS_1XERS1_CfNS_5SmallERS4_NS_5LargeE(
+  // CHECK-DBG-NOT: dbg.declare
   // CHECK-NOT: memcpy
   // CHECK: ret void
   void testD() { D d; }
@@ -227,6 +236,7 @@ namespace Test8 {
   void C::helper(NonPOD var) {}
 
   // CHECK-LABEL: define void @_ZThn8_N5Test81C3barENS_6NonPODE(
+  // CHECK-DBG-NOT: dbg.declare
   // CHECK-NOT: load [[NONPODTYPE]], [[NONPODTYPE]]*
   // CHECK-NOT: memcpy
   // CHECK: ret void
@@ -269,10 +279,14 @@ namespace Test11 {
   //  The this-adjustment and return-adjustment thunk required when
   //  C::f appears in a vtable where A is at a nonzero offset from C.
   // CHECK: define {{.*}} @_ZTcv0_n24_v0_n32_N6Test111C1fEv(
+  // CHECK-DBG-NOT: dbg.declare
+  // CHECK: ret
 
   //  The return-adjustment thunk required when C::f appears in a vtable
   //  where A is at a zero offset from C.
   // CHECK: define {{.*}} @_ZTch0_v0_n32_N6Test111C1fEv(
+  // CHECK-DBG-NOT: dbg.declare
+  // CHECK: ret
 }
 
 // Varargs thunk test.
@@ -295,6 +309,7 @@ namespace Test12 {
   // Varargs thunk; check that both the this and covariant adjustments
   // are generated.
   // CHECK: define {{.*}} @_ZTchn8_h8_N6Test121C1fEiz
+  // CHECK-DBG-NOT: dbg.declare
   // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -8
   // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 8
 }
@@ -318,6 +333,7 @@ namespace Test13 {
     return *this;
   }
   // CHECK: define {{.*}} @_ZTcvn8_n32_v8_n24_N6Test131D4foo1Ev
+  // CHECK-DBG-NOT: dbg.declare
   // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -8
   // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -32
   // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -24
@@ -338,6 +354,8 @@ namespace Test14 {
   void C::f() {
   }
   // CHECK: define void @_ZThn8_N6Test141C1fEv({{.*}}) unnamed_addr [[NUW:#[0-9]+]]
+  // CHECK-DBG-NOT: dbg.declare
+  // CHECK: ret void
 }
 
 // Varargs non-covariant thunk test.
@@ -376,6 +394,8 @@ struct D : public C {
 };
 D::~D() {}
 // CHECK: define linkonce_odr void @_ZThn8_N6Test161C3fooEv({{.*}}) {{.*}} comdat
+// CHECK-DBG-NOT: dbg.declare
+// CHECK: ret void
 }
 
 /**** The following has to go at the end of the file ****/