This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Fix uninitalized member variable use in ASTReader::ParseTargetOptions()
ClosedPublic

Authored by schittir on Mar 21 2023, 9:03 PM.

Details

Summary

Found by Coverity static analysis tool.

Diff Detail

Event Timeline

schittir created this revision.Mar 21 2023, 9:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2023, 9:03 PM
schittir requested review of this revision.Mar 21 2023, 9:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2023, 9:03 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tahonermann added inline comments.Mar 22 2023, 7:32 AM
clang/lib/Serialization/ASTReader.cpp
5890–5892 ↗(On Diff #507221)

It is odd that these values aren't preserved by the AST writer. I wonder if that is intentional.

It took me a while, but I eventually found that these data members are assigned via an inclusion of clang/Driver/Options.inc somewhere.

Rather than assigning values here, I think we would be better off adding member initializers in the class definition. But I think we do need to look into why the AST writer isn't preserving the values.

schittir updated this revision to Diff 507425.Mar 22 2023, 10:33 AM
tahonermann added inline comments.Mar 22 2023, 12:22 PM
clang/include/clang/Basic/TargetOptions.h
48

Looks good; this is consistent with the default initialization performed for llvm::TargetOptions::EABIVersion.

91

I see that COV_4 is the default as specified in clang/include/clang/Driver/Options.td, but I wonder if we want to duplicate that value here. I'm a bit more inclined to default to COV_None so that we're not trying to maintain the same default in multiple places. I don't know that it matters though.

Perhaps it would make sense to add a "default" option value as is done for EABI? I'm not sure.

schittir updated this revision to Diff 507964.Mar 23 2023, 11:16 PM

Changed CodeObjectVersion default to COV_None

schittir marked an inline comment as done.Mar 23 2023, 11:17 PM
aaron.ballman added inline comments.Mar 27 2023, 8:33 AM
clang/include/clang/Basic/TargetOptions.h
91

I think none makes the most sense to me. This is set via a CC1 option, and the driver doesn't unconditionally set it (https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/Clang.cpp#L1073), so I think none is safer than assuming CodeObjectVersion is meaningful when it's not set by -cc1. WDYT?

schittir added inline comments.Mar 28 2023, 10:49 AM
clang/include/clang/Basic/TargetOptions.h
91

I agree, and that's why I made the change to none. @tahonermann

tahonermann accepted this revision.Mar 29 2023, 9:13 AM

Changes look good to me. Thanks, Sindhu!

This revision is now accepted and ready to land.Mar 29 2023, 9:13 AM
schittir closed this revision.Jul 12 2023, 11:06 AM