From: Daniel Dunbar Date: Sat, 16 Aug 2008 01:41:47 +0000 (+0000) Subject: Add CodeGen support for AddrLabelExpr in initializers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54d19091a809d30a5e6e352fda53377d69ebda66;p=clang Add CodeGen support for AddrLabelExpr in initializers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54837 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index ec6a75f356..ea60cbb1b0 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -378,6 +378,14 @@ public: return EmitSizeAlignOf(E->getArgumentType(), E->getType(), E->isSizeOf()); } + llvm::Constant *VisitAddrLabelExpr(const AddrLabelExpr *E) { + assert(CGF && "Invalid address of label expression outside function."); + llvm::Constant *C = + llvm::ConstantInt::get(llvm::Type::Int32Ty, + CGF->GetIDForAddrOfLabel(E->getLabel())); + return llvm::ConstantExpr::getIntToPtr(C, ConvertType(E->getType())); + } + // Unary operators llvm::Constant *VisitUnaryPlus(const UnaryOperator *E) { return Visit(E->getSubExpr()); diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index e408e9ff9e..4eb906269a 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -123,10 +123,11 @@ public: return EmitSizeAlignOf(E->getArgumentType(), E->getType(), E->isSizeOf()); } Value *VisitAddrLabelExpr(const AddrLabelExpr *E) { - Value *V = llvm::ConstantInt::get(llvm::Type::Int32Ty, - CGF.GetIDForAddrOfLabel(E->getLabel())); - return Builder.CreateIntToPtr(V, - llvm::PointerType::getUnqual(llvm::Type::Int8Ty)); + llvm::Value *V = + llvm::ConstantInt::get(llvm::Type::Int32Ty, + CGF.GetIDForAddrOfLabel(E->getLabel())); + + return Builder.CreateIntToPtr(V, ConvertType(E->getType())); } // l-values.