[cfe-commits] r102998 - in /cfe/trunk: lib/CodeGen/CGClass.cpp lib/Sema/SemaDeclCXX.cpp test/CodeGenCXX/default-arg-temps.cpp

John McCall rjmccall at apple.com
Mon May 3 18:53:42 PDT 2010


Author: rjmccall
Date: Mon May  3 20:53:42 2010
New Revision: 102998

URL: http://llvm.org/viewvc/llvm-project?rev=102998&view=rev
Log:
When inheriting a default argument expression, inherit the full expression,
not just the inner expression.  This is important if the expression has any
temporaries.  Fixes PR 7028.

Basically a symptom of really tragic method names.


Modified:
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CodeGenCXX/default-arg-temps.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=102998&r1=102997&r2=102998&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon May  3 20:53:42 2010
@@ -584,7 +584,9 @@
                                 LHS.isVolatileQualified());
   } else {
     CGF.EmitAggExpr(MemberInit->getInit(), LHS.getAddress(), 
-                    LHS.isVolatileQualified(), false, true);
+                    LHS.isVolatileQualified(),
+                    /*IgnoreResult*/ false,
+                    /*IsInitializer*/ true);
     
     if (!CGF.Exceptions)
       return;

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=102998&r1=102997&r2=102998&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon May  3 20:53:42 2010
@@ -298,13 +298,15 @@
         << OldParam->getDefaultArgRange();
       Invalid = true;
     } else if (OldParam->hasDefaultArg()) {
-      // Merge the old default argument into the new parameter
+      // Merge the old default argument into the new parameter.
+      // It's important to use getInit() here;  getDefaultArg()
+      // strips off any top-level CXXExprWithTemporaries.
       NewParam->setHasInheritedDefaultArg();
       if (OldParam->hasUninstantiatedDefaultArg())
         NewParam->setUninstantiatedDefaultArg(
                                       OldParam->getUninstantiatedDefaultArg());
       else
-        NewParam->setDefaultArg(OldParam->getDefaultArg());
+        NewParam->setDefaultArg(OldParam->getInit());
     } else if (NewParam->hasDefaultArg()) {
       if (New->getDescribedFunctionTemplate()) {
         // Paragraph 4, quoted above, only applies to non-template functions.

Modified: cfe/trunk/test/CodeGenCXX/default-arg-temps.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/default-arg-temps.cpp?rev=102998&r1=102997&r2=102998&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/default-arg-temps.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/default-arg-temps.cpp Mon May  3 20:53:42 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm %s -o %t -triple=x86_64-apple-darwin9
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s
 
 struct T {
   T();
@@ -13,20 +13,62 @@
         X(const X&, const T& t = T());
 };
 
+// CHECK: define void @_Z1gv()
 void g() {
-  // RUN: grep "call void @_ZN1TC1Ev" %t | count 4
-  // RUN: grep "call void @_ZN1TD1Ev" %t | count 4
+  // CHECK:      call void @_ZN1TC1Ev([[T:%.*]]* [[AGG1:%.*]])
+  // CHECK-NEXT: call void @_Z1fRK1T([[T]]* [[AGG1]])
+  // CHECK-NEXT: call void @_ZN1TD1Ev([[T]]* [[AGG1]])
   f();
+
+  // CHECK-NEXT: call void @_ZN1TC1Ev([[T:%.*]]* [[AGG2:%.*]])
+  // CHECK-NEXT: call void @_Z1fRK1T([[T]]* [[AGG2]])
+  // CHECK-NEXT: call void @_ZN1TD1Ev([[T]]* [[AGG2]])
   f();
 
+  // CHECK-NEXT: call void @_ZN1XC1Ev(
   X a;
+
+  // CHECK-NEXT: call void @_ZN1TC1Ev(
+  // CHECK-NEXT: call void @_ZN1XC1ERKS_RK1T(
+  // CHECK-NEXT: call void @_ZN1TD1Ev(
   X b(a);
+
+  // CHECK-NEXT: call void @_ZN1TC1Ev(
+  // CHECK-NEXT: call void @_ZN1XC1ERKS_RK1T(
+  // CHECK-NEXT: call void @_ZN1TD1Ev(
   X c = a;
 }
 
 
-// RUN: grep memset %t
 class obj{ int a; float b; double d; };
+// CHECK: define void @_Z1hv()
 void h() {
+  // CHECK: call void @llvm.memset.p0i8.i64(
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(
   obj o = obj();
 }
+
+// PR7028 - mostly this shouldn't crash
+namespace test1 {
+  struct A { A(); };
+  struct B { B(); ~B(); };
+
+  struct C {
+    C(const B &file = B());
+  };
+  C::C(const B &file) {}
+
+  struct D {
+    C c;
+    A a;
+
+    // CHECK: define linkonce_odr void @_ZN5test11DC2Ev(
+    // CHECK:      call void @_ZN5test11BC1Ev(
+    // CHECK-NEXT: call void @_ZN5test11CC1ERKNS_1BE(
+    // CHECK-NEXT: call void @_ZN5test11BD1Ev(
+    // CHECK:      call void @_ZN5test11AC1Ev(
+    D() : c(), a() {}
+  };
+
+  D d;
+}





More information about the cfe-commits mailing list