[cfe-commits] r69406 - in /cfe/trunk: include/clang/AST/ include/clang/Frontend/ lib/AST/ lib/Analysis/ lib/CodeGen/ lib/Frontend/ lib/Sema/ test/PCH/ tools/clang-cc/

Douglas Gregor dgregor at apple.com
Fri Apr 17 17:02:19 PDT 2009


Author: dgregor
Date: Fri Apr 17 19:02:19 2009
New Revision: 69406

URL: http://llvm.org/viewvc/llvm-project?rev=69406&view=rev
Log:
FunctionDecl::getBody() is getting an ASTContext argument for use in
lazy PCH deserialization. Propagate that argument wherever it needs to
be. No functionality change, except that I've tightened up a few PCH
tests in preparation.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/AST/ExternalASTSource.h
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/AST/DeclSerialization.cpp
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Analysis/BasicStore.cpp
    cfe/trunk/lib/Analysis/BugReporter.cpp
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp
    cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp
    cfe/trunk/lib/Analysis/PathDiagnostic.cpp
    cfe/trunk/lib/CodeGen/CGObjC.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/PCH/blocks.c
    cfe/trunk/test/PCH/stmts.c
    cfe/trunk/test/PCH/va_arg.c
    cfe/trunk/tools/clang-cc/ASTConsumers.cpp
    cfe/trunk/tools/clang-cc/AnalysisConsumer.cpp
    cfe/trunk/tools/clang-cc/RewriteBlocks.cpp
    cfe/trunk/tools/clang-cc/RewriteObjC.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Apr 17 19:02:19 2009
@@ -16,6 +16,7 @@
 
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/ExternalASTSource.h"
 
 namespace clang {
 class Expr;
@@ -564,7 +565,7 @@
   /// FunctionDecl object to save an allocation like FunctionType does.
   ParmVarDecl **ParamInfo;
   
-  Stmt *Body;  // Null if a prototype.
+  Stmt *Body;
   
   /// PreviousDeclaration - A link to the previous declaration of this
   /// same function, NULL if this is the first declaration. For
@@ -596,7 +597,7 @@
                SourceLocation TSSL = SourceLocation())
     : ValueDecl(DK, DC, L, N, T), 
       DeclContext(DK),
-      ParamInfo(0), Body(0), PreviousDeclaration(0),
+      ParamInfo(0), Body(), PreviousDeclaration(0),
       SClass(S), IsInline(isInline), IsVirtual(false), IsPure(false),
       InheritedPrototype(false), HasPrototype(true), IsDeleted(false), 
       TypeSpecStartLoc(TSSL) {}
@@ -619,20 +620,25 @@
   /// function. The variant that accepts a FunctionDecl pointer will
   /// set that function declaration to the actual declaration
   /// containing the body (if there is one).
-  CompoundStmt *getBody(const FunctionDecl *&Definition) const;
+  CompoundStmt *getBody(ASTContext &Context, 
+                        const FunctionDecl *&Definition) const;
 
