Skip to content

Commit d27bd60

Browse files
committed
Emit getelementptr nuw for Struct field
1 parent ea965e0 commit d27bd60

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
@@ -1860,7 +1860,12 @@ DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
18601860
LLType * ty = nullptr;
18611861
if (!isFieldIdx) {
18621862
// apply byte-wise offset from object start
1863-
ptr = DtoGEP1(getI8Type(), ptr, off);
1863+
ptr = DtoGEP1(getI8Type(), ptr, off
1864+
#if LDC_LLVM_VER >= 2000
1865+
, "", nullptr
1866+
, llvm::GEPNoWrapFlags::inBounds() | llvm::GEPNoWrapFlags::noUnsignedWrap()
1867+
#endif
1868+
);
18641869
ty = DtoType(vd->type);
18651870
} else {
18661871
if (ad->structsize == 0) { // can happen for extern(C) structs
@@ -1874,7 +1879,12 @@ DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
18741879
} else {
18751880
st = irTypeAggr->getLLType();
18761881
}
1877-
ptr = DtoGEP(st, ptr, 0, off);
1882+
ptr = DtoGEP(st, ptr, 0, off
1883+
#if LDC_LLVM_VER >= 2000
1884+
, "", nullptr
1885+
, llvm::GEPNoWrapFlags::inBounds() | llvm::GEPNoWrapFlags::noUnsignedWrap()
1886+
#endif
1887+
);
18781888
ty = isaStruct(st)->getElementType(off);
18791889
}
18801890
}

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)