Skip to content

[llc] Signed Overflow detected by UBSan. #75944

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

Closed
Ralender opened this issue Dec 19, 2023 · 4 comments · Fixed by #101840
Closed

[llc] Signed Overflow detected by UBSan. #75944

Ralender opened this issue Dec 19, 2023 · 4 comments · Fixed by #101840
Labels
backend:X86 bug Indicates an unexpected problem or unintended behavior

Comments

@Ralender
Copy link
Collaborator

Ralender commented Dec 19, 2023

target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128"
target triple = "i386-unknown-linux-gnu"

define void @test(ptr %0) {
  %2 = alloca [10 x i8], i32 0, align 1
  %3 = ptrtoint ptr %2 to i32
  %4 = add i32 %3, 2147483647
  br label %5

5:                                                ; preds = %5, %1
  %6 = phi i32 [ 0, %1 ], [ %7, %5 ]
  %7 = add i32 %6, 1
  %8 = icmp eq i32 %6, %4
  br label %5
]

with llc compiled with UBSan

> llc out.ll
.../llvm-project/llvm/lib/Target/X86/X86RegisterInfo.cpp:945:27: runtime error: signed integer overflow: 3 + 2147483647 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior .../llvm-project/llvm/lib/Target/X86/X86RegisterInfo.cpp:945:27 in

I can reproduce this on f17e766

@Ralender Ralender added bug Indicates an unexpected problem or unintended behavior backend:X86 labels Dec 19, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2023

@llvm/issue-subscribers-bug

Author: None (Ralender)

```ll target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128" target triple = "i386-unknown-linux-gnu"

define void @test(ptr %0) {
%2 = alloca [10 x i8], i32 0, align 1
%3 = ptrtoint ptr %2 to i32
%4 = add i32 %3, 2147483647
br label %5

5: ; preds = %5, %1
%6 = phi i32 [ 0, %1 ], [ %7, %5 ]
%7 = add i32 %6, 1
%8 = icmp eq i32 %6, %4
br label %5
]

```bash
> llc out.ll
.../llvm-project/llvm/lib/Target/X86/X86RegisterInfo.cpp:945:27: runtime error: signed integer overflow: 3 + 2147483647 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior .../llvm-project/llvm/lib/Target/X86/X86RegisterInfo.cpp:945:27 in

I can reproduce this on f17e766

@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2023

@llvm/issue-subscribers-backend-x86

Author: None (Ralender)

```ll target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128" target triple = "i386-unknown-linux-gnu"

define void @test(ptr %0) {
%2 = alloca [10 x i8], i32 0, align 1
%3 = ptrtoint ptr %2 to i32
%4 = add i32 %3, 2147483647
br label %5

5: ; preds = %5, %1
%6 = phi i32 [ 0, %1 ], [ %7, %5 ]
%7 = add i32 %6, 1
%8 = icmp eq i32 %6, %4
br label %5
]

```bash
> llc out.ll
.../llvm-project/llvm/lib/Target/X86/X86RegisterInfo.cpp:945:27: runtime error: signed integer overflow: 3 + 2147483647 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior .../llvm-project/llvm/lib/Target/X86/X86RegisterInfo.cpp:945:27 in

I can reproduce this on f17e766

@MaskRay
Copy link
Member

MaskRay commented Jul 14, 2024

This will be fixed once the reverted #84114 relands.

@MaskRay
Copy link
Member

MaskRay commented Jul 23, 2024

Fixed by #99263

@MaskRay MaskRay closed this as completed Jul 23, 2024
arsenm pushed a commit that referenced this issue Aug 19, 2024
…101840)

Fix 32-bit integer overflows in the X86 target frame layout when dealing
with frames larger than 4gb. When this occurs, we'll scavenge a scratch
register to be able to hold the correct stack offset for frame locals.

This completes reapplying #84114.

Fixes #48911
Fixes #75944 
Fixes #87154
zmodem added a commit that referenced this issue Aug 21, 2024
…rames (#101840)"

This casuses assertion failures targeting 32-bit x86:

  lib/Target/X86/X86RegisterInfo.cpp:989:
  virtual bool llvm::X86RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator, int, unsigned int, RegScavenger *) const:
  Assertion `(Is64Bit || FitsIn32Bits) && "Requesting 64-bit offset in 32-bit immediate!"' failed.

See comment on the PR.

> Fix 32-bit integer overflows in the X86 target frame layout when dealing
> with frames larger than 4gb. When this occurs, we'll scavenge a scratch
> register to be able to hold the correct stack offset for frame locals.
>
> This completes reapplying #84114.
>
> Fixes #48911
> Fixes #75944
> Fixes #87154

This reverts commit 0abb779.
cjdb pushed a commit to cjdb/llvm-project that referenced this issue Aug 23, 2024
…rames (llvm#101840)"

This casuses assertion failures targeting 32-bit x86:

  lib/Target/X86/X86RegisterInfo.cpp:989:
  virtual bool llvm::X86RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator, int, unsigned int, RegScavenger *) const:
  Assertion `(Is64Bit || FitsIn32Bits) && "Requesting 64-bit offset in 32-bit immediate!"' failed.

See comment on the PR.

> Fix 32-bit integer overflows in the X86 target frame layout when dealing
> with frames larger than 4gb. When this occurs, we'll scavenge a scratch
> register to be able to hold the correct stack offset for frame locals.
>
> This completes reapplying llvm#84114.
>
> Fixes llvm#48911
> Fixes llvm#75944
> Fixes llvm#87154

This reverts commit 0abb779.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants