[cfe-commits] r80398 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/StmtDumper.cpp lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/constructor-conversion.cpp
Fariborz Jahanian
fjahanian at apple.com
Fri Aug 28 15:04:50 PDT 2009
Author: fjahanian
Date: Fri Aug 28 17:04:50 2009
New Revision: 80398
URL: http://llvm.org/viewvc/llvm-project?rev=80398&view=rev
Log:
path to ir-gen 12.3.1 Conversion by constructor
Added:
cfe/trunk/test/CodeGenCXX/constructor-conversion.cpp
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/StmtDumper.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=80398&r1=80397&r2=80398&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Aug 28 17:04:50 2009
@@ -1203,7 +1203,10 @@
/// CK_UserDefinedConversion - Conversion using a user defined type
/// conversion function.
- CK_UserDefinedConversion
+ CK_UserDefinedConversion,
+
+ /// CK_ConstructorConversion - Conversion by constructor
+ CK_ConstructorConversion
};
struct CastInfo {
Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=80398&r1=80397&r2=80398&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Fri Aug 28 17:04:50 2009
@@ -333,6 +333,9 @@
case CastExpr::CK_UserDefinedConversion:
fprintf(F, "<UserDefinedConversion>");
break;
+ case CastExpr::CK_ConstructorConversion:
+ fprintf(F, "<ConstructorConversion>");
+ break;
}
}
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=80398&r1=80397&r2=80398&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Aug 28 17:04:50 2009
@@ -920,9 +920,10 @@
break;
case ImplicitConversionSequence::UserDefinedConversion:
- // FIXME. Support other kinds of user defined convesions.
- if (CXXConversionDecl *CV =
- dyn_cast<CXXConversionDecl>(ICS.UserDefined.ConversionFunction))
+ {
+ FunctionDecl *FD = ICS.UserDefined.ConversionFunction;
+ CastExpr::CastKind CastKind = CastExpr::CK_Unknown;
+ if (CXXConversionDecl *CV = dyn_cast<CXXConversionDecl>(FD)) {
// FIXME. Get actual Source Location.
From =
new (Context) CXXFunctionalCastExpr(ToType.getNonReferenceType(),
@@ -930,10 +931,22 @@
CastExpr::CK_UserDefinedConversion,
From, CV,
SourceLocation());
- ImpCastExprToType(From, ToType.getNonReferenceType(),
- CastExpr::CK_Unknown,
- ToType->isLValueReferenceType());
- return false;
+ CastKind = CastExpr::CK_UserDefinedConversion;
+ }
+ else if (CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
+ // FIXME. Do we need to check for isLValueReferenceType?
+ DefaultFunctionArrayConversion(From);
+ OwningExprResult InitResult =
+ BuildCXXConstructExpr(ToType.getNonReferenceType(),
+ CD, &From, 1);
+ From = InitResult.takeAs<Expr>();
+ CastKind = CastExpr::CK_ConstructorConversion ;
+ }
+ ImpCastExprToType(From, ToType.getNonReferenceType(),
+ CastKind,
+ ToType->isLValueReferenceType());
+ return false;
+ }
case ImplicitConversionSequence::EllipsisConversion:
assert(false && "Cannot perform an ellipsis conversion");
Added: cfe/trunk/test/CodeGenCXX/constructor-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/constructor-conversion.cpp?rev=80398&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/constructor-conversion.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/constructor-conversion.cpp Fri Aug 28 17:04:50 2009
@@ -0,0 +1,58 @@
+// 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
+
+extern "C" int printf(...);
+
+class X { // ...
+public:
+ X(int) : iX(2), fX(2.3) , name("HELLO\n") { }
+
+ X(const char* arg, int ix=0) { iX = ix; fX = 6.0; name = arg+ix; }
+ X(): iX(100), fX(1.2) {}
+ int iX;
+ float fX;
+ const char *name;
+ void pr(void) {
+ printf("iX = %d fX = %f name = %s\n", iX, fX, name);
+ }
+};
+
+void g(X arg) {
+ arg.pr();
+}
+
+void f(X arg) {
+
+ X a = 1; // a = X(1)
+
+ a.pr();
+
+ X b = "Jessie"; // b=X("Jessie",0)
+
+ b.pr();
+
+
+ a = 2; // a = X(2)
+
+ a.pr();
+
+}
+
+
+int main()
+{
+ X x;
+ f(x);
+ g(3); // g(X(3))
+}
+
+// CHECK-LP64: call __ZN1XC1Ei
+// CHECK-LP64: call __ZN1XC1EPKci
+// CHECK-LP64: call __ZN1XC1Ev
+
+// CHECK-LP32: call L__ZN1XC1Ei
+// CHECK-LP32: call L__ZN1XC1EPKci
+// CHECK-LP32: call L__ZN1XC1Ev
More information about the cfe-commits
mailing list