r174385 - [frontend] Don't put a PCH/PTH filename into the set of includes in the preprocessor options;

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Feb 5 08:36:52 PST 2013


Author: akirtzidis
Date: Tue Feb  5 10:36:52 2013
New Revision: 174385

URL: http://llvm.org/viewvc/llvm-project?rev=174385&view=rev
Log:
[frontend] Don't put a PCH/PTH filename into the set of includes in the preprocessor options;
since only one of them is allowed in command-line, process them separately.

Otherwise, if more than one is specified in the command-line, one is processed normally
and the others are going to be treated and included as header files.

Related to radar://13140508

Added:
    cfe/trunk/test/PCH/multiple-include-pch.c
Modified:
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/FrontendAction.cpp
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=174385&r1=174384&r2=174385&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Feb  5 10:36:52 2013
@@ -1345,8 +1345,7 @@ static void ParsePreprocessorArgs(Prepro
   Opts.MacroIncludes = Args.getAllArgValues(OPT_imacros);
 
   // Add the ordered list of -includes.
-  for (arg_iterator it = Args.filtered_begin(OPT_include, OPT_include_pch,
-                                             OPT_include_pth),
+  for (arg_iterator it = Args.filtered_begin(OPT_include),
          ie = Args.filtered_end(); it != ie; ++it) {
     const Arg *A = *it;
     Opts.Includes.push_back(A->getValue());

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=174385&r1=174384&r2=174385&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Tue Feb  5 10:36:52 2013
@@ -247,16 +247,8 @@ bool FrontendAction::BeginSourceFile(Com
                                            CI.getLangOpts(),
                                            CI.getTargetOpts(),
                                            CI.getPreprocessorOpts())) {
-          for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) {
-            if (PPOpts.Includes[I] == PPOpts.ImplicitPCHInclude) {
-              PPOpts.Includes[I] = Dir->path();
-              PPOpts.ImplicitPCHInclude = Dir->path();
-              Found = true;
-              break;
-            }
-          }
-
-          assert(Found && "Implicit PCH include not in includes list?");
+          PPOpts.ImplicitPCHInclude = Dir->path();
+          Found = true;
           break;
         }
       }

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=174385&r1=174384&r2=174385&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Tue Feb  5 10:36:52 2013
@@ -784,15 +784,16 @@ void clang::InitializePreprocessor(Prepr
     AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i],
                              PP.getFileManager());
 
+  // Process -include-pch/-include-pth directives.
+  if (!InitOpts.ImplicitPCHInclude.empty())
+    AddImplicitIncludePCH(Builder, PP, InitOpts.ImplicitPCHInclude);
+  if (!InitOpts.ImplicitPTHInclude.empty())
+    AddImplicitIncludePTH(Builder, PP, InitOpts.ImplicitPTHInclude);
+
   // Process -include directives.
   for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
     const std::string &Path = InitOpts.Includes[i];
-    if (Path == InitOpts.ImplicitPTHInclude)
-      AddImplicitIncludePTH(Builder, PP, Path);
-    else if (Path == InitOpts.ImplicitPCHInclude)
-      AddImplicitIncludePCH(Builder, PP, Path);
-    else
-      AddImplicitInclude(Builder, Path, PP.getFileManager());
+    AddImplicitInclude(Builder, Path, PP.getFileManager());
   }
 
   // Exit the command line and go back to <built-in> (2 is LC_LEAVE).

Added: cfe/trunk/test/PCH/multiple-include-pch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/multiple-include-pch.c?rev=174385&view=auto
==============================================================================
--- cfe/trunk/test/PCH/multiple-include-pch.c (added)
+++ cfe/trunk/test/PCH/multiple-include-pch.c Tue Feb  5 10:36:52 2013
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-pch -o %t1.pch %s
+// RUN: %clang_cc1 -emit-pch -o %t2.pch %s
+// RUN: %clang_cc1 %s -include-pch %t1.pch -include-pch %t2.pch -verify
+
+#ifndef HEADER
+#define HEADER
+
+extern int x;
+
+#else
+
+#warning parsed this
+// expected-warning at -1 {{parsed this}}
+int foo() {
+  return x;
+}
+
+#endif





More information about the cfe-commits mailing list