From: Eli Friedman Date: Sun, 25 Jan 2009 01:21:06 +0000 (+0000) Subject: Fix the address of a label to be properly considered and emitted as a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f01158941ba4560c63150032073bb231ce38999e;p=clang Fix the address of a label to be properly considered and emitted as a constant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62948 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 4c242059b5..76bdaa2c8f 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -215,6 +215,8 @@ public: APValue VisitUnaryOperator(const UnaryOperator *E); APValue VisitObjCStringLiteral(ObjCStringLiteral *E) { return APValue(E, 0); } + APValue VisitAddrLabelExpr(AddrLabelExpr *E) + { return APValue(E, 0); } APValue VisitConditionalOperator(ConditionalOperator *E); }; } // end anonymous namespace diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 9d709d3a50..0e31cacd1b 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -619,6 +619,12 @@ public: return CGM.GetAddrOfConstantCString(Str, ".tmp"); } + case Expr::AddrLabelExprClass: { + assert(CGF && "Invalid address of label expression outside function."); + unsigned id = CGF->GetIDForAddrOfLabel(cast(E)->getLabel()); + llvm::Constant *C = llvm::ConstantInt::get(llvm::Type::Int32Ty, id); + return llvm::ConstantExpr::getIntToPtr(C, ConvertType(E->getType())); + } } CGM.ErrorUnsupported(E, "constant l-value expression"); llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType())); diff --git a/test/CodeGen/const-label-addr.c b/test/CodeGen/const-label-addr.c new file mode 100644 index 0000000000..1ae74e5ad0 --- /dev/null +++ b/test/CodeGen/const-label-addr.c @@ -0,0 +1,4 @@ +// RUN: clang %s -emit-llvm -o %t +int a() { +A:;static void* a = &&A; +}