summaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2020-04-23 17:39:07 -0700
committerIan Romanick <[email protected]>2020-04-27 09:08:34 -0700
commitba8f7f3fa2c62ba8cc31dda5915b4e2a58eef00a (patch)
tree632d9cbf7f0b1a347582ff9ec7c1d7e16e67955a /src/compiler
parentfc4eb0714cd6ddf3aaeb865ef0694fc6596f6d56 (diff)
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 <[email protected]> Reviewed-by: Alyssa Rosenzweig <[email protected]> [v1] Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4720>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/nir/nir_algebraic.py8
1 files 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<const>#)?(?P<name>\w+)"
r"(?:@(?P<type>int|uint|bool|float)?(?P<bits>\d+)?)?"
r"(?P<cond>\([^\)]+\))?"
- r"(?P<swiz>\.[xyzw]+)?")
+ r"(?P<swiz>\.[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')