Skip to content

Commit 0624efc

Browse files
committed
Fix return of pointer to local variable. TypeRange is not-owning and should not be used to return memory allocated inside a function/on the stack.
Signed-off-by: Rickert, Jonas <[email protected]>
1 parent 5d2f70f commit 0624efc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Dialect/ONNX/DialectBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,13 @@ TensorType OnnxBuilder::toTensor(Type input) const {
555555
return RankedTensorType::get(aTy.getShape(), elementTy);
556556
}
557557

558-
TypeRange OnnxBuilder::toTensors(TypeRange inputs) const {
558+
llvm::SmallVector<Type> OnnxBuilder::toTensors(TypeRange inputs) const {
559559
if (llvm::all_of(inputs, [](Type t) { return (mlir::isa<TensorType>(t)); }))
560560
return inputs;
561561
assert(llvm::all_of(inputs, [](Type t) {
562562
return (mlir::isa<MemRefType>(t));
563563
}) && "All inputs expect RankedMemref type when not a TensorType");
564-
llvm::SmallVector<Type, 4> resultTypes;
564+
llvm::SmallVector<Type> resultTypes;
565565
for (uint64_t i = 0; i < inputs.size(); ++i) {
566566
ShapedType aTy = mlir::cast<ShapedType>(inputs[i]);
567567
Type elementTy = aTy.getElementType();

src/Dialect/ONNX/DialectBuilder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ struct OnnxBuilder : DialectBuilder {
232232
// Convert a Type to TensorType if it is of MemRefType.
233233
mlir::TensorType toTensor(mlir::Type input) const;
234234
// Convert Type to TypeRange of TensorType if it is of MemRefType.
235-
mlir::TypeRange toTensors(mlir::TypeRange inputs) const;
235+
llvm::SmallVector<mlir::Type> toTensors(mlir::TypeRange inputs) const;
236236
// Convert a Value to MemrefType if it is of TensorType.
237237
mlir::Value toMemref(mlir::Value input) const;
238238

0 commit comments

Comments
 (0)