-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fixed issue #128882: don't warn if 1st argument to 'getcwd' is NULL #135720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seanm
wants to merge
1
commit into
llvm:main
Choose a base branch
from
seanm:Issue128882
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you drop this branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It caused a build/test warning/error here on github, I was hoping this was the correct fix. But I don't know the llvm codebase at all...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. I think I understand this now.
Because of
ReturnValueCondition(BO_EQ, ArgNo(0))
on the success path we assume that the returned pointer is the same (aka. equal to) the first argument, which means thatPath
holds the same pointer asBuf
.Because of this, dropping the
ArgConstraint(NotNull(ArgNo(0)))
means that no longer affects the return valuePath
. This is actually a good thing.Could you please help me how does the test failure look like for you if you would keep this hunk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the github CI delete previous results after I updated the PR? I can't find it here anymore...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, indeed it was there:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to interpret this:
So after your patch, now we reach the print statement at line 109 with 2 paths, one in which
errno
is known to be zero, and also a different path where we know it's not zero. This is why thetrue
expectation is met, but complains about that it also printsfalse
for the same line. I know it's hard to wrap your head around.Let's step back. What does this test? We are in a branch when
Path
aka. the result ofgetcwd
is NULL, aka. we had an error. In this caseerrno
should indicate the specific error that happened, which means we should know here thaterrno
is not zero. This is exactly what is enforced by the line 109.What if on the success path
Path
is equal toBuf
, which is a top-level symbol, thus when comparedPath
againstNULL
, we will have a state-split, so we enter thisPath == NULL
branch even on the success path. This is whyerrno
is known there to be non-zero, hence the new diagnostic.What is missing I think is a new
ReturnValueCondition
for the success path constraining the return value NOT being null. @balazske WDYT of this reasoning?Can we have multiple
ReturnValueCondition
s for a summary? I have something likeReturnValueCondition(BO_NE, SingleValue(0))
in mind to add there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, frankly, I do not follow. Seems this is a case where fixing the tests is harder than fixing the actual bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping @balazske
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the issue 128882, it references to the macOS man page for
getcwd
where a NULLbuf
argument is allowed. This is different from the original POSIX documentation where "the behavior of getcwd() is unspecified" ifbuf
is NULL. This is why the condition is there. But "unspecified" does not mean invalid, so it may be correct to drop this requirement. But we must check how this affects theBufferSizeConstraint
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not just macOS.
linux's glibc's "allocates the buffer dynamically using malloc if buf is NULL."
And FreeBSD: If buf is NULL, space is allocated as necessary to store the pathname. This space may later be free'd.