Skip to content

Commit a15fe4e

Browse files
authored
Merge pull request #60 from Jorghi12/patch-1
Escaping Inputs to regular expressions.
2 parents 9eb3991 + afabdb9 commit a15fe4e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tools/amd_build/pyHIPIFY/hipify-python.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def disable_asserts(input_string):
465465

466466

467467
def replace_forceinline(input_string):
468-
"""__forceinline__'d methods can cause 'symbol multiply defined' errors in HIP.
468+
"""__forceinline__'d methods can cause 'symbol multiply defined' errors in HIP.
469469
Adding 'static' to all such methods leads to compilation errors, so
470470
replacing '__forceinline__' with 'inline' as a workaround
471471
https://github.com/ROCm-Developer-Tools/HIP/blob/master/docs/markdown/hip_faq.md#what-if-hip-generates-error-of-symbol-multiply-defined-only-on-amd-machine
@@ -681,9 +681,9 @@ def preprocessor(filepath, stats, hipify_caffe2):
681681

682682
if cuda_type in output_source:
683683
if hipify_caffe2:
684-
pattern = r'({0})'.format(cuda_type)
684+
pattern = r'({0})'.format(re.escape(cuda_type))
685685
else:
686-
pattern = r'(\b{0}\b)'.format(cuda_type)
686+
pattern = r'(\b{0}\b)'.format(re.escape(cuda_type))
687687
output_source = re.sub(pattern, hip_type, output_source)
688688

689689
# Perform Kernel Launch Replacements
@@ -706,7 +706,7 @@ def file_specific_replacement(filepath, search_string, replace_string, strict=Fa
706706
with openf(filepath, "r+") as f:
707707
contents = f.read()
708708
if strict:
709-
contents = re.sub(r'\b({0})\b'.format(search_string), lambda x: replace_string, contents)
709+
contents = re.sub(r'\b({0})\b'.format(re.escape(search_string)), lambda x: replace_string, contents)
710710
else:
711711
contents = contents.replace(search_string, replace_string)
712712
f.seek(0)
@@ -824,7 +824,7 @@ def disable_unsupported_function_call(function, input_string, replacement):
824824
output_string = input_string
825825

826826
# Find all calls to the function
827-
calls = re.finditer(r"\b{0}\b".format(function), input_string)
827+
calls = re.finditer(r"\b{0}\b".format(re.escape(function)), input_string)
828828

829829
# Do replacements
830830
for call in calls:
@@ -983,7 +983,7 @@ def replace_arg(match):
983983
if "THCUNN" in filepath.split("/") and "generic" not in filepath.split("/"):
984984
kernel_name_with_template = kernel_name_with_template.replace("<real>", "<Dtype>")
985985

986-
full_new_kernel_launch = re.sub(r'\b{0}\b'.format(original_kernel_name_with_template),
986+
full_new_kernel_launch = re.sub(r'\b{0}\b'.format(re.escape(original_kernel_name_with_template)),
987987
lambda x: kernel_name_with_template, full_new_kernel_launch)
988988

989989
# Replace Launch
@@ -1181,7 +1181,7 @@ def main():
11811181

11821182
# Disable Constants w\ Boundary.
11831183
for const in constants:
1184-
txt = re.sub(r"\b{0}\b".format(const), constants[const], txt)
1184+
txt = re.sub(r"\b{0}\b".format(re.escape(const)), constants[const], txt)
11851185

11861186
# Disable Constants
11871187
for s_const in s_constants:

0 commit comments

Comments
 (0)