Skip to content

Commit 4e2216e

Browse files
[libc++][test] ADDITIONAL_COMPILE_FLAGS should be a space-separated list (#73541)
Found while running libc++'s test suite with MSVC's STL. `ADDITIONAL_COMPILE_FLAGS` is a `ParserKind.LIST`: https://github.com/llvm/llvm-project/blob/3c23ed156f0151923b168bdff0c34ec73fb37f38/libcxx/utils/libcxx/test/format.py#L104-L108 With a comma-separated example: https://github.com/llvm/llvm-project/blob/3c23ed156f0151923b168bdff0c34ec73fb37f38/libcxx/utils/libcxx/test/format.py#L223-L228 And comma-separated test coverage: https://github.com/llvm/llvm-project/blob/dd3184c30ff531b8aecea280e65233337dd02815/libcxx/test/libcxx/selftest/additional_compile_flags/substitutes-in-run.sh.cpp#L12-L15 Because the machinery splits on commas: https://github.com/llvm/llvm-project/blob/dd09221a29506031415cad8a1308998358633d48/llvm/utils/lit/lit/TestRunner.py#L1882-L1883 https://github.com/llvm/llvm-project/blob/dd09221a29506031415cad8a1308998358633d48/llvm/utils/lit/lit/TestRunner.py#L1951-L1956 However, most (although not all) usage of `ADDITIONAL_COMPILE_FLAGS` is treating it as space-separated. That apparently works in the normal Clang environment, but in my exotic configuration it causes `"-DMEOW -DWOOF"` to be passed as a single argument to MSVC, which then emits "warning C5102: ignoring invalid command-line macro definition `'_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT'`", causing test failures due to warnings-as-errors. This PR changes `ADDITIONAL_COMPILE_FLAGS` to actually be parsed as a space-separated list, and changes the few uses/examples that had commas.
1 parent 0ec4b82 commit 4e2216e

File tree

7 files changed

+61
-12
lines changed

7 files changed

+61
-12
lines changed

libcxx/test/libcxx/selftest/additional_compile_flags/substitutes-in-compile-flags.sh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
// Make sure that substitutions are performed inside additional compiler flags.
1414

1515
// ADDITIONAL_COMPILE_FLAGS: -I %t.1
16-
// ADDITIONAL_COMPILE_FLAGS: -isystem %t.2 , -isysroot %t.3
16+
// ADDITIONAL_COMPILE_FLAGS: -isystem %t.2 -isysroot %t.3
1717
// RUN: echo "-I %t.1 -isystem %t.2 -isysroot %t.3" | sed "s/\\\/\\\\\\\/g" > %t.escaped.grep
1818
// RUN: echo "%{compile_flags}" | grep -e -f %t.escaped.grep

libcxx/test/libcxx/selftest/additional_compile_flags/substitutes-in-run.sh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111

1212
// ADDITIONAL_COMPILE_FLAGS: -foo
1313
// ADDITIONAL_COMPILE_FLAGS: -bar
14-
// ADDITIONAL_COMPILE_FLAGS: -baz, -foom
14+
// ADDITIONAL_COMPILE_FLAGS: -baz -foom
1515
// RUN: echo "%{compile_flags}" | grep -e '-foo -bar -baz -foom'

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_fsizeddeallocation.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11}}
1616

1717
// REQUIRES: -fsized-deallocation
18-
// ADDITIONAL_COMPILE_FLAGS: -fsized-deallocation, -O3
18+
// ADDITIONAL_COMPILE_FLAGS: -fsized-deallocation -O3
1919

2020
#if !defined(__cpp_sized_deallocation)
2121
# error __cpp_sized_deallocation should be defined

