[llvm] fa8dc36 - [IR] Fix crashes caused by #85592 (#87169)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 2 00:49:35 PDT 2024
Author: elhewaty
Date: 2024-04-02T15:49:31+08:00
New Revision: fa8dc363506893eb9371dd3b7590f41fa9a7174a
URL: https://github.com/llvm/llvm-project/commit/fa8dc363506893eb9371dd3b7590f41fa9a7174a
DIFF: https://github.com/llvm/llvm-project/commit/fa8dc363506893eb9371dd3b7590f41fa9a7174a.diff
LOG: [IR] Fix crashes caused by #85592 (#87169)
This patch fixes the crash caused by the pull request:
https://github.com/llvm/llvm-project/pull/85592
Added:
Modified:
llvm/lib/IR/Operator.cpp
llvm/test/Transforms/FunctionAttrs/noundef.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp
index 495769279e3363..7b4449cd825f9b 100644
--- a/llvm/lib/IR/Operator.cpp
+++ b/llvm/lib/IR/Operator.cpp
@@ -28,8 +28,9 @@ bool Operator::hasPoisonGeneratingFlags() const {
return OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap();
}
case Instruction::Trunc: {
- auto *TI = dyn_cast<TruncInst>(this);
- return TI->hasNoUnsignedWrap() || TI->hasNoSignedWrap();
+ if (auto *TI = dyn_cast<TruncInst>(this))
+ return TI->hasNoUnsignedWrap() || TI->hasNoSignedWrap();
+ return false;
}
case Instruction::UDiv:
case Instruction::SDiv:
diff --git a/llvm/test/Transforms/FunctionAttrs/noundef.ll b/llvm/test/Transforms/FunctionAttrs/noundef.ll
index 946b562f39553e..9ab37082a30329 100644
--- a/llvm/test/Transforms/FunctionAttrs/noundef.ll
+++ b/llvm/test/Transforms/FunctionAttrs/noundef.ll
@@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt < %s -passes='function-attrs' -S | FileCheck %s
+ at g_var = external global [0 x i8]
+
define i32 @test_ret_constant() {
; CHECK-LABEL: define noundef i32 @test_ret_constant(
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
@@ -152,3 +154,15 @@ define i32 @test_ret_constant_msan() sanitize_memory {
;
ret i32 0
}
+
+define i64 @test_trunc_with_constexpr() {
+; CHECK-LABEL: define noundef i64 @test_trunc_with_constexpr(
+; CHECK-SAME: ) #[[ATTR0]] {
+; CHECK-NEXT: [[ADD:%.*]] = add i32 trunc (i64 sub (i64 0, i64 ptrtoint (ptr @g_var to i64)) to i32), 1
+; CHECK-NEXT: [[CONV:%.*]] = sext i32 [[ADD]] to i64
+; CHECK-NEXT: ret i64 [[CONV]]
+;
+ %add = add i32 trunc (i64 sub (i64 0, i64 ptrtoint (ptr @g_var to i64)) to i32), 1
+ %conv = sext i32 %add to i64
+ ret i64 %conv
+}
More information about the llvm-commits
mailing list