Skip to content

Commit fa8dc36

Browse files
authored
[IR] Fix crashes caused by #85592 (#87169)
This patch fixes the crash caused by the pull request: #85592
1 parent f6c87be commit fa8dc36

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

llvm/lib/IR/Operator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ bool Operator::hasPoisonGeneratingFlags() const {
2828
return OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap();
2929
}
3030
case Instruction::Trunc: {
31-
auto *TI = dyn_cast<TruncInst>(this);
32-
return TI->hasNoUnsignedWrap() || TI->hasNoSignedWrap();
31+
if (auto *TI = dyn_cast<TruncInst>(this))
32+
return TI->hasNoUnsignedWrap() || TI->hasNoSignedWrap();
33+
return false;
3334
}
3435
case Instruction::UDiv:
3536
case Instruction::SDiv:

llvm/test/Transforms/FunctionAttrs/noundef.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
22
; RUN: opt < %s -passes='function-attrs' -S | FileCheck %s
33

4+
@g_var = external global [0 x i8]
5+
46
define i32 @test_ret_constant() {
57
; CHECK-LABEL: define noundef i32 @test_ret_constant(
68
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
@@ -152,3 +154,15 @@ define i32 @test_ret_constant_msan() sanitize_memory {
152154
;
153155
ret i32 0
154156
}
157+
158+
define i64 @test_trunc_with_constexpr() {
159+
; CHECK-LABEL: define noundef i64 @test_trunc_with_constexpr(
160+
; CHECK-SAME: ) #[[ATTR0]] {
161+
; CHECK-NEXT: [[ADD:%.*]] = add i32 trunc (i64 sub (i64 0, i64 ptrtoint (ptr @g_var to i64)) to i32), 1
162+
; CHECK-NEXT: [[CONV:%.*]] = sext i32 [[ADD]] to i64
163+
; CHECK-NEXT: ret i64 [[CONV]]
164+
;
165+
%add = add i32 trunc (i64 sub (i64 0, i64 ptrtoint (ptr @g_var to i64)) to i32), 1
166+
%conv = sext i32 %add to i64
167+
ret i64 %conv
168+
}

0 commit comments

Comments
 (0)