Skip to content

Commit bf9af9f

Browse files
authored
[libclang][reproducers] Escape command-line arguments in a generated script. (#11498)
1 parent 113b8b0 commit bf9af9f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

clang/test/Modules/reproducer-with-module-dependencies.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
// Test the content of a reproducer script.
1717
// RUN: c-index-test core -gen-deps-reproducer -working-dir %t -o %t/repro-content \
1818
// RUN: -- clang-executable -c %t/reproducer.c -o %t/reproducer.o \
19-
// RUN: -fmodules -fmodules-cache-path=%t
19+
// RUN: -fmodules -fmodules-cache-path=%t \
20+
// RUN: -DMACRO="\$foo"
2021
// RUN: FileCheck %t/script-expectations.txt --input-file %t/repro-content/reproducer.sh
2122

2223
//--- modular-header.h
@@ -40,3 +41,4 @@ void test(void) {
4041
//--- script-expectations.txt
4142
CHECK: CLANG:-clang-executable
4243
CHECK: -fmodule-file=Test=reproducer.cache/explicitly-built-modules/Test-{{.*}}.pcm
44+
CHECK: MACRO=\$foo

clang/tools/libclang/CDependencies.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,10 @@ enum CXErrorCode clang_experimental_DependencyScanner_generateReproducer(
845845
&FileCacheName](llvm::raw_fd_ostream &OS,
846846
ArrayRef<std::string> Arguments) {
847847
OS << ReproExecutable;
848-
for (int I = 0, E = Arguments.size(); I < E; ++I)
849-
OS << ' ' << Arguments[I];
848+
for (int I = 0, E = Arguments.size(); I < E; ++I) {
849+
OS << ' ';
850+
llvm::sys::printArg(OS, Arguments[I], /*Quote=*/true);
851+
}
850852
OS << " -ivfsoverlay \"" << FileCacheName << "/vfs/vfs.yaml\"";
851853
OS << '\n';
852854
};

0 commit comments

Comments
 (0)