Skip to content

Commit 715d79d

Browse files
authored
[FRONTEND] assert identifier legality (#5697)
1 parent 29912c0 commit 715d79d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

python/triton/compiler/code_generator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
from .errors import (CompilationError, CompileTimeAssertionFailure, UnsupportedLanguageConstruct)
2121

2222

23+
def check_identifier_legality(name, type):
24+
pattern = r'^[a-zA-Z_][a-zA-Z0-9_]*$'
25+
if not re.match(pattern, name):
26+
raise CompilationError(f"invalid {type} identifier: {name}", name)
27+
return name
28+
29+
2330
def mangle_ty(ty):
2431
if ty.is_tuple():
2532
return 'T' + '_'.join(map(mangle_ty, ty.types)) + 'T'
@@ -276,6 +283,9 @@ def __init__(self, context, prototype, gscope, function_name, jit_fn: JITFunctio
276283

277284
self.lscope = {}
278285
self.jit_fn = jit_fn
286+
# TODO: we currently generate illegal names for non-kernel functions involving constexprs!
287+
if is_kernel:
288+
function_name = check_identifier_legality(function_name, "function")
279289
self.function_name = function_name
280290
self.is_kernel = is_kernel
281291
self.cur_node = None

0 commit comments

Comments
 (0)