vitalybuka wrote:
Sorry, I am changing direction from my earlier comments. I now think the
sanitizer directory should be handled exactly like debug and coverage. The
table at the end shows the difference today and the target.
Let's start with extracting a helper in a separate NFC PR:
```c++
/// Add a CC1 option to specify a compilation directory.
static const char *addCompDirArg(const ArgList &Args, ArgStringList &CmdArgs,
const llvm::vfs::FileSystem &VFS,
llvm::opt::OptSpecifier Opt,
StringRef CC1Flag) {
std::string CompDir;
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ, Opt))
CompDir = A->getValue();
if (CompDir.empty()) {
if (llvm::ErrorOr<std::string> CWD = VFS.getCurrentWorkingDirectory())
CompDir = std::move(*CWD);
else
return nullptr;
}
CmdArgs.push_back(Args.MakeArgString(Twine(CC1Flag) + CompDir));
StringRef Path(CmdArgs.back());
return Path.substr(Path.find('=') + 1).data();
}
```
And use it like:
```c++
addCompDirArg(Args, CmdArgs, VFS, options::OPT_fdebug_compilation_dir_EQ,
"-fdebug-compilation-dir=");
addCompDirArg(Args, CmdArgs, VFS, options::OPT_fcoverage_compilation_dir_EQ,
"-fcoverage-compilation-dir=");
// In #201803.
// addCompDirArg(Args, CmdArgs, VFS, options::OPT_fsanitize_compilation_dir_EQ,
// "-fsanitize-compilation-dir=");
```
Then in this PR:
- Add `-fsanitize-compilation-dir=` back as a driver flag, and forward the
value unchanged. No `make_absolute` or `remove_dots` in the driver.
- The helper passes the working directory when no flag is set, the same as
debug and coverage. So sanitizer paths under the working directory become
relative by default.
- Remove the ASan and UBSan changes and their docs from here. Keep the driver
change and the driver tests.
ASan, UBSan, HWASan and DFSan can each follow in their own PR. My two
`remove_dots` suggestions above apply to those follow-ups. The release note can
land with them, or once all are done.
| | Debug (HEAD) | Coverage (HEAD) | Sanitizer (PR as-is) | Sanitizer (target) |
| --- | --- | --- | --- | --- |
| Driver flags | `-fdebug-compilation-dir=`, `-ffile-compilation-dir=` |
`-fcoverage-compilation-dir=`, `-ffile-compilation-dir=` |
`-ffile-compilation-dir=` | `-fsanitize-compilation-dir=`,
`-ffile-compilation-dir=` |
| Flag forms | `=` and space-separated (legacy alias) | `=` only | `=` only |
`=` only |
| cc1 flag | `-fdebug-compilation-dir=` | `-fcoverage-compilation-dir=` |
`-fsanitize-compilation-dir=` | `-fsanitize-compilation-dir=` |
| Driver code | helper `addDebugCompDirArg` (`Clang.cpp:235`) | inline in
`addPGOAndCoverageFlags` (`Clang.cpp:571-581`) | inline in
`Clang::ConstructJob` (`Clang.cpp:8383-8391`) | shared helper with debug and
coverage |
| Emitted when feature is off | yes | yes (not on NVPTX) | yes, if
`-ffile-compilation-dir=` is set | yes |
| cc1 value, flag unset | `<CWD>` | `<CWD>` | not emitted | `<CWD>` |
| cc1 value, `-ffile-compilation-dir=.` | `.` | `.` | `<abs CWD>` | `.` |
| cc1 value, `-ffile-compilation-dir=/foo/bar/..` | `/foo/bar/..` |
`/foo/bar/..` | `/foo` | `/foo/bar/..` |
| cc1 processing | debug prefix map (`remapDIPath`), then embeds as
`DW_AT_comp_dir` | `remove_dots`, coverage prefix map (`normalizeFilename`),
then embeds as `FilenameStrs[0]` in `__llvm_covmap` | strips the value as a
prefix from absolute paths (ASan module name, UBSan locations) | resolves a
relative value against the cc1 working directory, then strips as in PR as-is |
| ScanDeps / `visitMutPaths` | cleared / visited | cleared / visited | cleared
/ visited | cleared / visited |
https://github.com/llvm/llvm-project/pull/201803
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits