Currently when assertions are enabled, the cc1 flag is not
inserted into the llvmcmd section of object files with embedded
bitcode. This deviates from the normal behavior where this is
the first flag that is inserted. This error stems from incorrect
use of the function generateCC1CommandLine() which requires
manually adding in the -cc1 flag which is currently not done.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for the fix! Left one suggestion.
clang/lib/Frontend/CompilerInvocation.cpp | ||
---|---|---|
4549 | This will shift all generated arguments in the vector. Could you do something like this instead? Args.push_back("-cc1"); Invocation.generateCC1CommandLine(Args, SA); I think generateCC1CommandLine() appends to Args, so this should be safe to do. |
clang/lib/Frontend/CompilerInvocation.cpp | ||
---|---|---|
4549 | Fixed. Thanks for the suggestion. Just tested it and everything looks good. For some reason when I was working on it this morning I didn't think it would be that easy. |
Added two unit tests to ensure functionality is correct in both
the assertion case and the default case. Should be sufficient
to ensure correct functionality without utilizing regression tests.
However, if regression tests are also desired, let me know and I can
add one in.
Thanks for adding the tests. They are failing in CI though, and I don't think they're entirely correct.
My understanding is that the goal is to make sure Clang doesn't drop the -cc1 flag when embedding command-lines into object files.
During normal compilation, the arguments given by the driver to CompilerInvocation::CreateFromArgs() already begin with -cc1, so I suggest setting up the tests to do so as well. We could use {"-cc1", "-round-trip-args"} in the first test case and {"-cc1", "-no-round-trip-args"} in the second.
We probably want to verify that the CompilerInvocation member used to store the command-line looks correctly. My guess is that the bitcode is using CodeGenOptions::CommandLineArgs, so I suggest checking that instead of GeneratedArgs in the final assertion.
(I feel like GeneratedArgs are an implementation detail in this particular test case. Moreover, the vector will be empty in the current revision, since you don't call Invocation.generateCC1CommandLine(GeneratedArgs, *this) like the surrounding test cases do.)
Rebased against main and adjusted unit tests to check directly
for the cc1 flag in CmdArgs which is directly consumed by the
bitcode writer while creating the .llvmcmd section. Also changed
the flags to better match what is already getting passed in.
Thanks for the review and your suggestions. Do you mind pushing this commit? I don't currently have commit access to LLVM. Thanks.
This will shift all generated arguments in the vector. Could you do something like this instead?
I think generateCC1CommandLine() appends to Args, so this should be safe to do.