libcxx/utils/libcxx/test/format.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def parseScript(test, preamble):
9999
),
100100
lit.TestRunner.IntegratedTestKeywordParser(
101101
"ADDITIONAL_COMPILE_FLAGS:",
102-
lit.TestRunner.ParserKind.LIST,
102+
lit.TestRunner.ParserKind.SPACE_LIST,
103103
initial_value=additionalCompileFlags,
104104
),
105105
]
@@ -110,7 +110,7 @@ def parseScript(test, preamble):
110110
for feature in test.config.available_features:
111111
parser = lit.TestRunner.IntegratedTestKeywordParser(
112112
"ADDITIONAL_COMPILE_FLAGS({}):".format(feature),
113-
lit.TestRunner.ParserKind.LIST,
113+
lit.TestRunner.ParserKind.SPACE_LIST,
114114
initial_value=additionalCompileFlags,
115115
)
116116
parsers.append(parser)
@@ -216,7 +216,7 @@ class CxxStandardLibraryTest(lit.formats.FileBasedTest):
216216
all the inputs necessary to run the test, such that e.g. execution
217217
on a remote host can be done by simply copying %T to the host.
218218
219-
// ADDITIONAL_COMPILE_FLAGS: flag1, flag2, flag3
219+
// ADDITIONAL_COMPILE_FLAGS: flag1 flag2 flag3
220220
221221
This directive will cause the provided flags to be added to the
222222
%{compile_flags} substitution for the test that contains it. This

llvm/utils/lit/lit/TestRunner.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ def getDefaultSubstitutions(test, tmpDir, tmpBase, normalize_slashes=False):
13521352

