This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Make /Zi and /Z7 aliases of -g rather than handling them specially
ClosedPublic

Authored by bogner on Aug 12 2023, 11:54 AM.

Details

Summary

The -g flag has been selecting whether to emit dwarf or codeview based
on the target ABI since 2018, so simply aliasing these flags does the
right thing for clang-cl.

This moves some code from Clang::ConstructJob to renderDebugOptions to
make things a little clearer now that we don't need to keep track of
whether we're doing codeview or not in multiple places, and also
combines the duplicate handling of the cl vs clang handling of jmc
flags as a result.

This is mostly NFC, but some -cc1 flags may be rendered in a slightly
different order because of the code that was moved around.

Diff Detail

Event Timeline

bogner created this revision.Aug 12 2023, 11:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2023, 11:54 AM
bogner requested review of this revision.Aug 12 2023, 11:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2023, 11:54 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rnk added a subscriber: smeenai.Aug 12 2023, 5:07 PM
rnk added inline comments.
clang/test/Driver/cl-options.c
567

I think Meta folks depend on a mode that emits both codeview and DWARF. +@smeenai

bogner added inline comments.Aug 13 2023, 3:05 AM
clang/test/Driver/cl-options.c
567

Hopefully if that's the case there's a better test somewhere than this one that discusses in detail how /Z7 is an alias for -gline-tables-only, which hasn't been true since 2017.

smeenai added inline comments.Aug 14 2023, 9:59 AM
clang/test/Driver/cl-options.c
567

Thanks for the headers up :) We don't depend on that mode any more though, so no problems on our end.

bogner added inline comments.Aug 14 2023, 10:27 AM
clang/test/Driver/cl-options.c
567

Also note that this change does not affect what happens if we specify both -gcodeview and -gdwarf together. That continues to pass both -gcodeview and -dwarf-version=... to clang -cc1. However, I don't see any tests that actually check that behaviour, so if that is a mode that's useful to keep working we definitely have some gaps there.

This change means that if you want to ask -cc1 for dwarf *and* codeview with /Z7 or /Zi, you'll need to specify -gdwarf and -gcodeview now. This matches how you would get both sets of options to render with -g, which I think makes sense.

smeenai added inline comments.
clang/test/Driver/cl-options.c
567

Yeah, that sounds good. IIRC when we were using the joint codeview + DWARF mode it was with the gcc-style Clang driver and not clang-cl, and we passed -gdwarf -gcodeview or similar to enable it anyway. We don't need that anymore though; @mstorsjo would know if there's anything on the MinGW side that cares for it.

rnk accepted this revision.Aug 14 2023, 11:13 AM

So, as I understand the discussion, after this patch, it will still be possible to get dwarf and codeview in the same compile, but users will have to resort to cc1 flags.

I think that's a good end state. I would like to retain the ability to generate both, but the driver should make it very hard to enable this mode. Burying it in cc1 flags seems like a good end state. Comments about lack of testing are valid.

This revision is now accepted and ready to land.Aug 14 2023, 11:13 AM
MaskRay accepted this revision.Aug 14 2023, 11:19 AM
MaskRay added inline comments.
clang/lib/Driver/ToolChains/Clang.cpp
4522

Keep just one blank line.

mstorsjo added inline comments.Aug 14 2023, 12:22 PM
clang/test/Driver/cl-options.c
567

I'm not aware of mingw usecases of using both codeview and DWARF at the same time - I've occasionally mentioned that I know some people do use that, but I haven't actually guided anybody into doing it.

For mingw, as long as -g -gcodeview on the driver level generates codeview (and not DWARF) like it used to, mingw should be fine.

This revision was landed with ongoing or failed builds.Aug 14 2023, 12:28 PM
This revision was automatically updated to reflect the committed changes.
bogner marked 3 inline comments as done.Aug 14 2023, 12:29 PM