Mesa (master): nir/algebraic: Detect some kinds of malformed variable names
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Apr 27 16:29:44 UTC 2020
Module: Mesa
Branch: master
Commit: ba8f7f3fa2c62ba8cc31dda5915b4e2a58eef00a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ba8f7f3fa2c62ba8cc31dda5915b4e2a58eef00a
Author: Ian Romanick <ian.d.romanick at intel.com>
Date: Thu Apr 23 17:39:07 2020 -0700
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 <jason at jlekstrand.net>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com> [v1]
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4720>
---
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<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')
More information about the mesa-commit
mailing list