This is an archive of the discontinued LLVM Phabricator instance.

SymbolFile: ensure that we have a value before invoking `getBitWidth`
ClosedPublic

Authored by compnerd on Mar 21 2023, 9:08 AM.

Details

Summary

Ensure that the variant returned by member->getValue() has a value and
is not Empty. Failure to do so will trigger an assertion failure in
llvm::pdb::Variant::getBitWidth(). This can occur when the static
member is a forward declaration.

Diff Detail

Event Timeline

compnerd created this revision.Mar 21 2023, 9:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2023, 9:08 AM
compnerd requested review of this revision.Mar 21 2023, 9:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2023, 9:08 AM

Thanks for tackling this! Yes, I hit it as well during development and wondered what is the right thing to do. The effect of the proposed change will be log messages like this right?

... which resolves to a constant value of mismatched width (-1 bits). Ignoring constant.

I think it would be great to log the actual issue (constant width not accessible) and bail out if value.Type == llvm::pdb::Empty. Even before requesting qual_type. What do you think?

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
1307

Is the -1 intended to express an invalid value? Maybe this should become a signed int then?

Thanks for tackling this! Yes, I hit it as well during development and wondered what is the right thing to do. The effect of the proposed change will be log messages like this right?

... which resolves to a constant value of mismatched width (-1 bits). Ignoring constant.

No, it should be something like 4294967295 bits. Assuming that you have that log enabled.

I think it would be great to log the actual issue (constant width not accessible) and bail out if value.Type == llvm::pdb::Empty. Even before requesting qual_type. What do you think?

Sure, I can test that and see if there are any adverse effects from that.

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
1307

Yeah, by means of it being impossibly large. I suppose I could do an explicit cast (i.e. static_cast<unsigned>(-1) to make this clearer.

compnerd updated this revision to Diff 507330.Mar 22 2023, 6:01 AM

Address feedback

sgraenitz accepted this revision.Mar 22 2023, 6:23 AM

Perfect, thanks!

This revision is now accepted and ready to land.Mar 22 2023, 6:23 AM