]> granicus.if.org Git - clang/commitdiff
the logic for computing __func__ and friends is really broken:
authorChris Lattner <sabre@nondot.org>
Thu, 23 Apr 2009 05:30:27 +0000 (05:30 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 23 Apr 2009 05:30:27 +0000 (05:30 +0000)
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
lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h

index e56101509f2b79c2cf90100bdb55087187e7953d..d22cdab70df990c92bed6def34cdc8b928305c22 100644 (file)
@@ -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) { 
index 27b60a01e9e319ad82f4ecc6dfecd4c5719ea5f9..a042c6a4ed5ab6d657ef5ba17f6174ef2db3353e 100644 (file)
@@ -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<CompoundStmt>(BExpr->getBody())->getRBracLoc());
 
index 67b6e4c3d73c3f22932a5a3a35cc584cc4925793..ed1baa0da0ad3f5086327f4a8c9650dfa4d357e1 100644 (file)
@@ -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<FunctionDecl>(CurFuncDecl)) {
+  if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurCodeDecl)) {
     FunctionName = CGM.getMangledName(FD);
   } else {
     // Just get the mangled name; skipping the asm prefix if it
index 082beb8de8544a72c0fa6415f17d3dcdc2e5396c..c05ead5233b516d2544b28b45f46fe3e699c0229 100644 (file)
@@ -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?");
index 32001ceab38116e4a3b818b31060774f672c1f89..2cad46ed0177ce58b6844969c54ac103bafca0a9 100644 (file)
@@ -70,9 +70,11 @@ public:
   typedef std::pair<llvm::Value *, llvm::Value *> 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;