diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-29 20:33:32 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-29 20:33:32 +0000 |
| commit | 0a484d007be8f63e527b5d8400800a90eb77b0b3 (patch) | |
| tree | 69243807a38b32e25371a9dc695c8c429b2b5a9a /clang | |
| parent | 7b194b780d3bb152ef25b37911c818b3e16bdce0 (diff) | |
| download | bcm5719-llvm-0a484d007be8f63e527b5d8400800a90eb77b0b3.tar.gz bcm5719-llvm-0a484d007be8f63e527b5d8400800a90eb77b0b3.zip | |
Patch to ir-gen user-defined conversions used in expressions
[12.3.2-p3]
llvm-svn: 80436
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 11 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/conversion-function.cpp | 18 |
2 files changed, 29 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 68ab6dfc589..e3511edd2be 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -324,6 +324,17 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond, 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. diff --git a/clang/test/CodeGenCXX/conversion-function.cpp b/clang/test/CodeGenCXX/conversion-function.cpp index f3c0e33bf12..e7820bb44f0 100644 --- a/clang/test/CodeGenCXX/conversion-function.cpp +++ b/clang/test/CodeGenCXX/conversion-function.cpp @@ -39,6 +39,22 @@ class Y { // ... 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 main() { 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: |

