[clang] 00a3c9f - [Frontend] Flip default of CreateInvocationOptions::ProbePrecompiled to false

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Tue May 10 07:58:40 PDT 2022


Author: Sam McCall
Date: 2022-05-10T16:58:13+02:00
New Revision: 00a3c9f2a46a566b3ff10f2d24b01426df2193ab

URL: https://github.com/llvm/llvm-project/commit/00a3c9f2a46a566b3ff10f2d24b01426df2193ab
DIFF: https://github.com/llvm/llvm-project/commit/00a3c9f2a46a566b3ff10f2d24b01426df2193ab.diff

LOG: [Frontend] Flip default of CreateInvocationOptions::ProbePrecompiled to false

This is generally a better default for tools other than the compiler, which
shouldn't assume a PCH file on disk is something they can consume.

Preserve the old behavior in places associated with libclang/c-index-test
(including ASTUnit) as there are tests relying on it and most important
consumers are out-of-tree. It's unclear whether the tests are specifically
trying to test this functionality, and what the downstream implications of
removing it are. Hopefully someone more familiar can clean this up in future.

Differential Revision: https://reviews.llvm.org/D125149

Added: 
    

Modified: 
    clang/include/clang/Frontend/Utils.h
    clang/lib/Frontend/ASTUnit.cpp
    clang/tools/c-index-test/core_main.cpp
    clang/tools/libclang/Indexing.cpp
    clang/unittests/Frontend/UtilsTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h
index 1e8841429ffa8..240624d5408f1 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -206,7 +206,7 @@ struct CreateInvocationOptions {
   /// This is used to replace -include with -include-pch in the cc1 args.
   /// FIXME: ProbePrecompiled=true is a poor, historical default.
   /// It misbehaves if the PCH file is from GCC, has the wrong version, etc.
-  bool ProbePrecompiled = true;
+  bool ProbePrecompiled = false;
   /// If set, the target is populated with the cc1 args produced by the driver.
   /// This may be populated even if createInvocation returns nullptr.
   std::vector<std::string> *CC1Args = nullptr;

diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 1d0f472e9c6e3..1cf20a0b662ad 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1732,6 +1732,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
     CreateInvocationOptions CIOpts;
     CIOpts.VFS = VFS;
     CIOpts.Diags = Diags;
+    CIOpts.ProbePrecompiled = true; // FIXME: historical default. Needed?
     CI = createInvocation(llvm::makeArrayRef(ArgBegin, ArgEnd),
                           std::move(CIOpts));
     if (!CI)

diff  --git a/clang/tools/c-index-test/core_main.cpp b/clang/tools/c-index-test/core_main.cpp
index c5f47baa84580..ea15b2bcd5c22 100644
--- a/clang/tools/c-index-test/core_main.cpp
+++ b/clang/tools/c-index-test/core_main.cpp
@@ -223,6 +223,7 @@ static bool printSourceSymbols(const char *Executable,
     Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions));
   CreateInvocationOptions CIOpts;
   CIOpts.Diags = Diags;
+  CIOpts.ProbePrecompiled = true; // FIXME: historical default. Needed?
   auto CInvok = createInvocation(ArgsWithProgName, std::move(CIOpts));
   if (!CInvok)
     return true;

diff  --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp
index 0534ccac290d1..206dd48828869 100644
--- a/clang/tools/libclang/Indexing.cpp
+++ b/clang/tools/libclang/Indexing.cpp
@@ -510,6 +510,7 @@ static CXErrorCode clang_indexSourceFile_Impl(
 
   CreateInvocationOptions CIOpts;
   CIOpts.Diags = Diags;
+  CIOpts.ProbePrecompiled = true; // FIXME: historical default. Needed?
   std::shared_ptr<CompilerInvocation> CInvok =
       createInvocation(*Args, std::move(CIOpts));
 

diff  --git a/clang/unittests/Frontend/UtilsTest.cpp b/clang/unittests/Frontend/UtilsTest.cpp
index 4c4b7b969107c..ae014d3f86b5a 100644
--- a/clang/unittests/Frontend/UtilsTest.cpp
+++ b/clang/unittests/Frontend/UtilsTest.cpp
@@ -48,20 +48,20 @@ TEST(BuildCompilerInvocationTest, ProbePrecompiled) {
   llvm::IntrusiveRefCntPtr<DiagnosticsEngine> CommandLineDiagsEngine =
       clang::CompilerInstance::createDiagnostics(new DiagnosticOptions, &D,
                                                  false);
-  // Default: ProbePrecompiled is true.
+  // Default: ProbePrecompiled=false
   CreateInvocationOptions CIOpts;
   CIOpts.Diags = CommandLineDiagsEngine;
   CIOpts.VFS = FS;
   std::unique_ptr<CompilerInvocation> CI = createInvocation(Args, CIOpts);
   ASSERT_TRUE(CI);
-  EXPECT_THAT(CI->getPreprocessorOpts().Includes, ElementsAre());
-  EXPECT_EQ(CI->getPreprocessorOpts().ImplicitPCHInclude, "foo.h.pch");
+  EXPECT_THAT(CI->getPreprocessorOpts().Includes, ElementsAre("foo.h"));
+  EXPECT_EQ(CI->getPreprocessorOpts().ImplicitPCHInclude, "");
 
-  CIOpts.ProbePrecompiled = false;
+  CIOpts.ProbePrecompiled = true;
   CI = createInvocation(Args, CIOpts);
   ASSERT_TRUE(CI);
-  EXPECT_THAT(CI->getPreprocessorOpts().Includes, ElementsAre("foo.h"));
-  EXPECT_EQ(CI->getPreprocessorOpts().ImplicitPCHInclude, "");
+  EXPECT_THAT(CI->getPreprocessorOpts().Includes, ElementsAre());
+  EXPECT_EQ(CI->getPreprocessorOpts().ImplicitPCHInclude, "foo.h.pch");
 }
 
 } // namespace


        


More information about the cfe-commits mailing list