diff options
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 6 | ||||
-rw-r--r-- | clang/test/CodeGen/const-label-addr.c | 4 |
3 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 4c242059b52..76bdaa2c8f8 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 9d709d3a509..0e31cacd1b0 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/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<AddrLabelExpr>(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/clang/test/CodeGen/const-label-addr.c b/clang/test/CodeGen/const-label-addr.c new file mode 100644 index 00000000000..1ae74e5ad06 --- /dev/null +++ b/clang/test/CodeGen/const-label-addr.c @@ -0,0 +1,4 @@ +// RUN: clang %s -emit-llvm -o %t +int a() { +A:;static void* a = &&A; +} |