This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix crashing getSValFromInitListExpr for nested initlists
ClosedPublic

Authored by steakhal on Mar 21 2023, 9:13 AM.

Details

Summary

In the following example, we will end up hitting the llvm_unreachable():
https://godbolt.org/z/5sccc95Ec

enum class E {};
const E glob[] = {{}};
void initlistWithinInitlist() {
  clang_analyzer_dump(glob[0]); // crashes at loading from `glob[0]`
}

We should just return std::nullopt instead for these cases. It's better than crashing.

Diff Detail

Event Timeline

steakhal created this revision.Mar 21 2023, 9:13 AM
Herald added a project: Restricted Project. · View Herald Transcript
steakhal requested review of this revision.Mar 21 2023, 9:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2023, 9:13 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I think this one also deserves backporting to clang-16.0.1 @xazax.hun

xazax.hun accepted this revision.Mar 21 2023, 9:18 AM

Ugh :/

I wonder if we should also open tickets on GitHub to reduce the chance of forgetting addressing the root cause for these. What do you think?

This revision is now accepted and ready to land.Mar 21 2023, 9:18 AM

Ugh :/

I wonder if we should also open tickets on GitHub to reduce the chance of forgetting addressing the root cause for these. What do you think?

Thanks for the quick review!

I think it would be valuable to track these FIXMEs as issues indeed. However, I don't have the time right now to file them.
Good tickets would require a bit more effort than I could invest now.

Speaking of issue tracking, I think it would be much more valuable to our users if we had a proper release notes section for CSA. Right now it is so ad-hoc.
That is also true for crash fixes and backports. Maybe we should put more emphasis on that part for the next major release.
I'm not sure how to enforce it though.

This has been backported to clang-16.0.1 as 1172ed57d8234990b277281b3084969fcdb38602