llvm / llvm/llvm-project

[clang-cl] Dependency file tracking is handled incorrectly in clang-cl over clang

Open
#189,195 0 comments 0 reactions 0 assignees View on GitHub
clang-cl
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

When running the command
```
clang-cl -v /clang:-MD -g file.cpp -c -o out.o
```
clang-cl will generate a file called `file.d` in the same directory. With regular clang,
```
clang++ -v -MD -g file.cpp -c -o out.o
```
will generate a file called `out.d` in the same directory, which is expected behaviour. According to GCC's explanation about `-MD`,

"-MD is equivalent to -M -MF file, except that -E is not implied. The driver determines file based on whether an -o option is given. If it is, the driver uses its argument but with a suffix of .d, otherwise it takes the name of the input file, removes any directory components and suffix, and applies a .d suffix."

Which means that clang-cl is naming the dependency file incorrectly, since -o has been specified and works for regular clang. It also ends up placing the file in the directory clang was called from, which means that on a large project this directory will fill up with invalid debug files.
Tested with LLVM version `22.1.2 (https://github.com/llvm/llvm-project 1ab49a973e210e97d61e5db6557180dcb92c3e98)`.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the clang-cl and clang commands shown in the issue, comparing the dependency-file paths and names produced with -MD and -o. Trace the clang-cl driver entry point for dependency-file handling and add or update coverage for this invocation; done means the output follows the -o-based naming behavior described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.