[PATCH] conformtest.py: Pass -dD to compiler
H.J. Lu
hjl.tools@gmail.com
Tue Dec 17 11:22:06 GMT 2024
Since Clang doesn't support -dN, pass -dD to compiler. Split and
reconstruct #define directives to "#define MACRO".
Tested with GCC 14.2 and Clang 19.1.5.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
conform/conformtest.py | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/conform/conformtest.py b/conform/conformtest.py
index 8337afcdad..f3cd648ef8 100644
--- a/conform/conformtest.py
+++ b/conform/conformtest.py
@@ -620,7 +620,8 @@ class HeaderTests(object):
out_file = os.path.join(self.temp_dir, 'namespace-out')
with open(c_file, 'w') as c_file_out:
c_file_out.write('#include <%s>\n' % self.header)
- cmd = ('%s %s -E %s -P -Wp,-dN > %s'
+ # NB: Use -dD, instead of -dN, since Clang doesn't support -dN.
+ cmd = ('%s %s -E %s -P -Wp,-dD > %s'
% (self.cc, self.cflags_namespace, c_file, out_file))
subprocess.check_call(cmd, shell=True)
bad_tokens = set()
@@ -629,6 +630,21 @@ class HeaderTests(object):
line = line.strip()
if not line:
continue
+ if line.startswith('#define'):
+ # -dD outputs of #define directives are
+ # #define MACRO expression
+ # #define MACRO(arg...) expression
+ # Split them to
+ # ['#define', 'MACRO', 'expression']
+ # ['#define', 'MACRO(arg...)', 'expression']
+ line = line.split()
+ # Split the second element to
+ # ['MACRO']
+ # ['MACRO', 'arg...)']
+ macro = line[1].split("(")
+ # Reconstruct the line to
+ # #define MACRO
+ line = line[0] + ' ' + macro[0]
if re.match(r'# [1-9]', line):
continue
if line.startswith('#pragma GCC '):
--
2.47.1
More information about the Libc-alpha
mailing list