# HG changeset patch # User Paul Boddie # Date 1488115776 -3600 # Node ID 67f2da40bb32603dc0e9eafd47a1d107f54e4d30 # Parent 00ee53b9977bb80c774de54cc847e9f25836a755 Added constant identifier digest collision testing. diff -r 00ee53b9977b -r 67f2da40bb32 errors.py --- a/errors.py Sun Feb 26 00:11:12 2017 +0100 +++ b/errors.py Sun Feb 26 14:29:36 2017 +0100 @@ -4,7 +4,7 @@ Error classes. Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 - 2014, 2016 Paul Boddie + 2014, 2016, 2017 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -85,6 +85,13 @@ def __str__(self): return "Error in deduction: %s" % self.message +class OptimiseError(ProgramError): + + "An error during optimisation." + + def __str__(self): + return "Error in optimisation: %s" % self.message + class TranslateError(NodeProcessingError): "An error during the module translation process." diff -r 00ee53b9977b -r 67f2da40bb32 optimiser.py --- a/optimiser.py Sun Feb 26 00:11:12 2017 +0100 +++ b/optimiser.py Sun Feb 26 14:29:36 2017 +0100 @@ -22,6 +22,7 @@ from common import add_counter_item, get_attrname_from_location, init_item, \ sorted_output from encoders import digest, encode_access_location, encode_instruction, get_kinds +from errors import OptimiseError from os.path import exists, join from os import makedirs from referencing import Reference @@ -73,6 +74,7 @@ self.constants = [] self.constant_numbers = {} + self.digests = {} # Optimiser activities. @@ -742,7 +744,21 @@ # Each constant is actually (value, value_type, encoding). for constant, n in constants.items(): - self.constants[constant] = digest(constant) + d = digest(constant) + self.constants[constant] = d + + # Make sure the digests are really distinct for different + # constants. + + if self.digests.has_key(d): + if self.digests[d] != constant: + raise OptimiseError, "Digest %s used for distinct constants %r and %r." % ( + d, self.digests[d], constant) + else: + self.digests[d] = constant + + # Establish a mapping from local constant identifiers to consolidated + # constant identifiers. self.constant_numbers = {}