MSVC's cl.exe has a few command line arguments which start with -M such as "-MD", "-MDd", "-MT", "-MTd", "-MP".
These arguments are not dependency file generation related, and these arguments were being removed by getClangStripDependencyFileAdjuster() which was wrong.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Seems reasonable to me. Just some nits.
clang/lib/Tooling/ArgumentsAdjusters.cpp | ||
---|---|---|
29 | Instead of manually indexing into the StringRef, the I think the if-statement could be replaced by if (ArgRef.consume_front("--driver-mode=")) return ArgRef; | |
32 | I'd drop the Optional and just let the empty StringRef signal not finding the driver mode. | |
107 | If getDriverMode() didn't return Optional, this could be simplified to bool UsingClDriver = (getDriverMode() == "cl"); | |
110–111 | This line and the "All dependency-file options begin with -M" line above seem to contradict each other. Perhaps the could be united somehow. | |
112 | Instead of a bool and if below, I'd suggest if-statements and early continues instead. Breaking up the old if-statement is nice though, and maybe the comment from above about what flags to ignore could be moved down here to those if statements. For example: // -M flags blah blah if (Arg.startswith("-M") && !UsingClDriver) continue; // MSVC flags blah blah if (Arg.startswith("/showIncludes") || Arg.startswith("-showIncludes")) continue; AdjustedArgs.push_back(Args[i]); | |
126–127 | Need to handle -MT too I suppose |
- Simplified the implementation of getDriverMode and got rid of the Optional return type.
- When using the cl driver mode, we do not want to skip the next argument for -MF, -MT, -MQ.
clang/lib/Tooling/ArgumentsAdjusters.cpp | ||
---|---|---|
112 | I realized that with my original change, we would skip the next argument under cl driver mode when -MT was used, which would be wrong. The next argument should only be skipped when IsDependencyFileArg is true. So I think it might be cleaner to keep that extra boolean so the code is easy to read and understand. What do you think? |
clang/lib/Tooling/ArgumentsAdjusters.cpp | ||
---|---|---|
112 | I think having the boolean variable is still more confusing (it adds more state to keep track of) than just handling the cases with if-statements and early continue. How about: // -M flags that take an arg.. if (!UsingClDriver && (Arg == "-MF" || Arg == "-MT" || Arg == "-MQ")) { ++i; continue; } // -M flags blah blah if (!UsingClDriver && Arg.startswith("-M")) continue; // MSVC flags blah blah if (Arg.startswith("/showIncludes") || Arg.startswith("-showIncludes")) continue; AdjustedArgs.push_back(Args[i]); ? |
- Remove the bool IsDependencyFileArg in the implementation of getClangStripDependencyFileAdjuster() to make it simpler.
- Add an extra argument after -MT in the test case to ensure we do not strip arguments after -MT when using the cl driver mode.
clang/lib/Tooling/ArgumentsAdjusters.cpp | ||
---|---|---|
112 | Yup I agree that looks better :) |
Note that I do not have commit access and this change will have to be committed by someone else on my behalf. Thanks!
Instead of manually indexing into the StringRef, the I think the if-statement could be replaced by