[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #96457)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 24 00:03:54 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Karl-Johan Karlsson (karka228)

<details>
<summary>Changes</summary>

The test clang/test/Preprocessor/embed_weird.cpp create a file directly in the Inputs dir in the llvm-project repo instead of the temporary directory. The llvm-project repo may be write protected e.g. in a sandboxed environment.

This patch create a separate temporary directory where the the null_byte.bin file is created along with the rest of copies of the other embed-files needed for the testcase.

---
Full diff: https://github.com/llvm/llvm-project/pull/96457.diff


1 Files Affected:

- (modified) clang/test/Preprocessor/embed_weird.cpp (+6-4) 


``````````diff
diff --git a/clang/test/Preprocessor/embed_weird.cpp b/clang/test/Preprocessor/embed_weird.cpp
index a90d3bc330538..31b622c848d6a 100644
--- a/clang/test/Preprocessor/embed_weird.cpp
+++ b/clang/test/Preprocessor/embed_weird.cpp
@@ -1,7 +1,9 @@
-// RUN: printf "\0" > %S/Inputs/null_byte.bin
-// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%S/Inputs -verify=expected,cxx -Wno-c23-extensions
-// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%S/Inputs -verify=expected,c
-// RUN: rm %S/Inputs/null_byte.bin
+// RUN: rm -rf %t && mkdir -p %t/media
+// RUN: cp %S/Inputs/single_byte.txt %S/Inputs/jk.txt %S/Inputs/numbers.txt %t/
+// RUN: cp %S/Inputs/media/empty %t/media/
+// RUN: printf "\0" > %t/null_byte.bin
+// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%t -verify=expected,cxx -Wno-c23-extensions
+// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%t -verify=expected,c
 #embed <media/empty>
 ;
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/96457


More information about the cfe-commits mailing list