[libcxx-commits] [libcxx] 0c91e13 - [libc++] Make sure -Werror is enabled all the time, except in verify tests

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 1 07:45:48 PDT 2020


Author: Louis Dionne
Date: 2020-05-01T10:45:39-04:00
New Revision: 0c91e134e6966277ffbc283a43729342fcd31d9e

URL: https://github.com/llvm/llvm-project/commit/0c91e134e6966277ffbc283a43729342fcd31d9e
DIFF: https://github.com/llvm/llvm-project/commit/0c91e134e6966277ffbc283a43729342fcd31d9e.diff

LOG: [libc++] Make sure -Werror is enabled all the time, except in verify tests

Added: 
    libcxx/test/libcxx/selftest/newformat/pass.cpp/werror.pass.cpp
    libcxx/test/libcxx/selftest/newformat/sh.cpp/werror.sh.cpp
    libcxx/test/libcxx/selftest/newformat/verify.cpp/no-werror.verify.cpp

Modified: 
    libcxx/utils/libcxx/test/config.py
    libcxx/utils/libcxx/test/newformat.py

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/selftest/newformat/pass.cpp/werror.pass.cpp b/libcxx/test/libcxx/selftest/newformat/pass.cpp/werror.pass.cpp
new file mode 100644
index 000000000000..31b7453164ea
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/newformat/pass.cpp/werror.pass.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL: *
+
+// Make sure that even a simple unused variable warning is treated as an
+// error in the test suite. This is to make sure the test suite always runs
+// with -Werror.
+
+// ADDITIONAL_COMPILE_FLAGS: -Wunused-variable
+
+// TODO: We don't enable -Werror on GCC right now, because too many tests fail.
+// UNSUPPORTED: gcc
+
+int main() {
+    int foo;
+}

diff  --git a/libcxx/test/libcxx/selftest/newformat/sh.cpp/werror.sh.cpp b/libcxx/test/libcxx/selftest/newformat/sh.cpp/werror.sh.cpp
new file mode 100644
index 000000000000..5b84275bf687
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/newformat/sh.cpp/werror.sh.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL: *
+
+// Make sure that even a simple unused variable warning is treated as an
+// error in the test suite, including in .sh.cpp tests.
+
+// TODO: We don't enable -Werror on GCC right now, because too many tests fail.
+// UNSUPPORTED: gcc
+
+// FILE_DEPENDENCIES: %t.exe
+// RUN: %{build} -Wunused-variable
+// RUN: %{run}
+
+int main() {
+    int foo;
+}

diff  --git a/libcxx/test/libcxx/selftest/newformat/verify.cpp/no-werror.verify.cpp b/libcxx/test/libcxx/selftest/newformat/verify.cpp/no-werror.verify.cpp
new file mode 100644
index 000000000000..4b89be558525
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/newformat/verify.cpp/no-werror.verify.cpp
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Make sure clang-verify tests distinguish warnings from errors.
+
+// ADDITIONAL_COMPILE_FLAGS: -Wunused-variable
+
+int main() {
+    int foo; // expected-warning {{unused variable}}
+}

diff  --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py
index dc7e25c0cee2..3f718ed50789 100644
--- a/libcxx/utils/libcxx/test/config.py
+++ b/libcxx/utils/libcxx/test/config.py
@@ -819,7 +819,7 @@ def configure_warnings(self):
         enable_warnings = self.get_lit_bool('enable_warnings',
                                             default_enable_warnings)
         self.cxx.useWarnings(enable_warnings)
-        self.cxx.warning_flags += ['-Wall', '-Wextra']
+        self.cxx.warning_flags += ['-Werror', '-Wall', '-Wextra']
         # On GCC, the libc++ headers cause errors due to throw() decorators
         # on operator new clashing with those from the test suite, so we
         # don't enable warnings in system headers on GCC.
@@ -972,7 +972,7 @@ def configure_substitutions(self):
         sub.append(('%{libcxx_src_root}', self.libcxx_src_root))
         # Configure flags substitutions
         flags = self.cxx.flags + (self.cxx.modules_flags if self.cxx.use_modules else [])
-        compile_flags = self.cxx.compile_flags + self.cxx.warning_flags
+        compile_flags = self.cxx.compile_flags + (self.cxx.warning_flags if self.cxx.use_warnings else [])
         sub.append(('%{flags}',         ' '.join(map(pipes.quote, flags))))
         sub.append(('%{compile_flags}', ' '.join(map(pipes.quote, compile_flags))))
         sub.append(('%{link_flags}',    ' '.join(map(pipes.quote, self.cxx.link_flags))))

diff  --git a/libcxx/utils/libcxx/test/newformat.py b/libcxx/utils/libcxx/test/newformat.py
index a6aaf8ec6314..0bb3be3369ba 100644
--- a/libcxx/utils/libcxx/test/newformat.py
+++ b/libcxx/utils/libcxx/test/newformat.py
@@ -231,37 +231,33 @@ def execute(self, test, litConfig):
         if '-fmodules' in test.config.available_features and self._disableWithModules(test):
             return lit.Test.Result(lit.Test.UNSUPPORTED, 'Test {} is unsupported when modules are enabled')
 
