]> granicus.if.org Git - clang/commitdiff
When building a module on-demand, clear out the "non-modular" language
authorDouglas Gregor <dgregor@apple.com>
Tue, 13 Sep 2011 20:44:41 +0000 (20:44 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 13 Sep 2011 20:44:41 +0000 (20:44 +0000)
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

include/clang/Basic/LangOptions.def
include/clang/Basic/LangOptions.h
include/clang/Frontend/PreprocessorOptions.h
lib/Basic/LangOptions.cpp
lib/Frontend/CompilerInstance.cpp
test/Modules/Inputs/Module.framework/Headers/Module.h
test/Modules/on-demand-build.m

index 381d44beb5029510585bd725995f3786678584fb..1fe6ece42d91c2327b216608c04a070d7e566b9f 100644 (file)
@@ -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")
index e8e1afcaef5e253b4540b8573e379db12e2be2bf..688047ff5bdf9b060f116d5b147be548ecec3946 100644 (file)
@@ -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
index 040b8451998714598883efd0c11073e4e6b33c31..3df65126005ba7734fd169e380085564c34be9a1 100644 (file)
@@ -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
index d29f7774dce7f34655d55b1f01e1d0c2d925d3c7..e9e516f10d7613b15a6ca847e332b198d4d91b54 100644 (file)
@@ -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;
+}
+
index f39b119c32653e3eb587d66946916e968f3acbcb..ece9cd8406ca6cc057eca30bf2d1bcd010ced820 100644 (file)
@@ -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;
index 1d9278b0ca17ec1fc3d75f2061f34222e69cd2ac..af403c83955308c198839e073d585c053f1a5afd 100644 (file)
@@ -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
 
index 2191499cec3246367efb7f2d4640a1c857687fc4..42b8533a9ae6e74253003305687d689eaec8d01c 100644 (file)
@@ -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() {