Fix the address of a label to be properly considered and emitted as a

constant.

llvm-svn: 62948
This commit is contained in:
Eli Friedman 2009-01-25 01:21:06 +00:00
parent 8b7c52658b
commit 529a99bcf4
3 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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()));

View File

@ -0,0 +1,4 @@
// RUN: clang %s -emit-llvm -o %t
int a() {
A:;static void* a = &&A;
}