Page MenuHomePhabricator

[clang][analyzer] Add errno modeling to StreamChecker
AcceptedPublic

Authored by balazske on Aug 17 2022, 2:30 AM.

Details

Summary

Update the existing modeling of stream functions in StreamChecker
with 'errno' modeling. The not (yet) evaluated stream functions
are not updated.

Diff Detail

Event Timeline

balazske created this revision.Aug 17 2022, 2:30 AM
Herald added a reviewer: NoQ. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
balazske requested review of this revision.Aug 17 2022, 2:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2022, 2:30 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
steakhal added inline comments.Aug 17 2022, 2:58 AM
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
283–284

Have you considered using llvm::Optional<int> for this?

537

I believe, getDecl() might return null, e.g. for calling a function pointer.

clang/test/Analysis/stream-errno.c
13–14

So these two lines correspond to the following clang_analyzer_eval().
It took me a while to make sense of the two independent note streams at once.
Please consider splitting this and similar cases to have a single stream of notes.

balazske updated this revision to Diff 453297.Aug 17 2022, 8:46 AM

StdLibraryFunctionsChecker should not overwrite errno constraints
that are set by StreamChecker.

balazske updated this revision to Diff 454026.Aug 19 2022, 8:49 AM
balazske marked 2 inline comments as done.
  • Use Optional for EofInitialized
  • Split tests into two files with and without note check.
balazske added inline comments.
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
537

In this case the function should be known (we know that fopen is the called function, if the name is known the Decl should be known too), I think it can not be null here.

martong accepted this revision.Sep 28 2022, 12:31 AM

LGTM, thanks!

clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
465

Makes sense.

This revision is now accepted and ready to land.Sep 28 2022, 12:31 AM