From b31ac22ed75e6b0095f92f32bc5592a61211846b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 8 Apr 2009 20:15:42 +0000 Subject: [PATCH] According to the GCC man page, all -imacros are included before any -include's. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68633 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/clang-cc/clang-cc.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index ee90147e60..3260a750a2 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -1100,12 +1100,15 @@ static bool InitializePreprocessor(Preprocessor &PP, DefineBuiltinMacro(PredefineBuffer, U_macros[u++].c_str(), "#undef "); } - // FIXME: Read any files specified by -imacros. + // If -imacros are specified, include them now. These are processed before + // any -include directives. + + for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i) + AddImplicitIncludeMacros(PredefineBuffer, ImplicitMacroIncludes[i]); - if (!ImplicitIncludePTH.empty() || !ImplicitIncludes.empty() || - !ImplicitMacroIncludes.empty()) { - // We want to add these paths to the predefines buffer in order, make a temporary - // vector to sort by their occurrence. + if (!ImplicitIncludePTH.empty() || !ImplicitIncludes.empty()) { + // We want to add these paths to the predefines buffer in order, make a + // temporary vector to sort by their occurrence. llvm::SmallVector, 8> OrderedPaths; if (!ImplicitIncludePTH.empty()) @@ -1114,10 +1117,6 @@ static bool InitializePreprocessor(Preprocessor &PP, for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i) OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i), &ImplicitIncludes[i])); - for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i) - OrderedPaths.push_back(std::make_pair(ImplicitMacroIncludes - .getPosition(i), - &ImplicitMacroIncludes[i])); llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end()); // Now that they are ordered by position, add to the predefines buffer. @@ -1127,13 +1126,9 @@ static bool InitializePreprocessor(Preprocessor &PP, Ptr >= &ImplicitIncludes[0] && Ptr <= &ImplicitIncludes[ImplicitIncludes.size()-1]) { AddImplicitInclude(PredefineBuffer, *Ptr); - } else if (Ptr == &ImplicitIncludePTH) { - AddImplicitIncludePTH(PredefineBuffer, PP); } else { - assert(Ptr >= &ImplicitMacroIncludes[0] && - Ptr <= &ImplicitMacroIncludes[ImplicitMacroIncludes.size()-1] && - "String must have been in -imacros?"); - AddImplicitIncludeMacros(PredefineBuffer, *Ptr); + assert(Ptr == &ImplicitIncludePTH); + AddImplicitIncludePTH(PredefineBuffer, PP); } } }