Skip to content

Commit 8a4551b

Browse files
committed
[Attributor][FIX] Use right address space to avoid assertion
When we strip and accumulate constant offsets we need to pick the right address space such that the offset APInt has the right bit width. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D112544
1 parent 4887752 commit 8a4551b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,11 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
12241224
}
12251225

12261226
// Check if the PHI operand is not dependent on the PHI itself.
1227-
APInt Offset(DL.getIndexTypeSizeInBits(AssociatedValue.getType()), 0);
1227+
// TODO: This is not great as we look at the pointer type. However, it
1228+
// is unclear where the Offset size comes from with typeless pointers.
1229+
APInt Offset(
1230+
DL.getIndexSizeInBits(CurPtr->getType()->getPointerAddressSpace()),
1231+
0);
12281232
if (&AssociatedValue == CurPtr->stripAndAccumulateConstantOffsets(
12291233
DL, Offset, /* AllowNonInbounds */ true)) {
12301234
if (Offset != PtrOI.Offset) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: opt < %s -S -passes=openmp-opt
2+
3+
; Verify the address space cast doesn't cause a crash
4+
5+
target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7"
6+
7+
%"struct.(anonymous namespace)::TeamStateTy" = type { %"struct.(anonymous namespace)::ICVStateTy", i32, i8* }
8+
%"struct.(anonymous namespace)::ICVStateTy" = type { i32, i32, i32, i32, i32, i32 }
9+
%"struct.(anonymous namespace)::ThreadStateTy" = type { %"struct.(anonymous namespace)::ICVStateTy", %"struct.(anonymous namespace)::ThreadStateTy"* }
10+
11+
@_ZN12_GLOBAL__N_19TeamStateE = internal addrspace(3) global %"struct.(anonymous namespace)::TeamStateTy" undef, align 8
12+
13+
define internal i8* @__kmpc_alloc_shared() {
14+
lor.lhs.false.i.i:
15+
br i1 false, label %_ZN4_OMP5state8lookup32ENS0_9ValueKindEb.exit.i, label %if.then.i44.i.i
16+
17+
if.then.i44.i.i: ; preds = %lor.lhs.false.i.i
18+
br label %_ZN4_OMP5state8lookup32ENS0_9ValueKindEb.exit.i
19+
20+
_ZN4_OMP5state8lookup32ENS0_9ValueKindEb.exit.i: ; preds = %if.then.i44.i.i, %lor.lhs.false.i.i
21+
%.pn.i45.i.i = phi i8* [ null, %if.then.i44.i.i ], [ addrspacecast (i8 addrspace(3)* bitcast (%"struct.(anonymous namespace)::TeamStateTy" addrspace(3)* @_ZN12_GLOBAL__N_19TeamStateE to i8 addrspace(3)*) to i8*), %lor.lhs.false.i.i ]
22+
%retval.0.in.i.i.i = getelementptr inbounds i8, i8* %.pn.i45.i.i, i64 4
23+
%retval.0.i46.i.i = bitcast i8* %retval.0.in.i.i.i to i32*
24+
%0 = load i32, i32* %retval.0.i46.i.i, align 4
25+
ret i8* null
26+
}
27+
28+
!llvm.module.flags = !{!0, !1}
29+
30+
!0 = !{i32 7, !"openmp", i32 50}
31+
!1 = !{i32 7, !"openmp-device", i32 50}

0 commit comments

Comments
 (0)