[cfe-commits] r139512 - in /cfe/trunk: lib/Frontend/ASTUnit.cpp lib/Serialization/ASTReader.cpp test/Index/preamble-reparse-cmd-define.c test/Index/preamble-reparse-cmd-define.c.h test/Index/preamble-reparse-cmd-define.c.remap
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Sep 12 11:09:38 PDT 2011
Author: akirtzidis
Date: Mon Sep 12 13:09:38 2011
New Revision: 139512
URL: http://llvm.org/viewvc/llvm-project?rev=139512&view=rev
Log:
[libclang] In ASTUnit::Parse copy the CompilerInvocation object instead of
modifying directly for the preamble.
This avoids an awful, hard to find, bug where "PreprocessorOpts.DisablePCHValidation = true"
would be persistent for subsequent reparses of the translation unit which would result
in defines, present in command-line but not in the PCH, being ignored.
Fixes rdar://9615399.
Added:
cfe/trunk/test/Index/preamble-reparse-cmd-define.c
cfe/trunk/test/Index/preamble-reparse-cmd-define.c.h
cfe/trunk/test/Index/preamble-reparse-cmd-define.c.remap
Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=139512&r1=139511&r2=139512&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Sep 12 13:09:38 2011
@@ -879,7 +879,10 @@
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
CICleanup(Clang.get());
- Clang->setInvocation(&*Invocation);
+ llvm::IntrusiveRefCntPtr<CompilerInvocation>
+ CCInvocation(new CompilerInvocation(*Invocation));
+
+ Clang->setInvocation(CCInvocation.getPtr());
OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].second;
// Set up diagnostics, capturing any diagnostics that would
@@ -942,13 +945,11 @@
PreprocessorOptions &PreprocessorOpts = Clang->getPreprocessorOpts();
PreprocessorOpts.DetailedRecordIncludesNestedMacroExpansions
= NestedMacroExpansions;
- std::string PriorImplicitPCHInclude;
if (OverrideMainBuffer) {
PreprocessorOpts.addRemappedFile(OriginalSourceFile, OverrideMainBuffer);
PreprocessorOpts.PrecompiledPreambleBytes.first = Preamble.size();
PreprocessorOpts.PrecompiledPreambleBytes.second
= PreambleEndsAtStartOfLine;
- PriorImplicitPCHInclude = PreprocessorOpts.ImplicitPCHInclude;
PreprocessorOpts.ImplicitPCHInclude = PreambleFile;
PreprocessorOpts.DisablePCHValidation = true;
@@ -967,9 +968,6 @@
// Keep track of the override buffer;
SavedMainFileBuffer = OverrideMainBuffer;
- } else {
- PreprocessorOpts.PrecompiledPreambleBytes.first = 0;
- PreprocessorOpts.PrecompiledPreambleBytes.second = false;
}
llvm::OwningPtr<TopLevelDeclTrackerAction> Act(
@@ -1003,21 +1001,11 @@
Act->EndSourceFile();
- // Remove the overridden buffer we used for the preamble.
- if (OverrideMainBuffer) {
- PreprocessorOpts.eraseRemappedFile(
- PreprocessorOpts.remapped_file_buffer_end() - 1);
- PreprocessorOpts.ImplicitPCHInclude = PriorImplicitPCHInclude;
- }
-
return false;
error:
// Remove the overridden buffer we used for the preamble.
if (OverrideMainBuffer) {
- PreprocessorOpts.eraseRemappedFile(
- PreprocessorOpts.remapped_file_buffer_end() - 1);
- PreprocessorOpts.ImplicitPCHInclude = PriorImplicitPCHInclude;
delete OverrideMainBuffer;
SavedMainFileBuffer = 0;
}
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=139512&r1=139511&r2=139512&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Sep 12 13:09:38 2011
@@ -2595,7 +2595,11 @@
// Here comes stuff that we only do once the entire chain is loaded.
// Check the predefines buffers.
- if (!DisableValidation && Type != MK_Module && CheckPredefinesBuffers())
+ if (!DisableValidation && Type != MK_Module && Type != MK_Preamble &&
+ // FIXME: CheckPredefinesBuffers also sets the SuggestedPredefines;
+ // if DisableValidation is true, defines that were set on command-line
+ // but not in the PCH file will not be added to SuggestedPredefines.
+ CheckPredefinesBuffers())
return IgnorePCH;
// Initialization of keywords and pragmas occurs before the
Added: cfe/trunk/test/Index/preamble-reparse-cmd-define.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble-reparse-cmd-define.c?rev=139512&view=auto
==============================================================================
--- cfe/trunk/test/Index/preamble-reparse-cmd-define.c (added)
+++ cfe/trunk/test/Index/preamble-reparse-cmd-define.c Mon Sep 12 13:09:38 2011
@@ -0,0 +1,9 @@
+// RUN: c-index-test -write-pch %t.h.pch %s.h
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_REMAP_AFTER_TRIAL=1 c-index-test -test-load-source-reparse 3 local \
+// RUN: "-remap-file=%s;%s.remap" %s -include %t.h -D CMD_MACRO=1 2>&1 | FileCheck %s
+
+// CHECK-NOT: error:
+
+int foo() {
+ return x;
+}
Added: cfe/trunk/test/Index/preamble-reparse-cmd-define.c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble-reparse-cmd-define.c.h?rev=139512&view=auto
==============================================================================
--- cfe/trunk/test/Index/preamble-reparse-cmd-define.c.h (added)
+++ cfe/trunk/test/Index/preamble-reparse-cmd-define.c.h Mon Sep 12 13:09:38 2011
@@ -0,0 +1 @@
+extern int x;
Added: cfe/trunk/test/Index/preamble-reparse-cmd-define.c.remap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble-reparse-cmd-define.c.remap?rev=139512&view=auto
==============================================================================
--- cfe/trunk/test/Index/preamble-reparse-cmd-define.c.remap (added)
+++ cfe/trunk/test/Index/preamble-reparse-cmd-define.c.remap Mon Sep 12 13:09:38 2011
@@ -0,0 +1,8 @@
+
+#ifndef CMD_MACRO
+#error CMD_MACRO undefined
+#endif
+
+int foo() {
+ return x;
+}
More information about the cfe-commits
mailing list