-  virtual CompoundStmt *getBody() const { 
+  virtual CompoundStmt *getBody(ASTContext &Context) const { 
     const FunctionDecl* Definition;
-    return getBody(Definition);
+    return getBody(Context, Definition);
   }
-  
+
+  /// \brief If the function has a body that is immediately available,
+  /// return it.
+  CompoundStmt *getBodyIfAvailable() const;
+
   /// isThisDeclarationADefinition - Returns whether this specific
   /// declaration of the function is also a definition. This does not
   /// determine whether the function has been defined (e.g., in a
   /// previous definition); for that information, use getBody.
   /// FIXME: Should return true if function is deleted or defaulted. However,
   /// CodeGenModule.cpp uses it, and I don't know if this would break it.
-  bool isThisDeclarationADefinition() const { return Body != 0; }
+  bool isThisDeclarationADefinition() const { return Body; }
 
   void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
 
@@ -1258,6 +1264,7 @@
   SourceLocation getCaretLocation() const { return getLocation(); }
 
   CompoundStmt *getBody() const { return (CompoundStmt*) Body; }
+  CompoundStmt *getBody(ASTContext &C) const { return (CompoundStmt*) Body; }
   void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
 
   // Iterator access to formal parameters.

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Fri Apr 17 19:02:19 2009
@@ -281,7 +281,7 @@
   // getBody - If this Decl represents a declaration for a body of code,
   //  such as a function or method definition, this method returns the top-level
   //  Stmt* of that body.  Otherwise this method returns null.  
-  virtual CompoundStmt* getBody() const { return 0; }
+  virtual CompoundStmt* getBody(ASTContext &Context) const { return 0; }
   
   // global temp stats (until we have a per-module visitor)
   static void addDeclKind(Kind k);

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Apr 17 19:02:19 2009
@@ -676,8 +676,8 @@
   /// defined. If false, then this constructor was defined by the
   /// user. This operation can only be invoked if the constructor has
   /// already been defined.
-  bool isImplicitlyDefined() const { 
-    assert(getBody() != 0 && 
+  bool isImplicitlyDefined(ASTContext &C) const { 
+    assert(isThisDeclarationADefinition() && 
            "Can only get the implicit-definition flag once the constructor has been defined");
     return ImplicitlyDefined; 
   }
@@ -685,7 +685,7 @@
   /// setImplicitlyDefined - Set whether this constructor was
   /// implicitly defined or not.
   void setImplicitlyDefined(bool ID) { 
-    assert(getBody() != 0 && 
+    assert(isThisDeclarationADefinition() && 
            "Can only set the implicit-definition flag once the constructor has been defined");
     ImplicitlyDefined = ID; 
   }
@@ -773,7 +773,7 @@
   /// user. This operation can only be invoked if the destructor has
   /// already been defined.
   bool isImplicitlyDefined() const { 
-    assert(getBody() != 0 && 
+    assert(isThisDeclarationADefinition() && 
            "Can only get the implicit-definition flag once the destructor has been defined");
     return ImplicitlyDefined; 
   }
@@ -781,7 +781,7 @@
   /// setImplicitlyDefined - Set whether this destructor was
   /// implicitly defined or not.
   void setImplicitlyDefined(bool ID) { 
-    assert(getBody() != 0 && 
+    assert(isThisDeclarationADefinition() && 
            "Can only set the implicit-definition flag once the destructor has been defined");
     ImplicitlyDefined = ID; 
   }

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Apr 17 19:02:19 2009
@@ -225,7 +225,10 @@
     return ImplementationControl(DeclImplementation); 
   }
 
-  virtual CompoundStmt *getBody() const { return (CompoundStmt*) Body; }
+  virtual CompoundStmt *getBody(ASTContext &C) const { 
+    return (CompoundStmt*) Body; 
+  }
+  CompoundStmt *getBody() { return (CompoundStmt*)Body; }
   void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
 
   // Implement isa/cast/dyncast/etc.

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Apr 17 19:02:19 2009
@@ -2505,6 +2505,9 @@
   const Stmt *getBody() const;
   Stmt *getBody();
 
+  const Stmt *getBody(ASTContext &C) const { return getBody(); }
+  Stmt *getBody(ASTContext &C) { return getBody(); }
+
   virtual SourceRange getSourceRange() const {
     return SourceRange(getCaretLocation(), getBody()->getLocEnd());
   }

Modified: cfe/trunk/include/clang/AST/ExternalASTSource.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTSource.h?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ExternalASTSource.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTSource.h Fri Apr 17 19:02:19 2009
@@ -16,11 +16,13 @@
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/Type.h"
 #include "llvm/ADT/SmallVector.h"
+#include <cassert>
 namespace clang {
 
 class ASTConsumer;
 class Decl;
 class DeclContext;
+class Stmt;
 
 /// \brief The deserialized representation of a set of declarations
 /// with the same name that are visible in a given context.

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Fri Apr 17 19:02:19 2009
@@ -273,6 +273,9 @@
   /// supplements.
   ASTContext &getContext() { return Context; }
 
+  /// \brief Retrieve the stream that this PCH reader is reading from.
+  llvm::BitstreamReader &getStream() { return Stream; }
+
   /// \brief Record that the given ID maps to the given switch-case
   /// statement.
   void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Apr 17 19:02:19 2009
@@ -320,7 +320,8 @@
 }
 
 
-CompoundStmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
+CompoundStmt *FunctionDecl::getBody(ASTContext &Context,
+                                    const FunctionDecl *&Definition) const {
   for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
     if (FD->Body) {
       Definition = FD;
@@ -331,6 +332,15 @@
   return 0;
 }
 
+CompoundStmt *FunctionDecl::getBodyIfAvailable() const {
+  for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
+    if (FD->Body)
+      return cast<CompoundStmt>(FD->Body);
+  }
+
+  return 0;
+}
+
 bool FunctionDecl::isMain() const {
   return getDeclContext()->getLookupContext()->isTranslationUnit() &&
     getIdentifier() && getIdentifier()->isStr("main");

Modified: cfe/trunk/lib/AST/DeclSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclSerialization.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclSerialization.cpp (original)
+++ cfe/trunk/lib/AST/DeclSerialization.cpp Fri Apr 17 19:02:19 2009
@@ -477,11 +477,11 @@
   if (ParamInfo != NULL) {
     S.EmitBool(true);
     S.EmitInt(getNumParams());
-    S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
+    // FIXME:    S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
   }
   else {
     S.EmitBool(false);
-    S.EmitOwnedPtr(Body);
+    // FIXME:    S.EmitOwnedPtr(Body);
   }
 }
 
@@ -508,7 +508,7 @@
   if (hasParamDecls)
     D.BatchReadOwnedPtrs(numParams,
                          reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
-                         decl->Body, C);
+                         /*FIXME: decl->Body,*/ C);
   else
     decl->Body = D.ReadOwnedPtr<Stmt>(C);
   

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Apr 17 19:02:19 2009
@@ -399,8 +399,12 @@
 SourceLocation BlockExpr::getCaretLocation() const { 
   return TheBlock->getCaretLocation(); 
 }
-const Stmt *BlockExpr::getBody() const { return TheBlock->getBody(); }
-Stmt *BlockExpr::getBody() { return TheBlock->getBody(); }
+const Stmt *BlockExpr::getBody() const { 
+  return TheBlock->getBody();
+}
+Stmt *BlockExpr::getBody() { 
+  return TheBlock->getBody(); 
+}
 
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/Analysis/BasicStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicStore.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BasicStore.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicStore.cpp Fri Apr 17 19:02:19 2009
@@ -525,7 +525,7 @@
           
           // Scan the method for ivar references.  While this requires an
           // entire AST scan, the cost should not be high in practice.
-          St = scanForIvars(MD->getBody(), PD, St);
+          St = scanForIvars(MD->getBody(getContext()), PD, St);
         }
       }
     }

Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Fri Apr 17 19:02:19 2009
@@ -140,7 +140,7 @@
                                             const ExplodedNode<GRState>* N);
   
   ParentMap& getParentMap() {
-    if (PM.get() == 0) PM.reset(new ParentMap(CodeDecl.getBody()));
+    if (PM.get() == 0) PM.reset(new ParentMap(CodeDecl.getBody(getContext())));
     return *PM.get();
   }
   
