]> granicus.if.org Git - clang/commitdiff
Fix the AST tree so ir-gen can do the conversion via copy construction.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 25 Sep 2009 18:11:25 +0000 (18:11 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 25 Sep 2009 18:11:25 +0000 (18:11 +0000)
Fixed pr5050.

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

lib/Sema/SemaExprCXX.cpp
test/CodeGenCXX/PR5050-constructor-conversion.cpp [new file with mode: 0644]

index a243b2cec6277d5e2ad5c250dd9f21f22b49cfa7..76c64f492b157e28f9e4a01c10e551110e765c53 100644 (file)
@@ -1113,7 +1113,9 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
   if (SCS.CopyConstructor) {
     // FIXME: When can ToType be a reference type?
     assert(!ToType->isReferenceType());
-
+    if (SCS.Second == ICK_Derived_To_Base)
+      ImpCastExprToType(From, ToType, CastExpr::CK_DerivedToBase,
+                        /*isLvalue=*/true);
     OwningExprResult FromResult =
       BuildCXXConstructExpr(/*FIXME:ConstructLoc*/SourceLocation(),
                             ToType, SCS.CopyConstructor,
diff --git a/test/CodeGenCXX/PR5050-constructor-conversion.cpp b/test/CodeGenCXX/PR5050-constructor-conversion.cpp
new file mode 100644 (file)
index 0000000..adfe74f
--- /dev/null
@@ -0,0 +1,19 @@
+// RUN: clang-cc -triple x86_64-apple-darwin -std=c++0x -S %s -o %t-64.s &&
+// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s &&
+// RUN: clang-cc -triple i386-apple-darwin -std=c++0x -S %s -o %t-32.s &&
+// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s &&
+// RUN: true
+
+struct A { A(const A&); };
+
+struct B : A { };
+
+A f(const B &b) {
+  return b;
+}
+
+// CHECK-LP64: call     __ZN1AC1ERK1A
+
+// CHECK-LP32: call     L__ZN1AC1ERK1A
+
+