This is an archive of the discontinued LLVM Phabricator instance.

[clang][analyzer] Handle special value AT_FDCWD in affected standard functions
ClosedPublic

Authored by balazske on Apr 25 2023, 8:00 AM.

Details

Summary

Some file and directory related functions have an integer file descriptor argument
that can be a valid file descriptor or a special value AT_FDCWD. This value is
relatively often used in open source projects and is usually defined as a negative
number, and the checker reports false warnings (a valid file descriptor is not
negative) if this fix is not included.

Diff Detail

Event Timeline

balazske created this revision.Apr 25 2023, 8:00 AM
Herald added a reviewer: NoQ. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
balazske requested review of this revision.Apr 25 2023, 8:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 8:00 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
balazske updated this revision to Diff 516818.Apr 25 2023, 8:26 AM

Fixed formatting problems.

steakhal added inline comments.Apr 26 2023, 5:32 AM
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
1530–1542
2142–2143

I think I would recommend hoisting this common subexpression. This would save repetition on subsequent occurrences.

const auto ValidDescriptorOrAtCWDRange = Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax});

You can explore if hoisting the whole ArgumentCondition would make it even more readable.

balazske updated this revision to Diff 517457.Apr 26 2023, 11:41 PM

added special argument condition function to remove code repetition

steakhal added inline comments.Apr 27 2023, 12:03 AM
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
1530–1542

What is your response @balazske?

1988

Should we define a specific constraint description?
If not, then we should not specify it explicitly - given that it's already defined as an empty string by default.

balazske updated this revision to Diff 517470.Apr 27 2023, 12:54 AM
balazske marked an inline comment as done.

using short way for getting macro value
added constraint description

balazske marked 2 inline comments as done.Apr 27 2023, 12:57 AM
balazske added inline comments.
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
1530–1542

This is much better.

1988

Now a description is added. This looks better, but the user should know what is a "valid file descriptor" (is 0 allowed or not), it is not shown now.

balazske marked 3 inline comments as done.May 15 2023, 1:27 AM
This revision is now accepted and ready to land.May 15 2023, 11:24 AM