]> granicus.if.org Git - clang/commitdiff
Don't use alias from derived dtor to base dtor at -O0.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 13 Nov 2013 23:20:45 +0000 (23:20 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 13 Nov 2013 23:20:45 +0000 (23:20 +0000)
This patch disables aliasing (and rauw) of derived dtors to base dtors at -O0.
This optimization can have a negative impact on the debug quality.

This was a latent bug for some time with local classes, but got noticed when it
was generalized and broke gdb's destrprint.exp.

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

lib/CodeGen/CGCXX.cpp
test/CodeGenCXX/ctor-dtor-alias.cpp
test/CodeGenCXX/destructors.cpp
test/CodeGenCXX/virtual-destructor-calls.cpp

index 581962f4a4dba4a1b55131ee59c8945946eede65..22baa654084978b49c651d6f5b3aba8e80b37a3d 100644 (file)
@@ -34,6 +34,11 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
   if (!getCodeGenOpts().CXXCtorDtorAliases)
     return true;
 
+  // Producing an alias to a base class ctor/dtor can degrade debug quality
+  // as the debugger cannot tell them appart.
+  if (getCodeGenOpts().OptimizationLevel == 0)
+    return true;
+
   // If the destructor doesn't have a trivial body, we have to emit it
   // separately.
   if (!D->hasTrivialBody())
index 266eecc8093de0614e1dc78c1913a887a84cd735..6efd0bf9f870b155922358a2d89d9764ea1721c0 100644 (file)
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -triple x86_64-linux -emit-llvm -o - -mconstructor-aliases | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-linux -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-optzns | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-linux -emit-llvm -o - -mconstructor-aliases | FileCheck --check-prefix=NOOPT %s
 
 namespace test1 {
 // test that we don't produce an alias when the destructor is weak_odr. The
@@ -53,6 +54,11 @@ namespace test4 {
 
   // CHECK-DAG: define linkonce_odr void @_ZN5test41AD2Ev(
   // CHECK-DAG: call i32 @__cxa_atexit{{.*}}_ZN5test41AD2Ev
+
+  // test that we don't do this optimization at -O0 so that the debugger can
+  // see both destructors.
+  // NOOPT-DAG: call i32 @__cxa_atexit{{.*}}@_ZN5test41BD2Ev
+  // NOOOPT-DAG: define linkonce_odr void @_ZN5test41BD2Ev
   struct A {
     virtual ~A() {}
   };
index 59c97b7dca9117d2e03a3f7450fcbff880d288aa..799cca28b4a4e38da66b80490ef1d88bbd65e6fd 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - -mconstructor-aliases -fcxx-exceptions -fexceptions | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - -mconstructor-aliases -fcxx-exceptions -fexceptions -O1 -disable-llvm-optzns | FileCheck %s
 
 // CHECK-DAG: @_ZN5test01AD1Ev = alias {{.*}} @_ZN5test01AD2Ev
 // CHECK-DAG: @_ZN5test11MD2Ev = alias {{.*}} @_ZN5test11AD2Ev
index 0c03c9f1f3d3f35f5313fed5bfb939776d1cd1a6..ae3704f3692864d3f14015e0c9bfd3d67e1ea48c 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 -mconstructor-aliases | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 -mconstructor-aliases -O1 -disable-llvm-optzns | FileCheck %s
 
 struct Member {
   ~Member();