This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][NFC] Fix dangling StringRef in barely used code
ClosedPublic

Authored by donat.nagy on Jun 27 2023, 9:23 AM.

Details

Summary

CheckerContext::getNoteTag has a shorthand version that takes a plain 'StringRef Note' instead of a lambda that calculates the note.

The old implementation of this method was incorrect because it created a lambda that captured the StringRef, which was dereferenced much later, when the NoteTags were visited.

In the current codebase this does not cause errors because this method is called only once, and there the Note argument is a string literal that remains valid. However, I tried to use this method in a checker that I was prototyping, and there it printed random memory junk (instead of the message that I composed in a local variable).

Diff Detail

Event Timeline

donat.nagy created this revision.Jun 27 2023, 9:23 AM
Herald added a project: Restricted Project. · View Herald Transcript
donat.nagy requested review of this revision.Jun 27 2023, 9:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2023, 9:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
xazax.hun accepted this revision.Jun 27 2023, 10:36 AM
This revision is now accepted and ready to land.Jun 27 2023, 10:36 AM
steakhal accepted this revision.Jun 27 2023, 3:18 PM

This is actually needed to get correct bug reports in D153612, otherwise I got garbage messages (probably a std::string stack variable was passed to the getNoteTag function). I would not say that this is NFC because it is a bugfix.

This revision was landed with ongoing or failed builds.Jun 30 2023, 8:18 AM
This revision was automatically updated to reflect the committed changes.