From 51954276ccee058ba3e82f41fb09e77da39d2d85 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 13 Jul 2010 23:17:26 +0000 Subject: Introduce a new cast kind for an "lvalue bitcast", which handles reinterpret_casts (possibly indirectly via C-style/functional casts) on values, e.g., int i; reinterpret_cast(i); The IR generated for this is essentially the same as for *reinterpret_cast(&i). Fixes PR6437, PR7593, and PR7344. llvm-svn: 108294 --- clang/lib/CodeGen/CGExpr.cpp | 3 ++- clang/lib/CodeGen/CGExprAgg.cpp | 4 ++++ clang/lib/CodeGen/CGExprScalar.cpp | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 0426a60f0c3..5a4808bce9d 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1816,7 +1816,8 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { return LValue::MakeAddr(Derived, MakeQualifiers(E->getType())); } - case CastExpr::CK_BitCast: { + case CastExpr::CK_BitCast: + case CastExpr::CK_LValueBitCast: { // This must be a reinterpret_cast (or c-style equivalent). const ExplicitCastExpr *CE = cast(E); diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 20722f7799c..219a5f91532 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -307,6 +307,10 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { break; } + case CastExpr::CK_LValueBitCast: + llvm_unreachable("there are no lvalue bit-casts on aggregates"); + break; + case CastExpr::CK_BitCast: { // This must be a member function pointer cast. Visit(E->getSubExpr()); diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 1ebc2c571a0..ef38209e1ea 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -925,6 +925,15 @@ Value *ScalarExprEmitter::EmitCastExpr(CastExpr *CE) { //assert(0 && "Unknown cast kind!"); break; + case CastExpr::CK_LValueBitCast: { + Value *V = EmitLValue(E).getAddress(); + V = Builder.CreateBitCast(V, + ConvertType(CGF.getContext().getPointerType(DestTy))); + // FIXME: Are the qualifiers correct here? + return EmitLoadOfLValue(LValue::MakeAddr(V, CGF.MakeQualifiers(DestTy)), + DestTy); + } + case CastExpr::CK_AnyPointerToObjCPointerCast: case CastExpr::CK_AnyPointerToBlockPointerCast: case CastExpr::CK_BitCast: { -- cgit v1.2.3