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

Assertion with overflowing pointer with -fsanitize=pointer-overflow #124357

Open
efriedma-quic opened this issue Jan 24, 2025 · 1 comment
Open
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@efriedma-quic
Copy link
Collaborator

efriedma-quic commented Jan 24, 2025

Testcase:

void f(void g(void*, void*)) {
  int a[2][2];
  g(&a[0x8000000000000000], a+0x8000000000000000);
}

Compile with -fsanitize=pointer-overflow, produces:

<stdin>:1:59: warning: array index -9223372036854775808 is past the end of the array (that has type 'int[2][2]') [-Warray-bounds]
    1 | void f(void g(void*, void*)) { int x = 2; int a[2][2]; g(&a[0x8000000000000000], a+0x8000000000000000); }
      |                                                           ^ ~~~~~~~~~~~~~~~~~~
<stdin>:1:43: note: array 'a' declared here
    1 | void f(void g(void*, void*)) { int x = 2; int a[2][2]; g(&a[0x8000000000000000], a+0x8000000000000000); }
      |                                           ^
clang: /usr2/efriedma/local/upstream/llvm-top/clang/lib/CodeGen/CGExprScalar.cpp:5837: llvm::Value *clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *, llvm::Value *, ArrayRef<llvm::Value *>, bool, bool, clang::SourceLocation, const llvm::Twine &): Assertion `(!isa<llvm::Constant>(EvaluatedGEP.TotalOffset) || EvaluatedGEP.OffsetOverflows == Builder.getFalse()) && "If the offset got constant-folded, we don't expect that there was an " "overflow."' failed.
@EugeneZelenko EugeneZelenko added clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Jan 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 24, 2025

@llvm/issue-subscribers-clang-codegen

Author: Eli Friedman (efriedma-quic)

Testcase:
void f(void g(void*, void*)) {
  int a[2][2];
  g(&amp;a[0x8000000000000000], a+0x8000000000000000);
}

Compile with -fsanitize=pointer-overflow, produces:

&lt;stdin&gt;:1:59: warning: array index -9223372036854775808 is past the end of the array (that has type 'int[2][2]') [-Warray-bounds]
    1 | void f(void g(void*, void*)) { int x = 2; int a[2][2]; g(&amp;a[0x8000000000000000], a+0x8000000000000000); }
      |                                                           ^ ~~~~~~~~~~~~~~~~~~
&lt;stdin&gt;:1:43: note: array 'a' declared here
    1 | void f(void g(void*, void*)) { int x = 2; int a[2][2]; g(&amp;a[0x8000000000000000], a+0x8000000000000000); }
      |                                           ^
clang: /usr2/efriedma/local/upstream/llvm-top/clang/lib/CodeGen/CGExprScalar.cpp:5837: llvm::Value *clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *, llvm::Value *, ArrayRef&lt;llvm::Value *&gt;, bool, bool, clang::SourceLocation, const llvm::Twine &amp;): Assertion `(!isa&lt;llvm::Constant&gt;(EvaluatedGEP.TotalOffset) || EvaluatedGEP.OffsetOverflows == Builder.getFalse()) &amp;&amp; "If the offset got constant-folded, we don't expect that there was an " "overflow."' failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

3 participants