Incorrect escaping in compiler parameter files for Visual C++
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
See https://groups.google.com/g/bazel-discuss/c/xQMWQcgnP30. Bazel doesn't correctly escape special characters in compiler parameter files.
### Which category does this issue belong to?
_No response_
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
BUILD.bazel:
```python
cc_binary(
name = "main",
srcs = ["main.cc"],
# Additional quoting due to
# https://github.com/bazelbuild/bazel/issues/10859.
local_defines = ["""'GREETING="Hello world!"'"""],
)
```
main.cc:
```c++
#include
int main() {
std::cout << GREETING << std::endl;
}
```
`bazel run :main` then works as expected on e.g. macOS, and on Windows with `--features=-compiler_param_file`. With param files enabled, compiling fails on Windows:
```
ERROR: C:/users/p/compilerparam/BUILD.bazel:1:10: Compiling main.cc failed: (Exit 2): cl.exe failed: error executing CppCompile command (from target //:main) C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe @bazel-out/x64_windows-fastbuild/bin/_objs/main/main.obj.params
cl : Command line warning D9024 : unrecognized source file type 'world!"', object file assumed
cl : Command line warning D9027 : source file 'world!"' ignored
main.cc(3): warning C4129: ' ': unrecognized character escape sequence
main.cc(3): error C2001: newline in constant
main.cc(4): error C2143: syntax error: missing ';' before '}'
Target //:main failed to build
```
### Which operating system are you running Bazel on?
Microsoft Windows [Version 10.0.17763.2803]
### What is the output of `bazel info release`?
release 7.0.1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
N/A
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
N/A
```
### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
Probably not
### Have you found anything relevant by searching the web?
- https://groups.google.com/g/bazel-discuss/c/xQMWQcgnP30
- Internal Google issue b/132888308
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Reproduce the example from BUILD.bazel and main.cc on Windows, comparing compiler parameter files with --features=-compiler_param_file. Start by tracing how the local_defines value is written to the generated main.obj.params file and passed to cl.exe. Done means the example compiles and runs with parameter files enabled without the reported escaping errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100