summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-09-13 20:44:41 +0000
committerDouglas Gregor <dgregor@apple.com>2011-09-13 20:44:41 +0000
commitf1312a828a2d482437823d757b7e6f32736b0a30 (patch)
treeb3edaf8bf6d28747ce384e1ff1b28de0079f3dab
parente3a6a82f1618dc3cfdd735e3e6fcb7a9e1150249 (diff)
downloadbcm5719-llvm-f1312a828a2d482437823d757b7e6f32736b0a30.tar.gz
bcm5719-llvm-f1312a828a2d482437823d757b7e6f32736b0a30.zip
When building a module on-demand, clear out the "non-modular" language
and preprocessor options (such as macro definitions) first. llvm-svn: 139638
-rw-r--r--clang/include/clang/Basic/LangOptions.def16
-rw-r--r--clang/include/clang/Basic/LangOptions.h4
-rw-r--r--clang/include/clang/Frontend/PreprocessorOptions.h10
-rw-r--r--clang/lib/Basic/LangOptions.cpp6
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp3
-rw-r--r--clang/test/Modules/Inputs/Module.framework/Headers/Module.h6
-rw-r--r--clang/test/Modules/on-demand-build.m2
7 files changed, 37 insertions, 10 deletions
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
index 381d44beb50..1fe6ece42d9 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -58,16 +58,16 @@ BENIGN_LANGOPT(ObjCInferRelatedResultType , 1, 1,
LANGOPT(Trigraphs , 1, 0,"trigraphs")
LANGOPT(BCPLComment , 1, 0, "BCPL-style '//' comments")
LANGOPT(Bool , 1, 0, "bool, true, and false keywords")
-BENIGN_LANGOPT(DollarIdents , 1, 0, "'$' in identifiers")
+BENIGN_LANGOPT(DollarIdents , 1, 1, "'$' in identifiers")
BENIGN_LANGOPT(AsmPreprocessor, 1, 0, "preprocessor in asm mode")
-BENIGN_LANGOPT(GNUMode , 1, 0, "GNU extensions")
-LANGOPT(GNUKeywords , 1, 0, "GNU keywords")
-BENIGN_LANGOPT(ImplicitInt, 1, 0, "C89 implicit 'int'")
+BENIGN_LANGOPT(GNUMode , 1, 1, "GNU extensions")
+LANGOPT(GNUKeywords , 1, 1, "GNU keywords")
+BENIGN_LANGOPT(ImplicitInt, 1, !C99 && !CPlusPlus, "C89 implicit 'int'")
LANGOPT(Digraphs , 1, 0, "digraphs")
-BENIGN_LANGOPT(HexFloats , 1, 0, "C99 hexadecimal float constants")
+BENIGN_LANGOPT(HexFloats , 1, C99, "C99 hexadecimal float constants")
LANGOPT(CXXOperatorNames , 1, 0, "C++ operator name keywords")
LANGOPT(AppleKext , 1, 0, "Apple kext support")
-BENIGN_LANGOPT(PascalStrings , 1, 0, "Pascal string support")
+BENIGN_LANGOPT(PascalStrings, 1, 0, "Pascal string support")
LANGOPT(WritableStrings , 1, 0, "writable string support")
LANGOPT(ConstStrings , 1, 0, "const-qualified string support")
LANGOPT(LaxVectorConversions , 1, 1, "lax vector conversions")
@@ -80,12 +80,12 @@ LANGOPT(TraditionalCPP , 1, 0, "traditional CPP emulation")
LANGOPT(RTTI , 1, 1, "run-time type information")
LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout")
LANGOPT(NeXTRuntime , 1, 1, "NeXT Objective-C runtime")
-BENIGN_LANGOPT(Freestanding , 1, 0, "freestanding implementation")
+LANGOPT(Freestanding, 1, 0, "freestanding implementation")
LANGOPT(NoBuiltin , 1, 0, "disable builtin functions")
BENIGN_LANGOPT(ThreadsafeStatics , 1, 1, "thread-safe static initializers")
LANGOPT(POSIXThreads , 1, 0, "POSIX thread support")
-BENIGN_LANGOPT(Blocks , 1, 0, "blocks extension to C")
+LANGOPT(Blocks , 1, 0, "blocks extension to C")
BENIGN_LANGOPT(EmitAllDecls , 1, 0, "support for emitting all declarations")
LANGOPT(MathErrno , 1, 1, "errno support for math functions")
BENIGN_LANGOPT(HeinousExtensions , 1, 0, "Extensions that we really don't like and may be ripped out at any time")
diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h
index e8e1afcaef5..688047ff5bd 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -66,6 +66,10 @@ public:
bool isSignedOverflowDefined() const {
return getSignedOverflowBehavior() == SOB_Defined;
}
+
+ /// \brief Reset all of the options that are not considered when building a
+ /// module.
+ void resetNonModularOptions();
};
/// Floating point control options
diff --git a/clang/include/clang/Frontend/PreprocessorOptions.h b/clang/include/clang/Frontend/PreprocessorOptions.h
index 040b8451998..3df65126005 100644
--- a/clang/include/clang/Frontend/PreprocessorOptions.h
+++ b/clang/include/clang/Frontend/PreprocessorOptions.h
@@ -190,6 +190,16 @@ public:
RemappedFiles.clear();
RemappedFileBuffers.clear();
}
+
+ /// \brief Reset any options that are not considered when building a
+ /// module.
+ void resetNonModularOptions() {
+ Macros.clear();
+ MacroIncludes.clear();
+ DumpDeserializedPCHDecls = false;
+ TokenCache.clear();
+ RetainRemappedFileBuffers = true;
+ }
};
} // end namespace clang
diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp
index d29f7774dce..e9e516f10d7 100644
--- a/clang/lib/Basic/LangOptions.cpp
+++ b/clang/lib/Basic/LangOptions.cpp
@@ -19,3 +19,9 @@ LangOptions::LangOptions() {
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) set##Name(Default);
#include "clang/Basic/LangOptions.def"
}
+
+void LangOptions::resetNonModularOptions() {
+#define LANGOPT(Name, Bits, Default, Description)
+#define BENIGN_LANGOPT(Name, Bits, Default, Description) Name = Default;
+}
+
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index f39b119c326..ece9cd8406c 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -654,6 +654,9 @@ static void compileModule(CompilerInstance &ImportingInstance,
// Construct a compiler invocation for creating this module.
llvm::IntrusiveRefCntPtr<CompilerInvocation> Invocation
(new CompilerInvocation(ImportingInstance.getInvocation()));
+ Invocation->getLangOpts().resetNonModularOptions();
+ Invocation->getPreprocessorOpts().resetNonModularOptions();
+
FrontendOptions &FrontendOpts = Invocation->getFrontendOpts();
FrontendOpts.OutputFile = ModuleFile.str();
FrontendOpts.DisableFree = false;
diff --git a/clang/test/Modules/Inputs/Module.framework/Headers/Module.h b/clang/test/Modules/Inputs/Module.framework/Headers/Module.h
index 1d9278b0ca1..af403c83955 100644
--- a/clang/test/Modules/Inputs/Module.framework/Headers/Module.h
+++ b/clang/test/Modules/Inputs/Module.framework/Headers/Module.h
@@ -1,6 +1,10 @@
const char *getModuleVersion(void);
+#ifdef FOO
+# error Module should have been built without -DFOO
+#endif
+
@interface Module
-+(const char *)version;
++(const char *)version; // retrieve module version
@end
diff --git a/clang/test/Modules/on-demand-build.m b/clang/test/Modules/on-demand-build.m
index 2191499cec3..42b8533a9ae 100644
--- a/clang/test/Modules/on-demand-build.m
+++ b/clang/test/Modules/on-demand-build.m
@@ -1,6 +1,6 @@
// RUN: mkdir -p %t
// RUN: rm -f %t/Module.pcm
-// RUN: %clang_cc1 -fmodule-cache-path %t -F %S/Inputs -verify %s
+// RUN: %clang_cc1 -fmodule-cache-path %t -F %S/Inputs -DFOO -verify %s
__import_module__ Module;
void test_getModuleVersion() {
OpenPOWER on IntegriCloud