[clang] [llvm] [UpdateTestChecks] Fix Windows crash when piping outputs (PR #237636)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 31 14:45:17 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-testing-tools
Author: Mattéo Rizza Murgier (matteo-rm)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/237636.diff
4 Files Affected:
- (added) clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c (+3)
- (added) clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c.expected (+8)
- (added) clang/test/utils/update_cc_test_checks/opt-pipeline.test (+4)
- (modified) llvm/utils/update_cc_test_checks.py (+4-2)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/237636
More information about the cfe-commits
mailing list