Skip to content

Commit 14738d7

Browse files
committed
compiler: Fix stack corruption bug in specialization
1 parent 7afa536 commit 14738d7

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

devito/ir/iet/visitors.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
from devito.exceptions import CompilationError
1818
from devito.ir.iet.nodes import (
19-
BlankLine, Call, Expression, ExpressionBundle, Iteration, Lambda, ListMajor, Node,
20-
MetaCall, Section
19+
BlankLine, Call, Expression, ExpressionBundle, Iteration, Lambda, ListMajor, MetaCall,
20+
Node, Section
2121
)
2222
from devito.ir.support.space import Backward
2323
from devito.symbolics import (
@@ -1593,13 +1593,17 @@ def visit_Operator(self, o, **kwargs):
15931593
# Modify the _func_table to ensure callbacks are specialized
15941594
state['_func_table'] = self._visit(o._func_table)
15951595

1596-
try:
1597-
state.pop('ccode')
1598-
except KeyError:
1599-
# C code has not previously been generated for this Operator
1600-
pass
1596+
state.pop('ccode', None)
1597+
1598+
# The specialized operator must be compiled fresh - strip any pre-existing
1599+
# compiled binary state inherited from a previously-applied operator.
1600+
# Without this, __setstate__ reloads the old binary (which expects the full
1601+
# parameter list), while the new operator has fewer parameters after
1602+
# specialization, causing a stack corruption (SIGABRT) at call time.
1603+
state.pop('binary', None)
1604+
state.pop('soname', None)
1605+
state.pop('_soname', None) # Clear cached soname so it is recomputed
16011606

1602-
# FIXME: These names aren't great
16031607
newargs, newkwargs = o.__getnewargs_ex__()
16041608
newop = o.__class__(*newargs, **newkwargs)
16051609

tests/test_specialization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ def test_basic_mpi(self, caplog, mode, override):
229229
@pytest.mark.parametrize('specialize',
230230
[('x_m',),
231231
('y_M',),
232-
('t_m',),
233-
('t_m', 't_M'),
232+
('time_m',),
233+
('time_m', 'time_M'),
234234
('x_m', 'y_M'),
235235
('x_m', 'x_M', 'y_m', 'y_M')])
236236
def test_diffusion_like(self, specialize):

0 commit comments

Comments
 (0)