https://github.com/matteo-rm created https://github.com/llvm/llvm-project/pull/237636
On Windows, `update_cc_test_checks` fails to update tests that pipe outputs since opening an already open `NamedTemporaryFile` errors when it's set to automatically delete. This PR fixes this by manually removing the file. From 8aa0d27b3efa3c3b246af58696e97fa50494ea60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Rizza=20Murgier?= <[email protected]> Date: Sat, 31 Oct 2026 22:31:52 +0100 Subject: [PATCH] [UpdateTestChecks] Fix Windows crash when piping outputs --- .../utils/update_cc_test_checks/Inputs/opt-pipeline.c | 3 +++ .../update_cc_test_checks/Inputs/opt-pipeline.c.expected | 8 ++++++++ clang/test/utils/update_cc_test_checks/opt-pipeline.test | 4 ++++ llvm/utils/update_cc_test_checks.py | 6 ++++-- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c create mode 100644 clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c.expected create mode 100644 clang/test/utils/update_cc_test_checks/opt-pipeline.test diff --git a/clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c b/clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c new file mode 100644 index 00000000000000..97652fc38a3028 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | opt -S | FileCheck %s + +void f(void) {} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c.expected b/clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c.expected new file mode 100644 index 00000000000000..f56a45206dedd6 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c.expected @@ -0,0 +1,8 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | opt -S | FileCheck %s + +// CHECK-LABEL: @f( +// CHECK-NEXT: entry: +// CHECK-NEXT: ret void +// +void f(void) {} diff --git a/clang/test/utils/update_cc_test_checks/opt-pipeline.test b/clang/test/utils/update_cc_test_checks/opt-pipeline.test new file mode 100644 index 00000000000000..328142e2ab1a99 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/opt-pipeline.test @@ -0,0 +1,4 @@ +## Test that the output of clang can be piped through opt. + +# RUN: cp %S/Inputs/opt-pipeline.c %t.c && %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/opt-pipeline.c.expected %t.c diff --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py index 97b446d5659734..cabdda9d5c0536 100755 --- a/llvm/utils/update_cc_test_checks.py +++ b/llvm/utils/update_cc_test_checks.py @@ -265,9 +265,9 @@ def get_function_body( # TODO Clean up duplication of asm/common build_function_body_dictionary for extra_command in extra_commands: extra_args = shlex.split(extra_command) - with tempfile.NamedTemporaryFile() as f: + with tempfile.NamedTemporaryFile(delete=False) as f: f.write(raw_tool_output.encode()) - f.flush() + try: if extra_args[0] == "opt": if args.opt is None: print( @@ -278,6 +278,8 @@ def get_function_body( sys.exit(1) extra_args[0] = args.opt raw_tool_output = common.invoke_tool(extra_args[0], extra_args[1:], f.name) + finally: + os.remove(f.name) if "-emit-llvm" in clang_args: builder.process_run_line( common.OPT_FUNCTION_RE, common.scrub_body, raw_tool_output, prefixes _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
