Skip to content

Commit 0f4c6b1

Browse files
committed
[lvm-windres] Try to match GNU windres regarding handling of unescaped quotes
Some background context: GNU windres invokes the preprocessor in a subprocess. Some windres options are passed through to the preproocessor, e.g. -D options for predefining defines. When GNU windres passes these options onwards, it takes the options in exact the form they are received (in argv or similar) and assembles them into a single preprocessor command string which gets interpreted by a shell (IIRC via the popen() function, or similar). When LLVM invokes subprocesses, it does so via APIs that take properly split argument vectors, to avoid needing to worry about shell quoting/escaping/unescaping. But in the case of LLVM windres, we have to emulate the effect of the shell parsing done by popen(). Most of the relevant cases are already taken care of here, but this patch fixes an uncommon case encountered in #57334. (This case is uncommon since it doesn't do what one would want to; the quotes need to be escaped more to work as intended through the popen() shell). Differential Revision: https://reviews.llvm.org/D146848
1 parent dc41f38 commit 0f4c6b1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Diff for: llvm/test/tools/llvm-rc/windres-preproc.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llvm-windres -### --include-dir %p/incdir1 --include %p/incdir2 "-DFOO1=\\\"foo bar\\\"" -UFOO2 -D FOO3 --preprocessor-arg "-DFOO4=\\\"baz baz\\\"" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK1
2-
; CHECK1: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-{{.*}}{{mingw32|windows-gnu}}" "-E" "-xc" "-DRC_INVOKED" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc" "-I" "{{.*}}incdir1" "-I" "{{.*}}incdir2" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3" "-DFOO4=\"baz baz\""{{$}}
1+
; RUN: llvm-windres -### --include-dir %p/incdir1 --include %p/incdir2 "-DFOO1=\\\"foo bar\\\"" -UFOO2 -D FOO3 --preprocessor-arg "-DFOO4=\\\"baz baz\\\"" -DFOO5=\"bar\" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK1
2+
; CHECK1: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-{{.*}}{{mingw32|windows-gnu}}" "-E" "-xc" "-DRC_INVOKED" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc" "-I" "{{.*}}incdir1" "-I" "{{.*}}incdir2" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3" "-DFOO4=\"baz baz\"" "-D" "FOO5=bar"{{$}}
33
; RUN: llvm-windres -### --preprocessor "i686-w64-mingw32-gcc -E -DFOO=\\\"foo\\ bar\\\"" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK2
44
; CHECK2: {{^}} "i686-w64-mingw32-gcc" "-E" "-DFOO=\"foo bar\"" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}}

Diff for: llvm/tools/llvm-rc/llvm-rc.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ std::string unescape(StringRef S) {
322322
else
323323
fatalError("Unterminated escape");
324324
continue;
325+
} else if (S[I] == '"') {
326+
// This eats an individual unescaped quote, like a shell would do.
327+
continue;
325328
}
326329
Out.push_back(S[I]);
327330
}

0 commit comments

Comments
 (0)