-        # TODO(ldionne): Enable -Werror with all supported compilers.
-        clangOrAppleClang = {'clang', 'apple-clang'}.intersection(test.config.available_features) != set()
-        werror = '-Werror' if clangOrAppleClang else ''
-
         if re.search('[.]sh[.][^.]+$', filename):
             steps = [ ] # The steps are already in the script
             return self._executeShTest(test, litConfig, steps)
         elif filename.endswith('.compile.pass.cpp'):
             steps = [
-                "%dbg(COMPILED WITH) %{{cxx}} %s {} %{{flags}} %{{compile_flags}} -fsyntax-only".format(werror)
+                "%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} -fsyntax-only"
             ]
             return self._executeShTest(test, litConfig, steps)
         elif filename.endswith('.compile.fail.cpp'):
             steps = [
-                "%dbg(COMPILED WITH) ! %{{cxx}} %s {} %{{flags}} %{{compile_flags}} -fsyntax-only".format(werror)
+                "%dbg(COMPILED WITH) ! %{cxx} %s %{flags} %{compile_flags} -fsyntax-only"
             ]
             return self._executeShTest(test, litConfig, steps)
         elif filename.endswith('.link.pass.cpp'):
             steps = [
-                "%dbg(COMPILED WITH) %{{cxx}} %s {} %{{flags}} %{{compile_flags}} %{{link_flags}} -o %t.exe".format(werror)
+                "%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe"
             ]
             return self._executeShTest(test, litConfig, steps)
         elif filename.endswith('.link.fail.cpp'):
             steps = [
-                "%dbg(COMPILED WITH) %{{cxx}} %s {} %{{flags}} %{{compile_flags}} -c -o %t.o".format(werror),
+                "%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} -c -o %t.o",
                 "%dbg(LINKED WITH) ! %{cxx} %t.o %{flags} %{link_flags} -o %t.exe"
             ]
             return self._executeShTest(test, litConfig, steps)
         elif filename.endswith('.run.fail.cpp'):
             steps = [
-                "%dbg(COMPILED WITH) %{{cxx}} %s {} %{{flags}} %{{compile_flags}} %{{link_flags}} -o %t.exe".format(werror),
+                "%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe",
                 "%dbg(EXECUTED AS) %{exec} ! %t.exe"
             ]
             return self._executeShTest(test, litConfig, steps, fileDependencies=['%t.exe'])
@@ -270,14 +266,16 @@ def execute(self, test, litConfig):
                 return lit.Test.Result(lit.Test.UNSUPPORTED,
                     "Test {} requires support for Clang-verify, which isn't supported by the compiler".format(test.getFullName()))
             steps = [
-                "%dbg(COMPILED WITH) %{{cxx}} %s %{{flags}} %{{compile_flags}} -fsyntax-only {}".format(VERIFY_FLAGS)
+                # Note: Use -Wno-error to make sure all diagnostics are not treated as errors,
+                #       which doesn't make sense for clang-verify tests.
+                "%dbg(COMPILED WITH) %{{cxx}} %s %{{flags}} %{{compile_flags}} -fsyntax-only -Wno-error {}".format(VERIFY_FLAGS)
             ]
             return self._executeShTest(test, litConfig, steps)
         # Make sure to check these ones last, since they will match other
         # suffixes above too.
         elif filename.endswith('.pass.cpp') or filename.endswith('.pass.mm'):
             steps = [
-                "%dbg(COMPILED WITH) %{{cxx}} %s {} %{{flags}} %{{compile_flags}} %{{link_flags}} -o %t.exe".format(werror),
+                "%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe",
                 "%dbg(EXECUTED AS) %{exec} %t.exe"
             ]
             return self._executeShTest(test, litConfig, steps, fileDependencies=['%t.exe'])
@@ -287,11 +285,11 @@ def execute(self, test, litConfig):
         elif filename.endswith('.fail.cpp'):
             if supportsVerify:
                 steps = [
-                    "%dbg(COMPILED WITH) %{{cxx}} %s %{{flags}} %{{compile_flags}} -fsyntax-only {}".format(VERIFY_FLAGS)
+                    "%dbg(COMPILED WITH) %{{cxx}} %s %{{flags}} %{{compile_flags}} -fsyntax-only -Wno-error {}".format(VERIFY_FLAGS)
                 ]
             else:
                 steps = [
-                    "%dbg(COMPILED WITH) ! %{{cxx}} {} %s %{{flags}} %{{compile_flags}} -fsyntax-only".format(werror)
+                    "%dbg(COMPILED WITH) ! %{cxx} %s %{flags} %{compile_flags} -fsyntax-only"
                 ]
             return self._executeShTest(test, litConfig, steps)
         else:


        


More information about the libcxx-commits mailing list