Skip to content

Commit

Permalink
Fix use-after-free detected by address sanitizer (#2914)
Browse files Browse the repository at this point in the history
`DistributedEncodingTrait::getCTAOrder()` returns a SmallVector by
value, which is deleted as soon as it is assigned to `ref`. `ref` then
becomes a dangling reference.

To prevent that, we now use a vector instead of an array reference.
  • Loading branch information
gflegar authored Jan 11, 2024
1 parent e3d809f commit 4dac289
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Dialect/TritonGPU/IR/Dialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,17 @@ SmallVector<unsigned> getCTASplitNum(Attribute layout) {
}

SmallVector<unsigned> getCTAOrder(Attribute layout) {
ArrayRef<unsigned> ref;
SmallVector<unsigned> res;
if (auto distributedLayout = layout.dyn_cast<DistributedEncodingTrait>()) {
ref = distributedLayout.getCTAOrder();
res = distributedLayout.getCTAOrder();
} else if (auto mfmaLayout = layout.dyn_cast<MfmaEncodingAttr>()) {
return {0, 1};
} else if (auto sharedLayout = layout.dyn_cast<SharedEncodingAttr>()) {
ref = sharedLayout.getCTALayout().getCTAOrder();
res = SmallVector<unsigned>(sharedLayout.getCTALayout().getCTAOrder());
} else {
llvm::report_fatal_error("Unimplemented usage of getCTAOrder");
}
return SmallVector<unsigned>(ref.begin(), ref.end());
return res;
}

SmallVector<int64_t> getShapePerCTA(ArrayRef<unsigned> CTASplitNum,
Expand Down

0 comments on commit 4dac289

Please sign in to comment.