[llvm-branch-commits] [cfe-branch] r114906 - in /cfe/branches/Apple/whitney: lib/Frontend/ASTUnit.cpp lib/Serialization/ASTReader.cpp test/Index/Inputs/a.h test/Index/Inputs/b.h test/Index/preamble-reparse-chained.c

Daniel Dunbar daniel at zuster.org
Mon Sep 27 15:13:07 PDT 2010


Author: ddunbar
Date: Mon Sep 27 17:13:07 2010
New Revision: 114906

URL: http://llvm.org/viewvc/llvm-project?rev=114906&view=rev
Log:
Merge r114774:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Fri Sep 24 23:29:12 2010 +0000

    When setting the globally-visible declarations for a particular
    identifier, we may have a Sema object but no translation unit scope
    (because parsing is finished). In this case, we still need to update
    the IdResolver, which might still be used when writing a PCH
    containing another PCH (without chaining). This bug manifested as a
    failure with precompiled preambles.

    Also, add a little environment-variable-sensitive logging for
    libclang.

Added:
    cfe/branches/Apple/whitney/test/Index/Inputs/a.h
    cfe/branches/Apple/whitney/test/Index/Inputs/b.h
    cfe/branches/Apple/whitney/test/Index/preamble-reparse-chained.c
Modified:
    cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp
    cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp

Modified: cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp?rev=114906&r1=114905&r2=114906&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp Mon Sep 27 17:13:07 2010
@@ -749,9 +749,20 @@
                         getSourceManager());
       StoredDiagnostics[I].setLocation(Loc);
     }
+
+    if (getenv("LIBCLANG_LOGGING"))
+      fprintf(stderr, "libclang: using precompiled preamble for \"%s\" at "
+              "\"%s\"\n",
+              OriginalSourceFile.c_str(),
+              PreambleFile.c_str());
+
   } else {
     PreprocessorOpts.PrecompiledPreambleBytes.first = 0;
     PreprocessorOpts.PrecompiledPreambleBytes.second = false;
+
+    if (getenv("LIBCLANG_LOGGING"))
+      fprintf(stderr, "libclang: not using precompiled preamble for \"%s\"\n",
+              OriginalSourceFile.c_str());
   }
   
   llvm::OwningPtr<TopLevelDeclTrackerAction> Act;
@@ -1215,6 +1226,13 @@
   // Create the source manager.
   Clang.setSourceManager(new SourceManager(getDiagnostics()));
   
+  if (getenv("LIBCLANG_LOGGING"))
+    fprintf(stderr, "libclang: creating precompiled preamble for \"%s\" at "
+            "\"%s\" (%u bytes)\n",
+            OriginalSourceFile.c_str(),
+            PreamblePCHPath.c_str(),
+            (unsigned)Preamble.size());
+
   llvm::OwningPtr<PrecompilePreambleAction> Act;
   Act.reset(new PrecompilePreambleAction(*this));
   if (!Act->BeginSourceFile(Clang, Clang.getFrontendOpts().Inputs[0].second,
@@ -1229,6 +1247,11 @@
     PreambleRebuildCounter = DefaultPreambleRebuildInterval;
     PreprocessorOpts.eraseRemappedFile(
                                PreprocessorOpts.remapped_file_buffer_end() - 1);
+
+    if (getenv("LIBCLANG_LOGGING"))
+      fprintf(stderr, "libclang: precompiled preamble compilation for \"%s\" "
+              "failed\n", OriginalSourceFile.c_str());
+
     return 0;
   }
   
@@ -1239,7 +1262,10 @@
   if (Diagnostics->hasErrorOccurred()) {
     // There were errors parsing the preamble, so no precompiled header was
     // generated. Forget that we even tried.
-    // FIXME: Should we leave a note for ourselves to try again?
+
+    if (getenv("LIBCLANG_LOGGING"))
+      fprintf(stderr, "libclang: precompiled preamble compilation for \"%s\" "
+              "failed\n", OriginalSourceFile.c_str());
     llvm::sys::Path(FrontendOpts.OutputFile).eraseFromDisk();
     Preamble.clear();
     if (CreatedPreambleBuffer)
@@ -1278,7 +1304,11 @@
   
   if (PreambleTimer)
     PreambleTimer->stopTimer();
-  
+
+  if (getenv("LIBCLANG_LOGGING"))
+    fprintf(stderr, "libclang: precompiled preamble for \"%s\" completed\n",
+            OriginalSourceFile.c_str());
+ 
   PreambleRebuildCounter = 1;
   PreprocessorOpts.eraseRemappedFile(
                                PreprocessorOpts.remapped_file_buffer_end() - 1);

Modified: cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp?rev=114906&r1=114905&r2=114906&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp Mon Sep 27 17:13:07 2010
@@ -3362,11 +3362,11 @@
 
   // Makes sure any declarations that were deserialized "too early"
   // still get added to the identifier's declaration chains.
-  if (SemaObj->TUScope) {
-    for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) {
+  for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) {
+    if (SemaObj->TUScope)
       SemaObj->TUScope->AddDecl(PreloadedDecls[I]);
-      SemaObj->IdResolver.AddDecl(PreloadedDecls[I]);
-    }
+
+    SemaObj->IdResolver.AddDecl(PreloadedDecls[I]);
   }
   PreloadedDecls.clear();
 
@@ -3564,8 +3564,8 @@
         // and add it to the declaration chain for this identifier, so
         // that (unqualified) name lookup will find it.
         SemaObj->TUScope->AddDecl(D);
-        SemaObj->IdResolver.AddDeclToIdentifierChain(II, D);
       }
+      SemaObj->IdResolver.AddDeclToIdentifierChain(II, D);
     } else {
       // Queue this declaration so that it will be added to the
       // translation unit scope and identifier's declaration chain

Added: cfe/branches/Apple/whitney/test/Index/Inputs/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/Inputs/a.h?rev=114906&view=auto
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/Inputs/a.h (added)
+++ cfe/branches/Apple/whitney/test/Index/Inputs/a.h Mon Sep 27 17:13:07 2010
@@ -0,0 +1,4 @@
+#ifndef A_H
+#define A_H
+typedef int A;
+#endif

Added: cfe/branches/Apple/whitney/test/Index/Inputs/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/Inputs/b.h?rev=114906&view=auto
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/Inputs/b.h (added)
+++ cfe/branches/Apple/whitney/test/Index/Inputs/b.h Mon Sep 27 17:13:07 2010
@@ -0,0 +1 @@
+typedef float B;

Added: cfe/branches/Apple/whitney/test/Index/preamble-reparse-chained.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/preamble-reparse-chained.c?rev=114906&view=auto
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/preamble-reparse-chained.c (added)
+++ cfe/branches/Apple/whitney/test/Index/preamble-reparse-chained.c Mon Sep 27 17:13:07 2010
@@ -0,0 +1,10 @@
+// RUN: c-index-test -write-pch %t.h.pch -x c-header %S/Inputs/a.h
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 all -I%S/Inputs -include %t.h %s | FileCheck %s
+#include "a.h"
+#include "b.h"
+
+A a;
+B b;
+
+// CHECK: a.h:3:13: TypedefDecl=A:3:13 (Definition) Extent=[3:13 - 3:14]
+// CHECK: b.h:1:15: TypedefDecl=B:1:15 (Definition) Extent=[1:15 - 1:16]





More information about the llvm-branch-commits mailing list