Author: Mattéo Rizza Murgier Date: 2026-11-02T09:43:16+01:00 New Revision: 0c0cb49887f5ca51978e4b4e8a53120f1ac69e22
URL: https://github.com/llvm/llvm-project/commit/0c0cb49887f5ca51978e4b4e8a53120f1ac69e22 DIFF: https://github.com/llvm/llvm-project/commit/0c0cb49887f5ca51978e4b4e8a53120f1ac69e22.diff LOG: [UpdateTestChecks] Add support for (RE)DEFINE directives (#237599) NOTE: This will be useful if we eventually want to auto-generate e.g. CIR tests (which currently rely on this). Added: clang/test/utils/update_cc_test_checks/Inputs/define.c clang/test/utils/update_cc_test_checks/Inputs/define.c.expected clang/test/utils/update_cc_test_checks/define.test Modified: llvm/utils/UpdateTestChecks/common.py Removed: ################################################################################ diff --git a/clang/test/utils/update_cc_test_checks/Inputs/define.c b/clang/test/utils/update_cc_test_checks/Inputs/define.c new file mode 100644 index 0000000000000..2ec8ab935fb29 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/define.c @@ -0,0 +1,12 @@ +// Check that DEFINE and REDEFINE substitutions are expanded in RUN lines. +// DEFINE: %{optimize} = opt -passes=mem2reg \ +// DEFINE: -S +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -disable-O0-optnone -emit-llvm %s -o - | %{optimize} | FileCheck %s --check-prefix=MEM2REG +// REDEFINE: %{optimize} = opt -passes=mem2reg,instcombine -S +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -disable-O0-optnone -emit-llvm %s -o - | %{optimize} | FileCheck %s --check-prefix=INSTCOMBINE +// DEFINE: %{pass1} = mem2reg +// DEFINE: %{pass2} = instcombine +// DEFINE: %{optimize-nested} = opt -passes=%{pass1},%{pass2} -S +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -disable-O0-optnone -emit-llvm %s -o - | %{optimize-nested} | FileCheck %s --check-prefix=NESTED + +int f(int a) { return (a + 1) - 1; } diff --git a/clang/test/utils/update_cc_test_checks/Inputs/define.c.expected b/clang/test/utils/update_cc_test_checks/Inputs/define.c.expected new file mode 100644 index 0000000000000..a9c537d696b15 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/define.c.expected @@ -0,0 +1,27 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// Check that DEFINE and REDEFINE substitutions are expanded in RUN lines. +// DEFINE: %{optimize} = opt -passes=mem2reg \ +// DEFINE: -S +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -disable-O0-optnone -emit-llvm %s -o - | %{optimize} | FileCheck %s --check-prefix=MEM2REG +// REDEFINE: %{optimize} = opt -passes=mem2reg,instcombine -S +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -disable-O0-optnone -emit-llvm %s -o - | %{optimize} | FileCheck %s --check-prefix=INSTCOMBINE +// DEFINE: %{pass1} = mem2reg +// DEFINE: %{pass2} = instcombine +// DEFINE: %{optimize-nested} = opt -passes=%{pass1},%{pass2} -S +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -disable-O0-optnone -emit-llvm %s -o - | %{optimize-nested} | FileCheck %s --check-prefix=NESTED + +// MEM2REG-LABEL: @f( +// MEM2REG-NEXT: entry: +// MEM2REG-NEXT: [[ADD:%.*]] = add nsw i32 [[A:%.*]], 1 +// MEM2REG-NEXT: [[SUB:%.*]] = sub nsw i32 [[ADD]], 1 +// MEM2REG-NEXT: ret i32 [[SUB]] +// +// INSTCOMBINE-LABEL: @f( +// INSTCOMBINE-NEXT: entry: +// INSTCOMBINE-NEXT: ret i32 [[A:%.*]] +// +// NESTED-LABEL: @f( +// NESTED-NEXT: entry: +// NESTED-NEXT: ret i32 [[A:%.*]] +// +int f(int a) { return (a + 1) - 1; } diff --git a/clang/test/utils/update_cc_test_checks/define.test b/clang/test/utils/update_cc_test_checks/define.test new file mode 100644 index 0000000000000..99c1c839a1d3e --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/define.test @@ -0,0 +1,4 @@ +## Test that DEFINE and REDEFINE substitutions are expanded in RUN lines. + +# RUN: cp %S/Inputs/define.c %t.c && %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/define.c.expected %t.c diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py index 2afa6072e1d37..2d1af7e2a1197 100644 --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -578,6 +578,7 @@ def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False): ##### LLVM IR parser RUN_LINE_RE = re.compile(r"^\s*(?://|[;#])\s*RUN:\s*(.*)$") +DEFINE_LINE_RE = re.compile(r"^\s*(?://|[;#])\s*(?:RE)?DEFINE:\s*(.*)$") CHECK_PREFIX_RE = re.compile(r"--?check-prefix(?:es)?[= ](\S+)") PREFIX_RE = re.compile("^[a-zA-Z0-9_-]+$") CHECK_RE = re.compile( @@ -672,12 +673,32 @@ def debug(*args, **kwargs): def find_run_lines(test, lines): debug("Scanning for RUN lines in test file:", test) - raw_lines = [m.group(1) for m in [RUN_LINE_RE.match(l) for l in lines] if m] - run_lines = [raw_lines[0]] if len(raw_lines) > 0 else [] - for l in raw_lines[1:]: - if run_lines[-1].endswith("\\"): - run_lines[-1] = run_lines[-1].rstrip("\\") + " " + l + # Collect run and (re)define lines. + directives = [] + for l in lines: + m = RUN_LINE_RE.match(l) or DEFINE_LINE_RE.match(l) + if not m: + continue + is_define = m.re is DEFINE_LINE_RE + if ( + directives + and directives[-1][0] == is_define + and directives[-1][1].endswith("\\") + ): + directives[-1][1] = directives[-1][1].rstrip("\\") + " " + m.group(1) + else: + directives.append([is_define, m.group(1)]) + + # Substitute into run lines. + substitutions = collections.OrderedDict() + run_lines = [] + for is_define, l in directives: + if is_define: + name, value = l.split("=", 1) + substitutions[name.strip()] = value.strip() else: + for name, value in reversed(substitutions.items()): + l = l.replace(name, value) run_lines.append(l) debug("Found {} RUN lines in {}:".format(len(run_lines), test)) for l in run_lines: _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
