mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
avoid to declare an unknown bound array without any element (#156543)
Fixes #153180 Pull Request resolved: https://github.com/pytorch/pytorch/pull/156543 Approved by: https://github.com/jansel Co-authored-by: Xu Han <xu.han@outlook.com>
This commit is contained in:
committed by
PyTorch MergeBot
parent
4237ee3c33
commit
c60327ba74
@ -1503,12 +1503,19 @@ class CppWrapperCpu(PythonWrapperCodegen):
|
||||
# This is why writeline needs to explicitly passed in as a parameter.
|
||||
var = f"int_array_{next(self.int_array_id)}"
|
||||
ctype = "int64_t"
|
||||
if var not in self.declared_int_array_vars:
|
||||
self.declared_int_array_vars.add(var)
|
||||
if int_array == "{}":
|
||||
# An array of unknown bound cannot be initialized with {}.
|
||||
if known_statically:
|
||||
writeline(f"static constexpr {ctype} {var}[] = {int_array};")
|
||||
writeline(f"static constexpr {ctype} *{var}=nullptr;")
|
||||
else:
|
||||
writeline(f"const {ctype} {var}[] = {int_array};")
|
||||
writeline(f"const {ctype} *{var}=nullptr;")
|
||||
else:
|
||||
if var not in self.declared_int_array_vars:
|
||||
self.declared_int_array_vars.add(var)
|
||||
if known_statically:
|
||||
writeline(f"static constexpr {ctype} {var}[] = {int_array};")
|
||||
else:
|
||||
writeline(f"const {ctype} {var}[] = {int_array};")
|
||||
return var
|
||||
|
||||
def make_buffer_allocation(self, buffer):
|
||||
|
Reference in New Issue
Block a user