summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2017-11-20 17:57:42 +0000
committerErich Keane <erich.keane@intel.com>2017-11-20 17:57:42 +0000
commit5c086c7626fab2617c0178a3951378bcbce2271c (patch)
treee073f8fc692b20d4dfcd8aead20817d8bf883db1 /clang/lib/Frontend
parent991447d6f892f4763347528290093c10806ece74 (diff)
downloadbcm5719-llvm-5c086c7626fab2617c0178a3951378bcbce2271c.tar.gz
bcm5719-llvm-5c086c7626fab2617c0178a3951378bcbce2271c.zip
For Linux/gnu compatibility, preinclude <stdc-predef.h> if the file is available
As reported in llvm bugzilla 32377. Here’s a patch to add preinclude of stdc-predef.h. The gcc documentation says “On GNU/Linux, <stdc-predef.h> is pre-included.” See https://gcc.gnu.org/gcc-4.8/porting_to.html; The preinclude is inhibited with –ffreestanding. Basically I fixed the failing test cases by adding –ffreestanding which inhibits this behavior. I fixed all the failing tests, including some in extra/test, there's a separate patch for that which is linked here Patch By: mibintc Differential Revision: https://reviews.llvm.org/D34158 llvm-svn: 318669
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp4
-rw-r--r--clang/lib/Frontend/InitPreprocessor.cpp16
2 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 384124bee2b..748c7ffbcdf 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2594,6 +2594,10 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
for (const Arg *A : Args.filtered(OPT_chain_include))
Opts.ChainedIncludes.emplace_back(A->getValue());
+ // Add the ordered list of -fsystem-include-if-exists.
+ for (const Arg *A : Args.filtered(OPT_fsystem_include_if_exists))
+ Opts.FSystemIncludeIfExists.emplace_back(A->getValue());
+
for (const Arg *A : Args.filtered(OPT_remap_file)) {
std::pair<StringRef, StringRef> Split = StringRef(A->getValue()).split(';');
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 1dfbf187554..6980706a90d 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -70,6 +70,15 @@ static void AddImplicitInclude(MacroBuilder &Builder, StringRef File) {
Builder.append(Twine("#include \"") + File + "\"");
}
+/// AddImplicitSystemIncludeIfExists - Add an implicit system \#include of the
+/// specified file to the predefines buffer: precheck with __has_include.
+static void AddImplicitSystemIncludeIfExists(MacroBuilder &Builder,
+ StringRef File) {
+ Builder.append(Twine("#if __has_include( <") + File + ">)");
+ Builder.append(Twine("#include <") + File + ">");
+ Builder.append(Twine("#endif"));
+}
+
static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File) {
Builder.append(Twine("#__include_macros \"") + File + "\"");
// Marker token to stop the __include_macros fetch loop.
@@ -1110,6 +1119,13 @@ void clang::InitializePreprocessor(
// Exit the command line and go back to <built-in> (2 is LC_LEAVE).
if (!PP.getLangOpts().AsmPreprocessor)
Builder.append("# 1 \"<built-in>\" 2");
+
+ // Process -fsystem-include-if-exists directives.
+ for (unsigned i = 0,
+ e = InitOpts.FSystemIncludeIfExists.size(); i != e; ++i) {
+ const std::string &Path = InitOpts.FSystemIncludeIfExists[i];
+ AddImplicitSystemIncludeIfExists(Builder, Path);
+ }
// If -imacros are specified, include them now. These are processed before
// any -include directives.
OpenPOWER on IntegriCloud