[PATCH] D65970: [GlobalOpt] prevent crashing on wide integer types (PR42932)
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 13:43:02 PDT 2019
spatel created this revision.
spatel added reviewers: t.p.northover, bogner, rnk.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: LLVM.
I don't know anything about this pass, so this is a minimal fix to prevent the crashing seen in:
https://bugs.llvm.org/show_bug.cgi?id=42932
...when converting a constant integer of arbitrary width to uint64_t.
https://reviews.llvm.org/D65970
Files:
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/test/Transforms/GlobalOpt/large-int-crash.ll
Index: llvm/test/Transforms/GlobalOpt/large-int-crash.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GlobalOpt/large-int-crash.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+ at X = internal global i128 0
+
+define void @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT: [[T0_B:%.*]] = load i1, i1* @X
+; CHECK-NEXT: [[T0:%.*]] = select i1 [[T0_B]], i128 18446744073709551616, i128 0
+; CHECK-NEXT: ret void
+;
+ %t0 = load i128, i128* @X, align 8
+ ret void
+}
+
+define void @store() {
+; CHECK-LABEL: @store(
+; CHECK-NEXT: store i1 true, i1* @X
+; CHECK-NEXT: ret void
+;
+ store i128 18446744073709551616, i128* @X, align 8
+ ret void
+}
Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1643,10 +1643,12 @@
// instead of a select to synthesize the desired value.
bool IsOneZero = false;
bool EmitOneOrZero = true;
- if (ConstantInt *CI = dyn_cast<ConstantInt>(OtherVal)){
+ auto *CI = dyn_cast<ConstantInt>(OtherVal);
+ if (CI && CI->getValue().getActiveBits() <= 64) {
IsOneZero = InitVal->isNullValue() && CI->isOne();
- if (ConstantInt *CIInit = dyn_cast<ConstantInt>(GV->getInitializer())){
+ auto *CIInit = dyn_cast<ConstantInt>(GV->getInitializer());
+ if (CIInit && CIInit->getValue().getActiveBits() <= 64) {
uint64_t ValInit = CIInit->getZExtValue();
uint64_t ValOther = CI->getZExtValue();
uint64_t ValMinus = ValOther - ValInit;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65970.214223.patch
Type: text/x-patch
Size: 1717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190808/f58c7e4e/attachment.bin>
More information about the llvm-commits
mailing list