Skip to content

Commit

Permalink
[FRONTEND] assert identifier legality (#5697)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptillet authored Jan 24, 2025
1 parent 29912c0 commit 715d79d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/triton/compiler/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
from .errors import (CompilationError, CompileTimeAssertionFailure, UnsupportedLanguageConstruct)


def check_identifier_legality(name, type):
pattern = r'^[a-zA-Z_][a-zA-Z0-9_]*$'
if not re.match(pattern, name):
raise CompilationError(f"invalid {type} identifier: {name}", name)
return name


def mangle_ty(ty):
if ty.is_tuple():
return 'T' + '_'.join(map(mangle_ty, ty.types)) + 'T'
Expand Down Expand Up @@ -276,6 +283,9 @@ def __init__(self, context, prototype, gscope, function_name, jit_fn: JITFunctio

self.lscope = {}
self.jit_fn = jit_fn
# TODO: we currently generate illegal names for non-kernel functions involving constexprs!
if is_kernel:
function_name = check_identifier_legality(function_name, "function")
self.function_name = function_name
self.is_kernel = is_kernel
self.cur_node = None
Expand Down

0 comments on commit 715d79d

Please sign in to comment.