summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2014-04-29 00:36:53 +0000
committerBen Langmuir <blangmuir@apple.com>2014-04-29 00:36:53 +0000
commitbe84adbf1b7d2c7d30c524392151f7e14a82daff (patch)
treebba2a35725a23b1201a06381a091d88ab1bf5243 /clang/test
parent72d57ab32e3ec8d59c40ee13344e3692139ca737 (diff)
downloadbcm5719-llvm-be84adbf1b7d2c7d30c524392151f7e14a82daff.tar.gz
bcm5719-llvm-be84adbf1b7d2c7d30c524392151f7e14a82daff.zip
Check -Werror options during module validation
This patch checks whether the diagnostic options that could lead to errors (principally -Werror) are consistent between when a module was built and when it is loaded. If there are new -Werror flags, then the module is rebuilt. In order to canonicalize the options we do this check at the level of the constructed DiagnosticsEngine, which contains the final set of diag to diagnostic level mappings. Currently we only rebuild with the new diagnostic options, but we intend to refine this in the future to include the union of the new and old flags, since we know the old ones did not cause errors. System modules are only rebuilt when -Wsystem-headers is enabled. One oddity is that unlike checking language options, we don’t perform this diagnostic option checking when loading from a precompiled header. The reason for this is that the compiler cannot rebuild the PCH, so anything that requires it to be rebuilt effectively leaks into the build system. And in this case, that would mean the build system understanding the complex relationship between diagnostic options and the underlying diagnostic mappings, which is unreasonable. Skipping the check is safe, because these options do not affect the generated AST. You simply won’t get new build errors due to changed -Werror options automatically, which is also true for non-module cases. llvm-svn: 207477
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Modules/Werror-Wsystem-headers.m23
-rw-r--r--clang/test/Modules/Werror.m75
-rw-r--r--clang/test/Modules/module_file_info.m7
-rw-r--r--clang/test/Modules/resolution-change.m3
4 files changed, 107 insertions, 1 deletions
diff --git a/clang/test/Modules/Werror-Wsystem-headers.m b/clang/test/Modules/Werror-Wsystem-headers.m
new file mode 100644
index 00000000000..b3ca77e9602
--- /dev/null
+++ b/clang/test/Modules/Werror-Wsystem-headers.m
@@ -0,0 +1,23 @@
+// REQUIRES: shell
+// RUN: rm -rf %t
+// RUN: rm -rf %t-saved
+// RUN: mkdir %t-saved
+
+// Initial module build
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -isysroot %S/Inputs/System -fsyntax-only %s -verify
+// RUN: cp %t/cstd.pcm %t-saved/cstd.pcm
+
+// Even with -Werror don't rebuild a system module
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -isysroot %S/Inputs/System -fsyntax-only %s -verify -Werror
+// RUN: diff %t/cstd.pcm %t-saved/cstd.pcm
+
+// Unless -Wsystem-headers is on
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -isysroot %S/Inputs/System -fsyntax-only %s -verify \
+// RUN: -Werror=unused -Wsystem-headers
+// RUN: not diff %t/cstd.pcm %t-saved/cstd.pcm
+
+// expected-no-diagnostics
+@import cstd;
diff --git a/clang/test/Modules/Werror.m b/clang/test/Modules/Werror.m
new file mode 100644
index 00000000000..94a98a5a198
--- /dev/null
+++ b/clang/test/Modules/Werror.m
@@ -0,0 +1,75 @@
+// REQUIRES: shell
+// RUN: rm -rf %t
+// RUN: rm -rf %t-saved
+// RUN: mkdir -p %t-saved
+
+// Initial module build (-Werror=header-guard)
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -Werror=header-guard
+// RUN: cp %t/Module.pcm %t-saved/Module.pcm
+
+// Building with looser -Werror options does not rebuild
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella
+// RUN: diff %t/Module.pcm %t-saved/Module.pcm
+
+// Make the build more restricted (-Werror)
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -Werror -Wno-incomplete-umbrella
+// RUN: not diff %t/Module.pcm %t-saved/Module.pcm
+// RUN: cp %t/Module.pcm %t-saved/Module.pcm
+
+// Ensure -Werror=header-guard is less strict than -Werror
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -Werror=header-guard -Wno-incomplete-umbrella
+// RUN: diff %t/Module.pcm %t-saved/Module.pcm
+
+// But -Werror=unused is not, because some of its diags are DefaultIgnore
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -Werror=unused
+// RUN: not diff %t/Module.pcm %t-saved/Module.pcm
+// RUN: cp %t/Module.pcm %t-saved/Module.pcm
+
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -Werror -Wno-incomplete-umbrella
+
+// FIXME: when rebuilding the module, take the union of the diagnostic options
+// so that we don't need to rebuild here
+// RUN-DISABLED: diff %t/Module.pcm %t-saved/Module.pcm
+
+// -Wno-everything, -Werror
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -Wno-everything -Wall -Werror
+// RUN: cp %t/Module.pcm %t-saved/Module.pcm
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -Wall -Werror
+// RUN: not diff %t/Module.pcm %t-saved/Module.pcm
+
+// -pedantic, -Werror is not compatible with -Wall -Werror
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -Werror -pedantic
+// RUN: not diff %t/Module.pcm %t-saved/Module.pcm
+// RUN: cp %t/Module.pcm %t-saved/Module.pcm
+
+// -pedantic-errors is less strict that -pedantic, -Werror
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -pedantic-errors
+// RUN: diff %t/Module.pcm %t-saved/Module.pcm
+
+// -Wsystem-headers does not affect non-system modules
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fdisable-module-hash \
+// RUN: -F %S/Inputs -fsyntax-only %s -verify -Wno-incomplete-umbrella \
+// RUN: -pedantic-errors -Wsystem-headers
+// RUN: diff %t/Module.pcm %t-saved/Module.pcm
+
+// expected-no-diagnostics
+@import Module;
diff --git a/clang/test/Modules/module_file_info.m b/clang/test/Modules/module_file_info.m
index 9f1ff2221b7..13e086ee48a 100644
--- a/clang/test/Modules/module_file_info.m
+++ b/clang/test/Modules/module_file_info.m
@@ -2,7 +2,7 @@
@import DependsOnModule;
// RUN: rm -rf %t
-// RUN: %clang_cc1 -w -fmodules -fdisable-module-hash -fmodules-cache-path=%t -F %S/Inputs -DBLARG -DWIBBLE=WOBBLE %s
+// RUN: %clang_cc1 -w -Wunused -fmodules -fdisable-module-hash -fmodules-cache-path=%t -F %S/Inputs -DBLARG -DWIBBLE=WOBBLE %s
// RUN: %clang_cc1 -module-file-info %t/DependsOnModule.pcm | FileCheck %s
// CHECK: Generated by this Clang:
@@ -21,6 +21,11 @@
// CHECK: ABI:
// CHECK: Linker version:
+// CHECK: Diagnostic options:
+// CHECK: IgnoreWarnings: Yes
+// CHECK: Warning options:
+// CHECK: -Wunused
+
// CHECK: Header search options:
// CHECK: System root [-isysroot=]: '/'
// CHECK: Use builtin include directories [-nobuiltininc]: Yes
diff --git a/clang/test/Modules/resolution-change.m b/clang/test/Modules/resolution-change.m
index a69014c6ae7..011782eec2b 100644
--- a/clang/test/Modules/resolution-change.m
+++ b/clang/test/Modules/resolution-change.m
@@ -6,6 +6,9 @@
// Use the PCH with the same header search options; should be fine
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I %S/Inputs/modules-with-same-name/path1/A -include-pch %t-A.pch %s -fsyntax-only -Werror
+// Different -W options are ok
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I %S/Inputs/modules-with-same-name/path1/A -include-pch %t-A.pch %s -fsyntax-only -Werror -Wauto-import
+
// Use the PCH with no way to resolve DependsOnA
// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -include-pch %t-A.pch %s -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-NODOA %s
// CHECK-NODOA: module 'DependsOnA' imported by AST file '{{.*A.pch}}' not found
OpenPOWER on IntegriCloud