Skip to content
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

[FunctionAttrs] Incorrect nonnull inference for non-inbounds GEP #91177

Closed
nikic opened this issue May 6, 2024 · 2 comments · Fixed by #91180
Closed

[FunctionAttrs] Incorrect nonnull inference for non-inbounds GEP #91177

nikic opened this issue May 6, 2024 · 2 comments · Fixed by #91180
Assignees
Labels
ipo Interprocedural optimizations miscompilation

Comments

@nikic
Copy link
Contributor

nikic commented May 6, 2024

FunctionAttrs incorrectly infers that the following function returns nonnull (https://llvm.godbolt.org/z/49Kbq15xn):

define ptr @test(ptr nonnull %arg) {
  %res = getelementptr i8, ptr %arg, i64 -8
  ret ptr %res
}

This is because the code assumes that the result of a GEP is non-null if the source is non-null here:

case Instruction::GetElementPtr:
This is not correct for non-inbounds GEPs.

@nikic nikic self-assigned this May 6, 2024
@nikic nikic added this to the LLVM 18.X Release milestone May 6, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status May 6, 2024
nikic added a commit to nikic/llvm-project that referenced this issue May 6, 2024
nikic added a commit to nikic/llvm-project that referenced this issue May 6, 2024
For inbounds GEPs, if the source pointer is non-null, the result
must also be non-null. However, this does not hold for non-inbounds
GEPs.

Fixes llvm#91177.
nikic added a commit that referenced this issue May 7, 2024
…91180)

For inbounds GEPs, if the source pointer is non-null, the result must
also be non-null. However, this does not hold for non-inbounds GEPs.
    
Fixes #91177.
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in LLVM Release Status May 7, 2024
@nikic
Copy link
Contributor Author

nikic commented May 7, 2024

/cherry-pick f34d30c

llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue May 7, 2024
…lvm#91180)

For inbounds GEPs, if the source pointer is non-null, the result must
also be non-null. However, this does not hold for non-inbounds GEPs.

Fixes llvm#91177.

(cherry picked from commit f34d30c)
@llvmbot
Copy link

llvmbot commented May 7, 2024

/pull-request #91286

@EugeneZelenko EugeneZelenko added ipo Interprocedural optimizations and removed llvm:optimizations labels May 7, 2024
tstellar pushed a commit to llvmbot/llvm-project that referenced this issue May 9, 2024
…lvm#91180)

For inbounds GEPs, if the source pointer is non-null, the result must
also be non-null. However, this does not hold for non-inbounds GEPs.

Fixes llvm#91177.

(cherry picked from commit f34d30c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ipo Interprocedural optimizations miscompilation
Projects
Development

Successfully merging a pull request may close this issue.

3 participants