Skip to content

Commit 398fa91

Browse files
committed
Emit getelementptr nuw for Struct field
1 parent 81588c7 commit 398fa91

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

gen/llvmhelpers.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,12 @@ DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
18821882
LLType * ty = nullptr;
18831883
if (!isFieldIdx) {
18841884
// apply byte-wise offset from object start
1885-
ptr = DtoGEP1(getI8Type(), ptr, off);
1885+
ptr = DtoGEP1(getI8Type(), ptr, off
1886+
#if LDC_LLVM_VER >= 2000
1887+
, "", nullptr
1888+
, llvm::GEPNoWrapFlags::inBounds() | llvm::GEPNoWrapFlags::noUnsignedWrap()
1889+
#endif
1890+
);
18861891
ty = DtoType(vd->type);
18871892
} else {
18881893
if (ad->structsize == 0) { // can happen for extern(C) structs
@@ -1896,7 +1901,12 @@ DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
18961901
} else {
18971902
st = irTypeAggr->getLLType();
18981903
}
1899-
ptr = DtoGEP(st, ptr, 0, off);
1904+
ptr = DtoGEP(st, ptr, 0, off
1905+
#if LDC_LLVM_VER >= 2000
1906+
, "", nullptr
1907+
, llvm::GEPNoWrapFlags::inBounds() | llvm::GEPNoWrapFlags::noUnsignedWrap()
1908+
#endif
1909+
);
19001910
ty = isaStruct(st)->getElementType(off);
19011911
}
19021912
}

tests/codegen/inbounds.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int foo7(int* p, int i) {
5858
// Struct field
5959
// CHECK-LABEL: @foo8
6060
float foo8(S s) {
61-
// CHECK: getelementptr inbounds
61+
// CHECK: getelementptr inbounds{{( nuw)?}}
6262
return s.y;
6363
}
6464

0 commit comments

Comments
 (0)