Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ def CIR_VectorType : CIR_Type<"Vector", "vector",
let assemblyFormat = [{
`<` $elementType `x` $size `>`
}];

let genVerifyDecl = 1;
}

//===----------------------------------------------------------------------===//
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,23 @@ cir::VectorType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
return llvm::NextPowerOf2(dataLayout.getTypeSizeInBits(*this));
}

mlir::LogicalResult cir::VectorType::verify(
llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
mlir::Type elementType, uint64_t size) {
if (size == 0)
return emitError() << "the number of vector elements must be non-zero";

// Check if it a valid FixedVectorType
if (mlir::isa<cir::PointerType, cir::FP128Type>(elementType))
return success();

// Check if it a valid VectorType
if (mlir::isa<cir::IntType>(elementType) ||
isAnyFloatingPointType(elementType))
return success();

return emitError() << "unsupported element type for CIR vector";
}
// TODO(cir): Implement a way to cache the datalayout info calculated below.

llvm::TypeSize
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CIR/IR/invalid-vector-zero-size.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: cir-opt %s -verify-diagnostics -split-input-file

!s32i = !cir.int<s, 32>

module {

// expected-error @below {{the number of vector elements must be non-zero}}
cir.global external @vec_a = #cir.zero : !cir.vector<!s32i x 0>

}
10 changes: 10 additions & 0 deletions clang/test/CIR/IR/invalid-vector.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: cir-opt %s -verify-diagnostics -split-input-file

!s32i = !cir.int<s, 32>

module {

// expected-error @below {{unsupported element type for CIR vector}}
cir.global external @vec_b = #cir.zero : !cir.vector<!cir.array<!s32i x 10> x 4>

}
Loading