@@ -163,7 +163,7 @@
   BugReport& getReport() { return *R; }
   GRBugReporter& getBugReporter() { return BR; }
   GRStateManager& getStateManager() { return BR.getStateManager(); }
-  
+
   PathDiagnosticLocation getEnclosingStmtLocation(const Stmt *S);
   
   PathDiagnosticLocation
@@ -189,7 +189,7 @@
   if (Stmt *S = GetNextStmt(N))
     return PathDiagnosticLocation(S, SMgr);
 
-  return FullSourceLoc(CodeDecl.getBody()->getRBracLoc(), SMgr);
+  return FullSourceLoc(CodeDecl.getBody(getContext())->getRBracLoc(), SMgr);
 }
   
 PathDiagnosticLocation

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Apr 17 19:02:19 2009
@@ -2903,7 +2903,8 @@
   }
   
   if (!L.isValid()) {
-    CompoundStmt *CS = BR.getStateManager().getCodeDecl().getBody();
+    CompoundStmt *CS 
+      = BR.getStateManager().getCodeDecl().getBody(BR.getContext());
     L = PathDiagnosticLocation(CS->getRBracLoc(), SMgr);
   }
 

Modified: cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp Fri Apr 17 19:02:19 2009
@@ -172,7 +172,7 @@
   }
   
   // dealloc found.  Scan for missing [super dealloc].
