This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][StdLibraryFunctionsChecker] Add more return value contraints
ClosedPublic

Authored by martong on Dec 7 2020, 9:37 AM.

Details

Summary

This time, we add contraints to functions that either return with [0, -1] or with a file descriptor.

Diff Detail

Event Timeline

martong created this revision.Dec 7 2020, 9:37 AM
martong requested review of this revision.Dec 7 2020, 9:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 7 2020, 9:37 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
steakhal accepted this revision.Dec 8 2020, 4:13 AM

It must have been a tedious task to collect all these - without any copy-paste errors, really impressive!

It's good to go, however, if you don't mind there would be some readability issues yet to solve in a later path in the inline comments.

clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
1367–1368

I think you should hoist this ArgumentCondition construction with a lambda call. It would lead to more readable summaries.

const auto ValidFileDescriptorArgAt = [](unsigned ArgIdx) {
  return ArgumentCondition(ArgIdx, WithinRange, Range(0, IntMax))));
};

Probably the very same principle would apply for handling off_t arguments.

You can probably find a better name, but you get the idea.
If you agree on this, you could create a follow-up patch.

1888

The same principle applies here too.

1905

It's a sane overapproximation. Perfectly fine for us.

This revision is now accepted and ready to land.Dec 8 2020, 4:13 AM

One more thing.
Please reflow the path's summary, to keep the range constraint in a single line.

martong edited the summary of this revision. (Show Details)Dec 8 2020, 7:32 AM
martong marked 3 inline comments as done.Dec 8 2020, 8:03 AM

Thanks for the review!

clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
1367–1368

Good idea, thanks! I am going to create another patch for this (and another for exec* functions).

This revision was landed with ongoing or failed builds.Dec 8 2020, 8:06 AM
This revision was automatically updated to reflect the committed changes.
martong marked an inline comment as done.