summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-10-17 21:58:32 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-10-17 21:58:32 +0000
commit662b71ee82339c67f2c3689196e716c6560cf925 (patch)
tree3ed57a543cce0de1a7dfaad2bf2a45b0b711684d /lib/CodeGen/CGExpr.cpp
parent5fabf9dbee29464bcd06cd09f8e569d1b850f948 (diff)
downloadclang-662b71ee82339c67f2c3689196e716c6560cf925.tar.gz
clang-662b71ee82339c67f2c3689196e716c6560cf925.tar.bz2
clang-662b71ee82339c67f2c3689196e716c6560cf925.tar.xz
Lift CodeGenFunction::EmitPredefinedFunctioName out of EmitPredefinedLValue.
- Shouldn't assume predefined expr is a function printing one. - Uses CGM functionality to cache function names per module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57737 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 872e3d1af4..34d025d289 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -531,21 +531,12 @@ LValue CodeGenFunction::EmitStringLiteralLValue(const StringLiteral *E) {
return LValue::MakeAddr(CGM.GetAddrOfConstantStringFromLiteral(E), 0);
}
-LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
- std::string FunctionName;
- if(const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl)) {
- FunctionName = FD->getName();
- } else if (isa<ObjCMethodDecl>(CurFuncDecl)) {
- // Just get the mangled name.
- FunctionName = CurFn->getName();
- } else {
- return EmitUnsupportedLValue(E, "predefined expression");
- }
+LValue CodeGenFunction::EmitPredefinedFunctionName(unsigned Type) {
std::string GlobalVarName;
-
- switch (E->getIdentType()) {
+
+ switch (Type) {
default:
- return EmitUnsupportedLValue(E, "predefined expression");
+ assert(0 && "Invalid type");
case PredefinedExpr::Func:
GlobalVarName = "__func__.";
break;
@@ -557,17 +548,30 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
GlobalVarName = "__PRETTY_FUNCTION__.";
break;
}
-
+
+ std::string FunctionName;
+ if(const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl)) {
+ FunctionName = FD->getName();
+ } else {
+ // Just get the mangled name.
+ FunctionName = CurFn->getName();
+ }
+
GlobalVarName += FunctionName;
-
- // FIXME: Can cache/reuse these within the module.
- llvm::Constant *C = llvm::ConstantArray::get(FunctionName);
-
- // Create a global variable for this.
- C = new llvm::GlobalVariable(C->getType(), true,
- llvm::GlobalValue::InternalLinkage,
- C, GlobalVarName, CurFn->getParent());
- return LValue::MakeAddr(C,0);
+ llvm::Constant *C =
+ CGM.GetAddrOfConstantCString(FunctionName, GlobalVarName.c_str());
+ return LValue::MakeAddr(C, 0);
+}
+
+LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
+ switch (E->getIdentType()) {
+ default:
+ return EmitUnsupportedLValue(E, "predefined expression");
+ case PredefinedExpr::Func:
+ case PredefinedExpr::Function:
+ case PredefinedExpr::PrettyFunction:
+ return EmitPredefinedFunctionName(E->getIdentType());
+ }
}
LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {