summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-10-17 14:55:37 +0000
committerDouglas Gregor <dgregor@apple.com>2011-10-17 14:55:37 +0000
commit71129d5e9e3a290df21ef8f3389c1b54b10f62cd (patch)
tree1a428c91cd676eb0e96231c15053feb9f1eeb5ec /clang
parentfd979b1eaf0f88210625b565166952d6e41fe592 (diff)
downloadbcm5719-llvm-71129d5e9e3a290df21ef8f3389c1b54b10f62cd.tar.gz
bcm5719-llvm-71129d5e9e3a290df21ef8f3389c1b54b10f62cd.zip
When building a module, use the macro definitions on the command line
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. llvm-svn: 142187
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Frontend/PreprocessorOptions.h1
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp17
-rw-r--r--clang/test/Modules/Inputs/CmdLine.framework/Headers/CmdLine.h6
-rw-r--r--clang/test/Modules/on-demand-build-warnings.m2
-rw-r--r--clang/test/Modules/on-demand-build.m8
-rw-r--r--clang/test/Modules/on-demand-macros.m13
6 files changed, 41 insertions, 6 deletions
diff --git a/clang/include/clang/Frontend/PreprocessorOptions.h b/clang/include/clang/Frontend/PreprocessorOptions.h
index 30a34060b25..0ee8cb38744 100644
--- a/clang/include/clang/Frontend/PreprocessorOptions.h
+++ b/clang/include/clang/Frontend/PreprocessorOptions.h
@@ -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();
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 53581061448..1debf3b3531 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -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/clang/test/Modules/Inputs/CmdLine.framework/Headers/CmdLine.h b/clang/test/Modules/Inputs/CmdLine.framework/Headers/CmdLine.h
new file mode 100644
index 00000000000..46b8fc0425a
--- /dev/null
+++ b/clang/test/Modules/Inputs/CmdLine.framework/Headers/CmdLine.h
@@ -0,0 +1,6 @@
+#ifdef FOO_RETURNS_INT_PTR
+int *foo(void);
+#else
+float *foo(void);
+#endif
+
diff --git a/clang/test/Modules/on-demand-build-warnings.m b/clang/test/Modules/on-demand-build-warnings.m
index ea531698cf5..aa122dbd855 100644
--- a/clang/test/Modules/on-demand-build-warnings.m
+++ b/clang/test/Modules/on-demand-build-warnings.m
@@ -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}}
diff --git a/clang/test/Modules/on-demand-build.m b/clang/test/Modules/on-demand-build.m
index 418e912f637..649caa8a7d8 100644
--- a/clang/test/Modules/on-demand-build.m
+++ b/clang/test/Modules/on-demand-build.m
@@ -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/clang/test/Modules/on-demand-macros.m b/clang/test/Modules/on-demand-macros.m
new file mode 100644
index 00000000000..96abb2331f1
--- /dev/null
+++ b/clang/test/Modules/on-demand-macros.m
@@ -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
+}
OpenPOWER on IntegriCloud