From ba8f7f3fa2c62ba8cc31dda5915b4e2a58eef00a Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 23 Apr 2020 17:39:07 -0700 Subject: [PATCH] nir/algebraic: Detect some kinds of malformed variable names I spent over an hour trying to debug a problem if a condition on a variable not being applied. The problem turned out to be "a(is_not_negative" instead of "a(is_not_negative)". This commit would have detected that problem and failed to build. v2: Just add $ to the end of the existing regex, and it will fail to match a malformed string. Suggested by Jason. Reviewed-by: Jason Ekstrand Reviewed-by: Alyssa Rosenzweig [v1] Part-of: --- src/compiler/nir/nir_algebraic.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 480dcaf3cf5..2112854570d 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -283,17 +283,21 @@ class Constant(Value): return self.value == other.value +# The $ at the end forces there to be an error if any part of the string +# doesn't match one of the field patterns. _var_name_re = re.compile(r"(?P#)?(?P\w+)" r"(?:@(?Pint|uint|bool|float)?(?P\d+)?)?" r"(?P\([^\)]+\))?" - r"(?P\.[xyzw]+)?") + r"(?P\.[xyzw]+)?" + r"$") class Variable(Value): def __init__(self, val, name, varset): Value.__init__(self, val, name, "variable") m = _var_name_re.match(val) - assert m and m.group('name') is not None + assert m and m.group('name') is not None, \ + "Malformed variable name \"{}\".".format(val) self.var_name = m.group('name') -- 2.30.2