Skip to content

Commit cc5e8cf

Browse files
committed
Emit getelementptr nuw for Struct field
1 parent 2931faa commit cc5e8cf

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

gen/llvmhelpers.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,12 @@ DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
18701870
LLType * ty = nullptr;
18711871
if (!isFieldIdx) {
18721872
// apply byte-wise offset from object start
1873-
ptr = DtoGEP1(getI8Type(), ptr, off);
1873+
ptr = DtoGEP1(getI8Type(), ptr, off
1874+
#if LDC_LLVM_VER >= 2000
1875+
, "", nullptr
1876+
, llvm::GEPNoWrapFlags::inBounds() | llvm::GEPNoWrapFlags::noUnsignedWrap()
1877+
#endif
1878+
);
18741879
ty = DtoType(vd->type);
18751880
} else {
18761881
if (ad->structsize == 0) { // can happen for extern(C) structs
@@ -1884,7 +1889,12 @@ DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
18841889
} else {
18851890
st = irTypeAggr->getLLType();
18861891
}
1887-
ptr = DtoGEP(st, ptr, 0, off);
1892+
ptr = DtoGEP(st, ptr, 0, off
1893+
#if LDC_LLVM_VER >= 2000
1894+
, "", nullptr
1895+
, llvm::GEPNoWrapFlags::inBounds() | llvm::GEPNoWrapFlags::noUnsignedWrap()
1896+
#endif
1897+
);
18881898
ty = isaStruct(st)->getElementType(off);
18891899
}
18901900
}

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)