This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][StdLibraryFunctionsChecker] Add return value constraint to functions with BufferSize
ClosedPublic

Authored by martong on Dec 2 2020, 3:40 AM.

Diff Detail

Event Timeline

martong created this revision.Dec 2 2020, 3:40 AM
martong requested review of this revision.Dec 2 2020, 3:40 AM

I've double-checked the return values of each touched summary.
Everything seems fine to me, besides the two I've highlighted.

clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
1775
1788

Same here.

1863

Aaa, I get it. We deal with this in a single transition. Fine.

2068

BTW, this is quite frequently repeated.
Do you think worth hoisting such a return value constraint?

I'm thinking of something like ReturnsZeroOrMinusOne.

martong marked 3 inline comments as done.Dec 2 2020, 6:36 AM
martong added inline comments.
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
1775

The two constraints are applied in the same case (branch), the second is more generic. The first constraint may not have any effect if Arg2 is Unknown. Consequently, [-1, -1] would be too strict in such cases.

martong marked 2 inline comments as done.Dec 2 2020, 6:48 AM
martong added inline comments.
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
2068

Good idea!

martong updated this revision to Diff 308951.Dec 2 2020, 6:48 AM
martong marked an inline comment as done.
  • Remove comments
  • Hoist Range(-1,0) to ReturnsZeroOrMinusOne
steakhal accepted this revision.Dec 2 2020, 7:41 AM

Awesome, thank you.

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

I overlooked that we have a single Case, my bad.

This revision is now accepted and ready to land.Dec 2 2020, 7:41 AM