[Bugfix] Add nullptr checking for AttrStmt
with coproc_uop_scope
attr key
#9123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug Description
I found there will be a segfault if we try to pass other types of parameters(except String) to
tir.AttrStmt
whenattr_key
is equal tocoproc_uop_scope
.Here is the code to trigger the segmentation fault error:
Bug Analysis
The bug located in src/target/llvm/codegen_cpu.cc. It assumes the value is a valid pointer after casting, but actually, it can be invalid. And we can find this function will check whether the value is a valid pointer for other
attr_key
, such astir::attr::pragma_import_llvm
. So to prevent this crash happen, I add a check after casting thevalue
toStringImmNode
to verify its validity.