Skip to content

Commit e4519fb

Browse files
committed
tests: Add test to ensure operands are cast to long when calculating temp array allocation sizes
1 parent 66d6755 commit e4519fb

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎tests/test_dse.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,6 +2976,30 @@ def test_subdims_wo_block_temps(self):
29762976

29772977
op.apply()
29782978

2979+
@pytest.mark.parametrize('lang', ['C', 'CXX'])
2980+
def test_temp_array_allocation_uses_long(self, lang):
2981+
"""
2982+
Ensure that operands are cast to long when calculating the size of a
2983+
temporary array to prevent int32 wraparound.
2984+
"""
2985+
grid = Grid(shape=(31, 17, 25))
2986+
2987+
a = Function(name='a', grid=grid)
2988+
f = TimeFunction(name='f', grid=grid)
2989+
g = TimeFunction(name='g', grid=grid)
2990+
2991+
eq0 = Eq(f.forward, g + sin(a).dx)
2992+
eq1 = Eq(g.forward, f + sin(a).dx)
2993+
2994+
opt = ('advanced', {'cire-minmem': True, 'index-mode': 'int64'})
2995+
with switchconfig(language=lang):
2996+
op = Operator([eq0, eq1], opt=opt)
2997+
2998+
cast = '(long)' if lang == 'C' else 'static_cast<long>'
2999+
3000+
# 3 casts in memalign, 3 in memset
3001+
assert str(op).count(cast) == 6
3002+
29793003

29803004
class TestIsoAcoustic:
29813005

0 commit comments

Comments
 (0)