[libcxx-commits] [libcxx] [libc++] Add a %{verify} substitution (PR #70878)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 1 08:26:29 PDT 2023
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/70878
>From c67dbaeefcbde593d6790654a09264646da7bbc5 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 31 Oct 2023 20:16:35 -0400
Subject: [PATCH 1/4] [libc++] Add a %{verify} substitution
This makes it easier to write .sh.cpp tests that perform multiple
clang-verify checks in the same test.
---
.../convenience_substitutions/verify.sh.cpp | 15 +++++++++++
libcxx/utils/libcxx/test/format.py | 27 ++++++++++---------
2 files changed, 30 insertions(+), 12 deletions(-)
create mode 100644 libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp
diff --git a/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp b/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp
new file mode 100644
index 000000000000000..a34b5ff5740a6c2
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: verify-support
+
+// Make sure that we provide the %{verify} convenience substitution.
+
+// RUN: %{verify}
+
+static_assert(false, ""); // expected-error {{static assertion failed}}
diff --git a/libcxx/utils/libcxx/test/format.py b/libcxx/utils/libcxx/test/format.py
index 4106cd83db34b7d..8bd69be8172c494 100644
--- a/libcxx/utils/libcxx/test/format.py
+++ b/libcxx/utils/libcxx/test/format.py
@@ -75,11 +75,14 @@ def parseScript(test, preamble):
tmpDir, tmpBase = _getTempPaths(test)
substitutions = lit.TestRunner.getDefaultSubstitutions(test, tmpDir, tmpBase)
- # Check base substitutions and add the %{build} and %{run} convenience substitutions
+ # Check base substitutions and add the %{build}, %{verify} and %{run} convenience substitutions
+ #
+ # Note: We use -Wno-error with %{verify} to make sure that we don't treat all diagnostics as
+ # errors, which doesn't make sense for clang-verify tests because we may want to check
+ # for specific warning diagnostics.
_checkBaseSubstitutions(substitutions)
- substitutions.append(
- ("%{build}", "%{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe")
- )
+ substitutions.append(("%{build}", "%{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe"))
+ substitutions.append(("%{verify}", "%{cxx} %s %{flags} %{compile_flags} -fsyntax-only -Wno-error -Xclang -verify -Xclang -verify-ignore-unexpected=note -ferror-limit=0"))
substitutions.append(("%{run}", "%{exec} %t.exe"))
# Parse the test file, including custom directives
@@ -227,6 +230,13 @@ class CxxStandardLibraryTest(lit.formats.FileBasedTest):
file with the %{flags}, %{compile_flags} and %{link_flags}
substitutions, and that produces an executable named %t.exe.
+ %{verify}
+ Expands to a command-line that builds the current source
+ file with the %{flags} and %{compile_flags} substitutions
+ and enables clang-verify. This can be used to write .sh.cpp
+ tests that use clang-verify. Note that this substitution can
+ only be used when the 'verify-support' feature is available.
+
%{run}
Equivalent to `%{exec} %t.exe`. This is intended to be used
in conjunction with the %{build} substitution.
@@ -265,9 +275,6 @@ def getTestsForPath(self, testSuite, pathInSuite, litConfig, localConfig):
yield lit.Test.Test(testSuite, pathInSuite, localConfig)
def execute(self, test, litConfig):
- VERIFY_FLAGS = (
- "-Xclang -verify -Xclang -verify-ignore-unexpected=note -ferror-limit=0"
- )
supportsVerify = "verify-support" in test.config.available_features
filename = test.path_in_suite[-1]
@@ -306,11 +313,7 @@ def execute(self, test, litConfig):
),
)
steps = [
- # 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
- )
+ "%dbg(COMPILED WITH) %{verify}"
]
return self._executeShTest(test, litConfig, steps)
# Make sure to check these ones last, since they will match other
>From 0f860f206dc2e8e79a7fc004739f7953bc551146 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 1 Nov 2023 10:45:24 -0400
Subject: [PATCH 2/4] Fix test in C++03 mode
---
.../libcxx/selftest/convenience_substitutions/verify.sh.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp b/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp
index a34b5ff5740a6c2..ec60b7fcb618ba0 100644
--- a/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp
+++ b/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp
@@ -12,4 +12,5 @@
// RUN: %{verify}
-static_assert(false, ""); // expected-error {{static assertion failed}}
+struct Foo { };
+typedef Foo::x x; // expected-error {{no type named 'x' in 'Foo'}}
>From 0cc8b182d43d0bf2960495da5d0586ae62c30ea0 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 1 Nov 2023 10:47:49 -0400
Subject: [PATCH 3/4] Apply Python formatting
---
libcxx/utils/libcxx/test/format.py | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/libcxx/utils/libcxx/test/format.py b/libcxx/utils/libcxx/test/format.py
index 8bd69be8172c494..52c6f9cd8f2ef22 100644
--- a/libcxx/utils/libcxx/test/format.py
+++ b/libcxx/utils/libcxx/test/format.py
@@ -81,8 +81,15 @@ def parseScript(test, preamble):
# errors, which doesn't make sense for clang-verify tests because we may want to check
# for specific warning diagnostics.
_checkBaseSubstitutions(substitutions)
- substitutions.append(("%{build}", "%{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe"))
- substitutions.append(("%{verify}", "%{cxx} %s %{flags} %{compile_flags} -fsyntax-only -Wno-error -Xclang -verify -Xclang -verify-ignore-unexpected=note -ferror-limit=0"))
+ substitutions.append(
+ ("%{build}", "%{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe")
+ )
+ substitutions.append(
+ (
+ "%{verify}",
+ "%{cxx} %s %{flags} %{compile_flags} -fsyntax-only -Wno-error -Xclang -verify -Xclang -verify-ignore-unexpected=note -ferror-limit=0",
+ )
+ )
substitutions.append(("%{run}", "%{exec} %t.exe"))
# Parse the test file, including custom directives
@@ -312,9 +319,7 @@ def execute(self, test, litConfig):
test.getFullName()
),
)
- steps = [
- "%dbg(COMPILED WITH) %{verify}"
- ]
+ steps = ["%dbg(COMPILED WITH) %{verify}"]
return self._executeShTest(test, litConfig, steps)
# Make sure to check these ones last, since they will match other
# suffixes above too.
>From 7efc291f323ebb53f2a3c87b3beb47f590c87db7 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 1 Nov 2023 11:26:14 -0400
Subject: [PATCH 4/4] Fix format in test
---
.../libcxx/selftest/convenience_substitutions/verify.sh.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp b/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp
index ec60b7fcb618ba0..d1713b44a086d23 100644
--- a/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp
+++ b/libcxx/test/libcxx/selftest/convenience_substitutions/verify.sh.cpp
@@ -12,5 +12,5 @@
// RUN: %{verify}
-struct Foo { };
+struct Foo {};
typedef Foo::x x; // expected-error {{no type named 'x' in 'Foo'}}
More information about the libcxx-commits
mailing list