From 82081b22062fc4fb14c791cb4e547632e20b24cd Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Mon, 16 Oct 2017 01:20:01 +0200 Subject: [PATCH] Fix crash when variables appear inside global lists. Fixes #3. --- lslopt/lsldeadcode.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lslopt/lsldeadcode.py b/lslopt/lsldeadcode.py index c5556eb..337d3b4 100644 --- a/lslopt/lsldeadcode.py +++ b/lslopt/lsldeadcode.py @@ -223,8 +223,19 @@ class deadcode(object): node['X'] = True if child is not None: if 'orig' in child[0]: - self.MarkReferences(child[0]['orig']) - child[0]['X'] = child[0]['orig']['X'] + orig = child[0]['orig'] + self.MarkReferences(orig) + child[0]['X'] = orig['X'] + if orig['nt'] == 'LIST': + # Add fake writes to variables used in list elements in + # 'orig', so they don't get deleted (Issue #3) + for subnode in orig['ch']: + if subnode['nt'] == 'IDENT': + # can only happen in globals + assert subnode['scope'] == 0 + sym = self.symtab[0][subnode['name']] + sym['W'] = False + self.tree[sym['Loc']]['X'] = True else: self.MarkReferences(child[0]) return True