]> granicus.if.org Git - clang/commitdiff
clang-cc: Simplify this code, now that predefines handling is uniform in the
authorDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 05:33:31 +0000 (05:33 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 05:33:31 +0000 (05:33 +0000)
PCH/-E and PCH/not--E cases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86808 91177308-0d34-0410-b5e6-96231b3b80d8

tools/clang-cc/clang-cc.cpp

index a13d1a4da44e9d03a7fbaf2b5a57d4281d8352a3..8bf02f748f71a86b8e7cf6475107038c44f13c94 100644 (file)
@@ -1114,39 +1114,27 @@ static void InitializePreprocessorOptions(PreprocessorOptions &InitOpts) {
     // We want to add these paths to the predefines buffer in order, make a
     // temporary vector to sort by their occurrence.
     llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
+    std::string OriginalFile; // For use by -implicit-include-pch.
 
     if (!ImplicitIncludePTH.empty())
       OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
                                             &ImplicitIncludePTH));
-    if (!ImplicitIncludePCH.empty())
+    if (!ImplicitIncludePCH.empty()) {
+      OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
+      // FIXME: Don't fail like this.
+      if (OriginalFile.empty())
+        exit(1);
       OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
-                                            &ImplicitIncludePCH));
+                                            &OriginalFile));
+    }
     for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
       OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
                                             &ImplicitIncludes[i]));
     llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
 
     // Now that they are ordered by position, add to the predefines buffer.
-    for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i) {
-      std::string *Ptr = OrderedPaths[i].second;
-      if (!ImplicitIncludes.empty() &&
-          Ptr >= &ImplicitIncludes[0] &&
-          Ptr <= &ImplicitIncludes[ImplicitIncludes.size()-1]) {
-        InitOpts.addInclude(*Ptr);
-      } else if (Ptr == &ImplicitIncludePTH) {
-        InitOpts.addInclude(*Ptr);
-      } else {
-        // We end up here when we're producing preprocessed output and
-        // we loaded a PCH file. In this case, just include the header
-        // file that was used to build the precompiled header.
-        assert(Ptr == &ImplicitIncludePCH);
-        std::string OriginalFile = PCHReader::getOriginalSourceFile(*Ptr);
-        // FIXME: Don't fail like this.
-        if (OriginalFile.empty())
-          exit(1);
-        InitOpts.addInclude(OriginalFile);
-      }
-    }
+    for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
+      InitOpts.addInclude(*OrderedPaths[i].second);
   }
 }