Skip to content

Commit

Permalink
gep issue test
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartarchibald committed Jun 26, 2017
1 parent 76191dc commit 7e9f24e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvmlite/ir/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def __init__(self, parent, ptr, indices, inbounds, name):
isinstance(lasttyp, types.PointerType)):
typ = lasttyp
else:
typ = typ.as_pointer(ptr.addrspace)
typ = typ.as_pointer(getattr(ptr, 'addrspace', 0))

super(GEPInstr, self).__init__(parent, typ, "getelementptr",
[ptr] + list(indices), name=name)
Expand Down
17 changes: 17 additions & 0 deletions llvmlite/tests/test_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,23 @@ def test_gep(self):
%"d" = getelementptr i32*, i32** %"c", i32 5, i32 %".1"
""")
# XXX test with more complex types

def test_gep_castinstr(self):
# similar to:
# numba::runtime::nrtdynmod.py_define_nrt_meminfo_data()
block = self.block(name='my_block')
builder = ir.IRBuilder(block)
a, b = builder.function.args[:2]
int8ptr = int8.as_pointer()
ls = ir.LiteralStructType([int64, int8ptr, int8ptr, int8ptr, int64])
d = builder.bitcast(a, ls.as_pointer(), name='d')
e = builder.gep(d, [ir.Constant(int32, x) for x in [0, 3]], name='e')
self.assertEqual(e.type, ir.PointerType(int8ptr))
self.check_block(block, """\
my_block:
%"d" = bitcast i32 %".1" to {i64, i8*, i8*, i8*, i64}*
%"e" = getelementptr {i64, i8*, i8*, i8*, i64}, {i64, i8*, i8*, i8*, i64}* %"d", i32 0, i32 3
""")

def test_gep_addrspace(self):
block = self.block(name='my_block')
Expand Down
Empty file modified runtests.py
100644 → 100755
Empty file.

0 comments on commit 7e9f24e

Please sign in to comment.