This is an archive of the discontinued LLVM Phabricator instance.

[clang-cl] Implement /ZH: flag
ClosedPublic

Authored by thakis on Sep 23 2022, 8:27 AM.

Details

Summary

Based on a patch by Arlo Siemsen (D98438)!

Diff Detail

Event Timeline

thakis created this revision.Sep 23 2022, 8:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 23 2022, 8:27 AM
thakis requested review of this revision.Sep 23 2022, 8:27 AM
probinson added a subscriber: probinson.

Probably we should reject the -gsrc... option if we're emitting DWARF, which requires MD5 (at least so far).

Probably we should reject the -gsrc... option if we're emitting DWARF, which requires MD5 (at least so far).

It's a cc1 option. As those aren't considered user facing, we don't do a lot of checking for them usually.

hans added a comment.Sep 23 2022, 11:55 AM

nice!

clang/include/clang/Basic/CodeGenOptions.def
344

ultra nit: period. But maybe the comment is superfluous?

clang/include/clang/Basic/CodeGenOptions.h
106

what does CSK stand for here?

thakis added inline comments.Sep 23 2022, 1:42 PM
clang/include/clang/Basic/CodeGenOptions.def
344

Seems superfluous to me too, but this file is very consistent about having superfluous comments for every option. I'll add the trailing period.

clang/include/clang/Basic/CodeGenOptions.h
106

I'm guessing "check sum kind", but I don't know :)

SHA_ looks a bit funny as prefix too...

I also don't love the cc1 flag name, but I figured it's a bit bikesheddy and it's internal only so i kept it as is.

If you have a preference for flag name, enum name, and enum prefix, let me know.

probinson added inline comments.Sep 23 2022, 1:50 PM
clang/test/CodeGen/debug-info-file-checksum.c
4

I thought -gsrc... was not a driver option, but here it is being passed to the driver?

thakis added inline comments.Sep 23 2022, 2:56 PM
clang/test/CodeGen/debug-info-file-checksum.c
4

Good catch, thanks. https://reviews.llvm.org/D134544#inline-1297003 does mark it as CC1Option. It's definitely meant to be a driver option, let me look into why this works here. It shouldn't.

thakis added inline comments.Sep 23 2022, 3:00 PM
clang/test/CodeGen/debug-info-file-checksum.c
4

Aha, I want NoDriverOption too. Update coming in a bit…

thakis updated this revision to Diff 462596.Sep 23 2022, 3:01 PM

don't accidentally add a flag for this to the gcc-style driver

hans accepted this revision.Sep 23 2022, 10:35 PM

lgtm

clang/include/clang/Basic/CodeGenOptions.h
106

How about

enum DebugSrcHashKind { DSH_MD5, ...

("kind" seems a common suffix for these, "debug" is a nice hint about what area this applies to.)

clang/lib/CodeGen/CGDebugInfo.cpp
377

Perhaps it would be simpler to drop the CSKind variable and fold the return into the individual cases?

This revision is now accepted and ready to land.Sep 23 2022, 10:35 PM
thakis updated this revision to Diff 462731.Sep 25 2022, 8:04 AM

final tweaks

clang/include/clang/Basic/CodeGenOptions.h
106

DebugSourceHash it is.

clang/lib/CodeGen/CGDebugInfo.cpp
377

Oh, that's much nicer, thanks.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 25 2022, 11:43 AM
dblaikie added inline comments.
clang/include/clang/Driver/Options.td
3220

This is a driver flag, yeah? Might be worth documenting/emitting a warning that it's not compatible with DWARF emission? (looks like the DWARF code in LLVM ignores any hash that's not MD5, because DWARF doesn't have a way to encode other hash algorithms currently - though maybe there's some extension space available to add it, I haven't checked/looked)

thakis added inline comments.Jul 8 2023, 10:22 AM
clang/include/clang/Driver/Options.td
3220

belated: this is Flags<[CC1Option, NoDriverOption]>, in the line below, so I think this isn't a driver flag. (It's what the CLFlags added below expand to – those are driver flags, but only for clang-cl.)

dblaikie added inline comments.Jul 19 2023, 11:29 AM
clang/include/clang/Driver/Options.td
3220

Oh, I see - I think I was confused by the driver code referencing gsrc_hash_EQ - but that's because the /ZH are implemented as aliases for gsrc_hash_EQ.

I guess then maybe my comment applies to /ZH - if someone asks for DWARF and uses that flag? But maybe not worth it...