13531353
substitutions.append(("%{pathsep}", os.pathsep))
13541354
substitutions.append(("%basename_t", baseName))
1355-
1355+
13561356
substitutions.extend(
13571357
[
13581358
("%{fs-src-root}", pathlib.Path(sourcedir).anchor),
@@ -1795,6 +1795,7 @@ class ParserKind(object):
17951795
TAG: A keyword taking no value. Ex 'END.'
17961796
COMMAND: A keyword taking a list of shell commands. Ex 'RUN:'
17971797
LIST: A keyword taking a comma-separated list of values.
1798+
SPACE_LIST: A keyword taking a space-separated list of values.
17981799
BOOLEAN_EXPR: A keyword taking a comma-separated list of
17991800
boolean expressions. Ex 'XFAIL:'
18001801
INTEGER: A keyword taking a single integer. Ex 'ALLOW_RETRIES:'
@@ -1808,18 +1809,20 @@ class ParserKind(object):
18081809
TAG = 0
18091810
COMMAND = 1
18101811
LIST = 2
1811-
BOOLEAN_EXPR = 3
1812-
INTEGER = 4
1813-
CUSTOM = 5
1814-
DEFINE = 6
1815-
REDEFINE = 7
1812+
SPACE_LIST = 3
1813+
BOOLEAN_EXPR = 4
1814+
INTEGER = 5
1815+
CUSTOM = 6
1816+
DEFINE = 7
1817+
REDEFINE = 8
18161818

18171819
@staticmethod
18181820
def allowedKeywordSuffixes(value):
18191821
return {
18201822
ParserKind.TAG: ["."],
18211823
ParserKind.COMMAND: [":"],
18221824
ParserKind.LIST: [":"],
1825+
ParserKind.SPACE_LIST: [":"],
18231826
ParserKind.BOOLEAN_EXPR: [":"],
18241827
ParserKind.INTEGER: [":"],
18251828
ParserKind.CUSTOM: [":", "."],
@@ -1833,6 +1836,7 @@ def str(value):
18331836
ParserKind.TAG: "TAG",
18341837
ParserKind.COMMAND: "COMMAND",
18351838
ParserKind.LIST: "LIST",
1839+
ParserKind.SPACE_LIST: "SPACE_LIST",
18361840
ParserKind.BOOLEAN_EXPR: "BOOLEAN_EXPR",
18371841
ParserKind.INTEGER: "INTEGER",
18381842
ParserKind.CUSTOM: "CUSTOM",
@@ -1881,6 +1885,8 @@ def __init__(self, keyword, kind, parser=None, initial_value=None):
18811885
)
18821886
elif kind == ParserKind.LIST:
18831887
self.parser = self._handleList
1888+
elif kind == ParserKind.SPACE_LIST:
1889+
self.parser = self._handleSpaceList
18841890
elif kind == ParserKind.BOOLEAN_EXPR:
18851891
self.parser = self._handleBooleanExpr
18861892
elif kind == ParserKind.INTEGER:
@@ -1955,6 +1961,14 @@ def _handleList(line_number, line, output):
19551961
output.extend([s.strip() for s in line.split(",")])
19561962
return output
19571963

1964+
@staticmethod
1965+
def _handleSpaceList(line_number, line, output):
1966+
"""A parser for SPACE_LIST type keywords"""
1967+
if output is None:
1968+
output = []
1969+
output.extend([s.strip() for s in line.split(" ") if s.strip() != ""])
1970+
return output
1971+
19581972
@staticmethod
19591973
def _handleSingleInteger(line_number, line, output):
19601974
"""A parser for INTEGER type keywords"""

llvm/utils/lit/tests/Inputs/testrunner-custom-parsers/test.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
// MY_RUN: baz
55
// MY_LIST: one, two
66
// MY_LIST: three, four
7+
// MY_SPACE_LIST: orange
8+
// MY_SPACE_LIST: tabby tortie tuxedo
9+
// MY_SPACE_LIST: void
10+
// MY_SPACE_LIST: multiple spaces
11+
// MY_SPACE_LIST: cute, fluffy, kittens
712
// MY_RUN: foo \
813
// MY_RUN: bar
914
//
@@ -25,3 +30,4 @@
2530
//
2631
// END.
2732
// MY_LIST: five
33+
// MY_SPACE_LIST: zebra

llvm/utils/lit/tests/unit/TestRunner.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def custom_parse(line_number, line, output):
6161
IntegratedTestKeywordParser("MY_TAG.", ParserKind.TAG),
6262
IntegratedTestKeywordParser("MY_DNE_TAG.", ParserKind.TAG),
6363
IntegratedTestKeywordParser("MY_LIST:", ParserKind.LIST),
64+
IntegratedTestKeywordParser("MY_SPACE_LIST:", ParserKind.SPACE_LIST),
6465
IntegratedTestKeywordParser("MY_BOOL:", ParserKind.BOOLEAN_EXPR),
6566
IntegratedTestKeywordParser("MY_INT:", ParserKind.INTEGER),
6667
IntegratedTestKeywordParser("MY_RUN:", ParserKind.COMMAND),
@@ -104,6 +105,26 @@ def test_lists(self):
104105
list_parser = self.get_parser(parsers, "MY_LIST:")
105106
self.assertEqual(list_parser.getValue(), ["one", "two", "three", "four"])
106107

108+
def test_space_lists(self):
109+
parsers = self.make_parsers()
110+
self.parse_test(parsers)
111+
space_list_parser = self.get_parser(parsers, "MY_SPACE_LIST:")
112+
self.assertEqual(
113+
space_list_parser.getValue(),
114+
[
115+
"orange",
116+
"tabby",
117+
"tortie",
118+
"tuxedo",
119+
"void",
120+
"multiple",
121+
"spaces",
122+
"cute,",
123+
"fluffy,",
124+
"kittens",
125+
],
126+
)
127+
107128
def test_commands(self):
108129
parsers = self.make_parsers()
109130
self.parse_test(parsers)
@@ -222,6 +243,14 @@ def custom_parse(line_number, line, output):
222243
except BaseException as e:
223244
self.fail("LIST_WITH_DOT. raised the wrong exception: %r" % e)
224245

246+
try:
247+
IntegratedTestKeywordParser("SPACE_LIST_WITH_DOT.", ParserKind.SPACE_LIST),
248+
self.fail("SPACE_LIST_WITH_DOT. failed to raise an exception")
249+
except ValueError as e:
250+
pass
251+
except BaseException as e:
252+
self.fail("SPACE_LIST_WITH_DOT. raised the wrong exception: %r" % e)
253+
225254
try:
226255
IntegratedTestKeywordParser(
227256
"CUSTOM_NO_SUFFIX", ParserKind.CUSTOM, custom_parse

0 commit comments

Comments
 (0)