[cfe-commits] r80436 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp test/CodeGenCXX/conversion-function.cpp
Fariborz Jahanian
fjahanian at apple.com
Sat Aug 29 13:33:33 PDT 2009
Author: fjahanian
Date: Sat Aug 29 15:33:32 2009
New Revision: 80436
URL: http://llvm.org/viewvc/llvm-project?rev=80436&view=rev
Log:
Patch to ir-gen user-defined conversions used in expressions
[12.3.2-p3]
Modified:
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/test/CodeGenCXX/conversion-function.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=80436&r1=80435&r2=80436&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sat Aug 29 15:33:32 2009
@@ -324,6 +324,17 @@
llvm::BasicBlock *FalseBlock) {
if (const ParenExpr *PE = dyn_cast<ParenExpr>(Cond))
return EmitBranchOnBoolExpr(PE->getSubExpr(), TrueBlock, FalseBlock);
+ if (const CastExpr *E = dyn_cast<CastExpr>(Cond))
+ if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) {
+ if (const CXXFunctionalCastExpr *CXXFExpr =
+ dyn_cast<CXXFunctionalCastExpr>(E)) {
+ EmitCXXFunctionalCastExpr(CXXFExpr);
+ return;
+ }
+ else if (isa<CStyleCastExpr>(E))
+ return EmitBranchOnBoolExpr(E->getSubExpr(), TrueBlock, FalseBlock);
+ assert(false && "EmitBranchOnBoolExpr - Expected CStyleCastExpr");
+ }
if (const BinaryOperator *CondBOp = dyn_cast<BinaryOperator>(Cond)) {
// Handle X && Y in a condition.
Modified: cfe/trunk/test/CodeGenCXX/conversion-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/conversion-function.cpp?rev=80436&r1=80435&r2=80436&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/conversion-function.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/conversion-function.cpp Sat Aug 29 15:33:32 2009
@@ -39,6 +39,22 @@
Y y;
+int count=0;
+class O { // ...
+public:
+ operator int(){ return ++iO; }
+ O() : iO(count++) {}
+ int iO;
+};
+
+void g(O a, O b)
+{
+ int i = (a) ? 1+a : 0;
+ int j = (a&&b) ? a+b : i;
+ if (a) { }
+ printf("i = %d j = %d a.iO = %d b.iO = %d\n", i, j, a.iO, b.iO);
+}
+
int main() {
int c = X(Z(y)); // OK: y.operator Z().operator X().operator int()
printf("c = %d\n", c);
@@ -58,6 +74,8 @@
int e = (int)((X)((Z)y));
printf("e = %d\n", e);
+ O o1, o2;
+ g(o1, o2);
}
// CHECK-LP64: .globl __ZN1ScviEv
// CHECK-LP64-NEXT: __ZN1ScviEv:
More information about the cfe-commits
mailing list