From b5437d238752dc297e42410e98d38d5250fe0463 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 23 Apr 2009 05:30:27 +0000 Subject: [PATCH] the logic for computing __func__ and friends is really broken: the type assigned by sema (and is visible with sizeof(__func__) for example) has nothing to do with what codegen ends up producing. We should eventually add a method on PredefinedExpr to handle this. In the meantime, just set up some framework and add some fixme's. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69872 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Expr.h | 5 +++++ lib/CodeGen/CGBlocks.cpp | 4 ++-- lib/CodeGen/CGExpr.cpp | 5 ++++- lib/CodeGen/CodeGenFunction.cpp | 2 +- lib/CodeGen/CodeGenFunction.h | 6 ++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index e56101509f..d22cdab70d 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -376,6 +376,11 @@ public: SourceLocation getLocation() const { return Loc; } void setLocation(SourceLocation L) { Loc = L; } + // FIXME: The logic for computing the value of a predefined expr should go + // into a method here that takes the inner-most code decl (a block, function + // or objc method) that the expr lives in. This would allow sema and codegen + // to be consistent for things like sizeof(__func__) etc. + virtual SourceRange getSourceRange() const { return SourceRange(Loc); } static bool classof(const Stmt *T) { diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 27b60a01e9..a042c6a4ed 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -672,9 +672,9 @@ CodeGenFunction::GenerateBlockFunction(const BlockExpr *BExpr, CGM.SetInternalFunctionAttributes(BD, Fn, FI); - StartFunction(BD, ResultType, Fn, Args, + StartFunction(OuterFuncDecl, ResultType, Fn, Args, BExpr->getBody()->getLocEnd()); - CurFuncDecl = OuterFuncDecl; + CurCodeDecl = BD; EmitStmt(BExpr->getBody()); FinishFunction(cast(BExpr->getBody())->getRBracLoc()); diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 67b6e4c3d7..ed1baa0da0 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -752,8 +752,11 @@ LValue CodeGenFunction::EmitPredefinedFunctionName(unsigned Type) { break; } + // FIXME: This isn't right at all. The logic for computing this should go + // into a method on PredefinedExpr. This would allow sema and codegen to be + // consistent for things like sizeof(__func__) etc. std::string FunctionName; - if (const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl)) { + if (const FunctionDecl *FD = dyn_cast_or_null(CurCodeDecl)) { FunctionName = CGM.getMangledName(FD); } else { // Just get the mangled name; skipping the asm prefix if it diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 082beb8de8..c05ead5233 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -145,7 +145,7 @@ void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy, const FunctionArgList &Args, SourceLocation StartLoc) { DidCallStackSave = false; - CurFuncDecl = D; + CurCodeDecl = CurFuncDecl = D; FnRetTy = RetTy; CurFn = Fn; assert(CurFn->isDeclaration() && "Function already has body?"); diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 32001ceab3..2cad46ed01 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -70,9 +70,11 @@ public: typedef std::pair ComplexPairTy; CGBuilderTy Builder; - /// CurFuncDecl - Holds the Decl for the current function or method. This - /// excludes BlockDecls. + /// CurFuncDecl - Holds the Decl for the current function or ObjC method. + /// This excludes BlockDecls. const Decl *CurFuncDecl; + /// CurCodeDecl - This is the inner-most code context, which includes blocks. + const Decl *CurCodeDecl; const CGFunctionInfo *CurFnInfo; QualType FnRetTy; llvm::Function *CurFn; -- 2.40.0