-  if (MD->getBody() && !scan_dealloc(MD->getBody(), S)) {
+  if (MD->getBody(Ctx) && !scan_dealloc(MD->getBody(Ctx), S)) {
     
     const char* name = LOpts.getGCMode() == LangOptions::NonGC
                        ? "missing [super dealloc]"
@@ -223,7 +223,7 @@
               
     // ivar must be released if and only if the kind of setter was not 'assign'
     bool requiresRelease = PD->getSetterKind() != ObjCPropertyDecl::Assign;
-    if(scan_ivar_release(MD->getBody(), ID, PD, RS, SelfII, Ctx) 
+    if(scan_ivar_release(MD->getBody(Ctx), ID, PD, RS, SelfII, Ctx) 
        != requiresRelease) {
       const char *name;
       const char* category = "Memory (Core Foundation/Objective-C)";

Modified: cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp Fri Apr 17 19:02:19 2009
@@ -85,7 +85,7 @@
   // Now scan the methods for accesses.
   for (ObjCImplementationDecl::instmeth_iterator I = D->instmeth_begin(),
        E = D->instmeth_end(); I!=E; ++I)
-    Scan(M, (*I)->getBody());
+    Scan(M, (*I)->getBody(BR.getContext()));
   
   // Scan for @synthesized property methods that act as setters/getters
   // to an ivar.

Modified: cfe/trunk/lib/Analysis/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PathDiagnostic.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/Analysis/PathDiagnostic.cpp Fri Apr 17 19:02:19 2009
@@ -171,8 +171,13 @@
     case DeclK:
       if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
         return MD->getSourceRange();
-      if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
-        return FD->getBody()->getSourceRange();
+      if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+        // FIXME: We would like to always get the function body, even
+        // when it needs to be de-serialized, but getting the
+        // ASTContext here requires significant changes.
+        if (CompoundStmt *Body = FD->getBodyIfAvailable())
+          return Body->getSourceRange();
+      }
       else {
         SourceLocation L = D->getLocation();
         return SourceRange(L, L);

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Fri Apr 17 19:02:19 2009
@@ -131,8 +131,8 @@
   if (CGM.getDebugInfo() && !OMD->hasAttr<NodebugAttr>())
     DebugInfo = CGM.getDebugInfo();
   StartObjCMethod(OMD, OMD->getClassInterface());
-  EmitStmt(OMD->getBody());
-  FinishFunction(cast<CompoundStmt>(OMD->getBody())->getRBracLoc());
+  EmitStmt(OMD->getBody(getContext()));
+  FinishFunction(cast<CompoundStmt>(OMD->getBody(getContext()))->getRBracLoc());
 }
 
 // FIXME: I wasn't sure about the synthesis approach. If we end up

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Apr 17 19:02:19 2009
@@ -225,7 +225,7 @@
                                     FProto->getArgType(i)));
   }
 
-  const CompoundStmt *S = FD->getBody();
+  const CompoundStmt *S = FD->getBody(getContext());
 
   StartFunction(FD, FD->getResultType(), Fn, Args, S->getLBracLoc());
   EmitStmt(S);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Apr 17 19:02:19 2009
