Author: Mattéo Rizza Murgier
Date: 2026-11-01T09:42:00+01:00
New Revision: 281f3236354095c2e3494709ec65879ebb7333a6

URL: 
https://github.com/llvm/llvm-project/commit/281f3236354095c2e3494709ec65879ebb7333a6
DIFF: 
https://github.com/llvm/llvm-project/commit/281f3236354095c2e3494709ec65879ebb7333a6.diff

LOG: [UpdateTestChecks] Fix Windows error when piping outputs (#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 closing the file
after initially writing to it and then manually removing it.

Added: 
    clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c
    clang/test/utils/update_cc_test_checks/Inputs/opt-pipeline.c.expected
    clang/test/utils/update_cc_test_checks/opt-pipeline.test

Modified: 
    llvm/utils/update_cc_test_checks.py

Removed: 
    


################################################################################
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

Reply via email to