From: Anders Carlsson Date: Sat, 14 Nov 2009 21:21:42 +0000 (+0000) Subject: Handle CK_BitCast in EmitCastLValue. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=658e8123a80d0e62f227a0c1532f2a4f106b3e73;p=clang Handle CK_BitCast in EmitCastLValue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88810 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index c297903a69..c446c03689 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1302,7 +1302,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { if (ICE->isLvalueCast()) return EmitLValue(E->getSubExpr()); - assert(0 && "Unhandled cast!"); + assert(false && "Unhandled cast!"); case CastExpr::CK_NoOp: case CastExpr::CK_ConstructorConversion: @@ -1327,13 +1327,22 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { return LValue::MakeAddr(Base, MakeQualifiers(E->getType())); } - case CastExpr::CK_ToUnion: { llvm::Value *Temp = CreateTempAlloca(ConvertType(E->getType())); EmitAnyExpr(E->getSubExpr(), Temp, false); return LValue::MakeAddr(Temp, MakeQualifiers(E->getType())); - } + } + case CastExpr::CK_BitCast: { + // This must be a reinterpret_cast. + const CXXReinterpretCastExpr *CE = cast(E); + + LValue LV = EmitLValue(E->getSubExpr()); + llvm::Value *V = Builder.CreateBitCast(LV.getAddress(), + ConvertType(CE->getTypeAsWritten())); + return LValue::MakeAddr(V, MakeQualifiers(E->getType())); + } + } } diff --git a/test/CodeGenCXX/reinterpret-cast.cpp b/test/CodeGenCXX/reinterpret-cast.cpp index 25be9b9948..58a980d528 100644 --- a/test/CodeGenCXX/reinterpret-cast.cpp +++ b/test/CodeGenCXX/reinterpret-cast.cpp @@ -10,3 +10,8 @@ unsigned long f2() { unsigned long f3(void *p) { return reinterpret_cast(p); } + +void f4(int*&); +void f5(void*& u) { + f4(reinterpret_cast(u)); +} \ No newline at end of file