@@ -971,7 +971,7 @@
   if (D->hasAttr<DLLExportAttr>()) {
     if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
       // The dllexport attribute is ignored for undefined symbols.
-      if (FD->getBody())
+      if (FD->getBody(getContext()))
         GA->setLinkage(llvm::Function::DLLExportLinkage);
     } else {
       GA->setLinkage(llvm::Function::DLLExportLinkage);
@@ -1403,7 +1403,7 @@
   case Decl::ObjCMethod: {
     ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(D);
     // If this is not a prototype, emit the body.
-    if (OMD->getBody())
+    if (OMD->getBody(getContext()))
       CodeGenFunction(*this).GenerateObjCMethod(OMD);
     break;
   }

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Apr 17 19:02:19 2009
@@ -241,13 +241,15 @@
     : public DeclVisitor<PCHDeclWriter, void> {
 
     PCHWriter &Writer;
+    ASTContext &Context;
     PCHWriter::RecordData &Record;
 
   public:
     pch::DeclCode Code;
 
-    PCHDeclWriter(PCHWriter &Writer, PCHWriter::RecordData &Record) 
-      : Writer(Writer), Record(Record) { }
+    PCHDeclWriter(PCHWriter &Writer, ASTContext &Context, 
+                  PCHWriter::RecordData &Record) 
+      : Writer(Writer), Context(Context), Record(Record) { }
 
     void VisitDecl(Decl *D);
     void VisitTranslationUnitDecl(TranslationUnitDecl *D);
@@ -340,7 +342,7 @@
   VisitValueDecl(D);
   Record.push_back(D->isThisDeclarationADefinition());
   if (D->isThisDeclarationADefinition())
-    Writer.AddStmt(D->getBody());
+    Writer.AddStmt(D->getBody(Context));
   Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
   Record.push_back(D->getStorageClass()); // FIXME: stable encoding
   Record.push_back(D->isInline());
@@ -1474,7 +1476,7 @@
 
   // Emit all of the declarations.
   RecordData Record;
-  PCHDeclWriter W(*this, Record);
+  PCHDeclWriter W(*this, Context, Record);
   while (!DeclsToEmit.empty()) {
     // Pull the next declaration off the queue
     Decl *D = DeclsToEmit.front();

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr 17 19:02:19 2009
@@ -2824,7 +2824,7 @@
 
   // See if this is a redefinition.
   const FunctionDecl *Definition;
-  if (FD->getBody(Definition)) {
+  if (FD->getBody(Context, Definition)) {
     Diag(FD->getLocation(), diag::err_redefinition) << FD->getDeclName();
     Diag(Definition->getLocation(), diag::note_previous_definition);
   }

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr 17 19:02:19 2009
@@ -771,7 +771,7 @@
   if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
     isDef = (!VD->hasExternalStorage() || VD->getInit());
   } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-    isDef = FD->getBody();
+    isDef = FD->getBody(S.Context);
   } else if (isa<ObjCPropertyDecl>(D)) {
     // We ignore weak import on properties
     return;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Apr 17 19:02:19 2009
@@ -2417,7 +2417,7 @@
       // Check if we have too few/too many template arguments, based
       // on our knowledge of the function definition.
       const FunctionDecl *Def = 0;
-      if (FDecl->getBody(Def) && NumArgs != Def->param_size())
+      if (FDecl->getBody(Context, Def) && NumArgs != Def->param_size())
         Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
           << (NumArgs > Def->param_size()) << FDecl << Fn->getSourceRange();
     }

Modified: cfe/trunk/test/PCH/blocks.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/blocks.c?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/test/PCH/blocks.c (original)
+++ cfe/trunk/test/PCH/blocks.c Fri Apr 17 19:02:19 2009
@@ -1,9 +1,9 @@
 // Test this without pch.
-// RUN: clang-cc -fblocks -include %S/blocks.h -fsyntax-only -ast-print -o - %s
+// RUN: clang-cc -fblocks -include %S/blocks.h -fsyntax-only -emit-llvm -o - %s
 
 // Test with pch.
 // RUN: clang-cc -emit-pch -fblocks -o %t %S/blocks.h &&
-// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -ast-print -o - %s 
+// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -emit-llvm -o - %s 
 
 int do_add(int x, int y) { return add(x, y); }
 

Modified: cfe/trunk/test/PCH/stmts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/stmts.c?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/test/PCH/stmts.c (original)
+++ cfe/trunk/test/PCH/stmts.c Fri Apr 17 19:02:19 2009
@@ -1,9 +1,9 @@
 // Test this without pch.
-// RUN: clang-cc -include %S/stmts.h -fsyntax-only -ast-print -o - %s
+// RUN: clang-cc -include %S/stmts.h -fsyntax-only -emit-llvm -o - %s
 
 // Test with pch.
 // RUN: clang-cc -emit-pch -o %t %S/stmts.h &&
-// RUN: clang-cc -include-pch %t -fsyntax-only -ast-print -o - %s 
+// RUN: clang-cc -include-pch %t -fsyntax-only -emit-llvm -o - %s 
 
 void g0(void) { f0(5); }
 int g1(int x) { return f1(x); }

Modified: cfe/trunk/test/PCH/va_arg.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/va_arg.c?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/test/PCH/va_arg.c (original)
+++ cfe/trunk/test/PCH/va_arg.c Fri Apr 17 19:02:19 2009
@@ -1,10 +1,11 @@
 // Test this without pch.
-// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include %S/va_arg.h -fsyntax-only -ast-print -o - %s
+// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include %S/va_arg.h %s
 
 // Test with pch.
-// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -emit-pch -o %t %S/va_arg.h &&
-// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include-pch %t -fsyntax-only -ast-print -o - %s 
+// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -o %t %S/va_arg.h &&
+// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include-pch %t %s 
 
+// FIXME: Crash when emitting LLVM bitcode using PCH!
 char *g0(char** argv, int argc) { return argv[argc]; }
 
 char *g(char **argv) {

Modified: cfe/trunk/tools/clang-cc/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/ASTConsumers.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/ASTConsumers.cpp (original)
+++ cfe/trunk/tools/clang-cc/ASTConsumers.cpp Fri Apr 17 19:02:19 2009
@@ -80,9 +80,10 @@
   if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     PrintFunctionDeclStart(FD);
 
-    if (FD->getBody()) {
+    // FIXME: Pass a context here so we can use getBody()
+    if (FD->getBodyIfAvailable()) {
       Out << ' ';
-      FD->getBody()->printPretty(Out, 0, Indentation, true);
+      FD->getBodyIfAvailable()->printPretty(Out, 0, Indentation, true);
       Out << '\n';
     }
   } else if (isa<ObjCMethodDecl>(D)) {
@@ -221,7 +222,8 @@
 }
 
 void DeclPrinter::PrintFunctionDeclStart(FunctionDecl *FD) {
-  bool HasBody = FD->getBody();
+  // FIXME: pass a context so that we can use getBody.
+  bool HasBody = FD->getBodyIfAvailable();
   
   Out << '\n';
 
@@ -264,7 +266,7 @@
   AFT->getResultType().getAsStringInternal(Proto);
   Out << Proto;
   
-  if (!FD->getBody())
+  if (!FD->getBodyIfAvailable())
     Out << ";\n";
   // Doesn't print the body.
 }
@@ -596,10 +598,10 @@
   if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     PrintFunctionDeclStart(FD);
     
-    if (FD->getBody()) {
+    if (FD->getBodyIfAvailable()) {
       Out << '\n';
       // FIXME: convert dumper to use std::ostream?
-      FD->getBody()->dumpAll(*SM);
+      FD->getBodyIfAvailable()->dumpAll(*SM);
       Out << '\n';
     }
   } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
@@ -664,9 +666,9 @@
   if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     DeclPrinter().PrintFunctionDeclStart(FD);
     
-    if (FD->getBody()) {
+    if (FD->getBodyIfAvailable()) {
       llvm::cerr << '\n';
-      FD->getBody()->viewAST();
+      FD->getBodyIfAvailable()->viewAST();
       llvm::cerr << '\n';
     }
     return;

Modified: cfe/trunk/tools/clang-cc/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/AnalysisConsumer.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/AnalysisConsumer.cpp (original)
+++ cfe/trunk/tools/clang-cc/AnalysisConsumer.cpp Fri Apr 17 19:02:19 2009
@@ -425,7 +425,7 @@
           AnalyzeSpecificFunction != FD->getIdentifier()->getName())
         break;
       
-      Stmt* Body = FD->getBody();
+      Stmt* Body = FD->getBody(*Ctx);
       if (Body) HandleCode(FD, Body, FunctionActions);
       break;
     }

Modified: cfe/trunk/tools/clang-cc/RewriteBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/RewriteBlocks.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/RewriteBlocks.cpp (original)
+++ cfe/trunk/tools/clang-cc/RewriteBlocks.cpp Fri Apr 17 19:02:19 2009
@@ -1092,7 +1092,7 @@
     // definitions using the same code.
     RewriteFunctionProtoType(FD->getType(), FD);
     
-    if (CompoundStmt *Body = FD->getBody()) {
+    if (CompoundStmt *Body = FD->getBody(*Context)) {
       CurFunctionDef = FD;
       FD->setBody(cast_or_null<CompoundStmt>(RewriteFunctionBody(Body)));
       // This synthesizes and inserts the block "impl" struct, invoke function,
@@ -1104,7 +1104,7 @@
   }
   if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
     RewriteMethodDecl(MD);
-    if (Stmt *Body = MD->getBody()) {
+    if (Stmt *Body = MD->getBody(*Context)) {
       CurMethodDef = MD;
       RewriteFunctionBody(Body);
       InsertBlockLiteralsWithinMethod(MD);
@@ -1116,7 +1116,7 @@
       RewriteBlockPointerDecl(VD);
       if (VD->getInit()) {
         if (BlockExpr *CBE = dyn_cast<BlockExpr>(VD->getInit())) {
-          RewriteFunctionBody(CBE->getBody());
+          RewriteFunctionBody(CBE->getBody(*Context));
 
           // We've just rewritten the block body in place.
           // Now we snarf the rewritten text and stash it away for later use.

Modified: cfe/trunk/tools/clang-cc/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/RewriteObjC.cpp?rev=69406&r1=69405&r2=69406&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/RewriteObjC.cpp (original)
+++ cfe/trunk/tools/clang-cc/RewriteObjC.cpp Fri Apr 17 19:02:19 2009
@@ -994,7 +994,7 @@
     ObjCMethodDecl *OMD = *I;
     RewriteObjCMethodDecl(OMD, ResultStr);
     SourceLocation LocStart = OMD->getLocStart();
-    SourceLocation LocEnd = OMD->getBody()->getLocStart();
+    SourceLocation LocEnd = OMD->getBody(*Context)->getLocStart();
     
     const char *startBuf = SM->getCharacterData(LocStart);
     const char *endBuf = SM->getCharacterData(LocEnd);
@@ -1009,7 +1009,7 @@
     ObjCMethodDecl *OMD = *I;
     RewriteObjCMethodDecl(OMD, ResultStr);
     SourceLocation LocStart = OMD->getLocStart();
-    SourceLocation LocEnd = OMD->getBody()->getLocStart();
+    SourceLocation LocEnd = OMD->getBody(*Context)->getLocStart();
     
     const char *startBuf = SM->getCharacterData(LocStart);
     const char *endBuf = SM->getCharacterData(LocEnd);
@@ -4445,7 +4445,7 @@
     // definitions using the same code.
     RewriteBlocksInFunctionProtoType(FD->getType(), FD);
 
-    if (CompoundStmt *Body = FD->getBody()) {
+    if (CompoundStmt *Body = FD->getBody(*Context)) {
       CurFunctionDef = FD;
       CollectPropertySetters(Body);
       CurrentBody = Body;





More information about the cfe-commits mailing list