aboutsummaryrefslogtreecommitdiff
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
commit1c7e0472f5683a8ade62285f366637050cf113e5 (patch)
tree5cce234698b9cc8c665aebdc1a29bea9843b652a
parent221d5a5005b3dbde50b8b0a40bb5c5e6da8c1173 (diff)
When building a module on-demand, clear out the "non-modular" language
and preprocessor options (such as macro definitions) first. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139638 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/LangOptions.def16
-rw-r--r--include/clang/Basic/LangOptions.h4
-rw-r--r--include/clang/Frontend/PreprocessorOptions.h10
-rw-r--r--lib/Basic/LangOptions.cpp6
-rw-r--r--lib/Frontend/CompilerInstance.cpp3
-rw-r--r--test/Modules/Inputs/Module.framework/Headers/Module.h6
-rw-r--r--test/Modules/on-demand-build.m2
7 files changed, 37 insertions, 10 deletions
diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def
index 381d44beb5..1fe6ece42d 100644
--- a/include/clang/Basic/LangOptions.def
+++ b/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/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index e8e1afcaef..688047ff5b 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/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/include/clang/Frontend/PreprocessorOptions.h b/include/clang/Frontend/PreprocessorOptions.h
index 040b845199..3df6512600 100644
--- a/include/clang/Frontend/PreprocessorOptions.h
+++ b/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/lib/Basic/LangOptions.cpp b/lib/Basic/LangOptions.cpp
index d29f7774dc..e9e516f10d 100644
--- a/lib/Basic/LangOptions.cpp
+++ b/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/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index f39b119c32..ece9cd8406 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/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/test/Modules/Inputs/Module.framework/Headers/Module.h b/test/Modules/Inputs/Module.framework/Headers/Module.h
index 1d9278b0ca..af403c8395 100644
--- a/test/Modules/Inputs/Module.framework/Headers/Module.h
+++ b/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/test/Modules/on-demand-build.m b/test/Modules/on-demand-build.m
index 2191499cec..42b8533a9a 100644
--- a/test/Modules/on-demand-build.m
+++ b/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() {