]> granicus.if.org Git - clang/commitdiff
When building a module, use the macro definitions on the command line
authorDouglas Gregor <dgregor@apple.com>
Mon, 17 Oct 2011 14:55:37 +0000 (14:55 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 17 Oct 2011 14:55:37 +0000 (14:55 +0000)
as part of the hash rather than ignoring them. This means we'll end up
building more module variants (overall), but it allows configuration
macros such as NDEBUG to work so long as they're specified via command
line. More to come in this space.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142187 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PreprocessorOptions.h
lib/Frontend/CompilerInvocation.cpp
test/Modules/Inputs/CmdLine.framework/Headers/CmdLine.h [new file with mode: 0644]
test/Modules/on-demand-build-warnings.m
test/Modules/on-demand-build.m
test/Modules/on-demand-macros.m [new file with mode: 0644]

index 30a34060b25b861d06e5ca64dc0d056b41d4fa27..0ee8cb38744a60144223d635260a4a25bbf68bc1 100644 (file)
@@ -206,7 +206,6 @@ public:
   /// \brief Reset any options that are not considered when building a
   /// module.
   void resetNonModularOptions() {
-    Macros.clear();
     Includes.clear();
     MacroIncludes.clear();
     ChainedIncludes.clear();
index 535810614486c966191e3bdfe44bb22cf036e969..1debf3b353187f8a077783612b010cd1dd284b5c 100644 (file)
@@ -2026,6 +2026,23 @@ std::string CompilerInvocation::getModuleHash() const {
   Signature.add(getPreprocessorOpts().UsePredefines, 1);
   Signature.add(getPreprocessorOpts().DetailedRecord, 1);
   
+  // Hash the preprocessor defines.
+  // FIXME: This is terrible. Use an MD5 sum of the preprocessor defines.
+  std::vector<StringRef> MacroDefs;
+  for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator 
+            I = getPreprocessorOpts().Macros.begin(),
+         IEnd = getPreprocessorOpts().Macros.end();
+       I != IEnd; ++I) {
+    if (!I->second)
+      MacroDefs.push_back(I->first);
+  }
+  llvm::array_pod_sort(MacroDefs.begin(), MacroDefs.end());
+       
+  unsigned PPHashResult = 0;
+  for (unsigned I = 0, N = MacroDefs.size(); I != N; ++I)
+    PPHashResult = llvm::HashString(MacroDefs[I], PPHashResult);
+  Signature.add(PPHashResult, 32);
+  
   // We've generated the signature. Treat it as one large APInt that we'll
   // encode in base-36 and return.
   Signature.flush();
diff --git a/test/Modules/Inputs/CmdLine.framework/Headers/CmdLine.h b/test/Modules/Inputs/CmdLine.framework/Headers/CmdLine.h
new file mode 100644 (file)
index 0000000..46b8fc0
--- /dev/null
@@ -0,0 +1,6 @@
+#ifdef FOO_RETURNS_INT_PTR
+int *foo(void);
+#else
+float *foo(void);
+#endif
+
index ea531698cf58abd2e24a12504c041d9246ebf7db..aa122dbd85590d59722da41d63d3e257149b272e 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Wmodule-build -fmodule-cache-path %t -F %S/Inputs -DFOO -verify %s
+// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Wmodule-build -fmodule-cache-path %t -F %S/Inputs -verify %s
 
 __import_module__ Module; // expected-warning{{building module 'Module' from source}}
 
index 418e912f6370fa699a2e2a788a8a2902c592a952..649caa8a7d8050bd7464e0d47e26635465031d69 100644 (file)
@@ -1,8 +1,8 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Werror -fmodule-cache-path %t -F %S/Inputs -DFOO -verify %s
-// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Werror -x objective-c++ -fmodule-cache-path %t -F %S/Inputs -DFOO -verify %s
-// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Werror -fmodule-cache-path %t -F %S/Inputs -DFOO -verify %s
-
+// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Werror -fmodule-cache-path %t -F %S/Inputs -verify %s
+// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Werror -x objective-c++ -fmodule-cache-path %t -F %S/Inputs -verify %s
+// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Werror -fmodule-cache-path %t -F %S/Inputs -verify %s
+#define FOO
 __import_module__ Module;
 @interface OtherClass
 @end
diff --git a/test/Modules/on-demand-macros.m b/test/Modules/on-demand-macros.m
new file mode 100644 (file)
index 0000000..96abb23
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodule-cache-path %t -F %S/Inputs -DFOO_RETURNS_INT_PTR -verify %s
+// RUN: %clang_cc1 -fmodule-cache-path %t -F %S/Inputs -verify %s
+
+__import_module__ CmdLine;
+
+void test() {
+#ifdef FOO_RETURNS_INT_PTR
+  int *ip = foo();
+#else
+  float *fp = foo();
+#endif
+}