[Mlir-commits] [mlir] [mlir][LLVM] Verify too many indices in GEP verifier (PR #70174)
Tobias Gysi
llvmlistbot at llvm.org
Wed Oct 25 01:28:11 PDT 2023
Markus =?utf-8?q?Böck?= <markus.boeck02 at gmail.com>
Message-ID:
In-Reply-To: <llvm/llvm-project/pull/70174/mlir at github.com>
================
@@ -664,90 +664,51 @@ static void printGEPIndices(OpAsmPrinter &printer, LLVM::GEPOp gepOp,
});
}
-namespace {
-/// Base class for llvm::Error related to GEP index.
-class GEPIndexError : public llvm::ErrorInfo<GEPIndexError> {
-protected:
- unsigned indexPos;
-
-public:
- static char ID;
-
- std::error_code convertToErrorCode() const override {
- return llvm::inconvertibleErrorCode();
- }
-
- explicit GEPIndexError(unsigned pos) : indexPos(pos) {}
-};
-
-/// llvm::Error for out-of-bound GEP index.
-struct GEPIndexOutOfBoundError
- : public llvm::ErrorInfo<GEPIndexOutOfBoundError, GEPIndexError> {
- static char ID;
-
- using ErrorInfo::ErrorInfo;
-
- void log(llvm::raw_ostream &os) const override {
- os << "index " << indexPos << " indexing a struct is out of bounds";
- }
-};
-
-/// llvm::Error for non-static GEP index indexing a struct.
-struct GEPStaticIndexError
- : public llvm::ErrorInfo<GEPStaticIndexError, GEPIndexError> {
- static char ID;
-
- using ErrorInfo::ErrorInfo;
-
- void log(llvm::raw_ostream &os) const override {
- os << "expected index " << indexPos << " indexing a struct "
- << "to be constant";
- }
-};
-} // end anonymous namespace
-
-char GEPIndexError::ID = 0;
-char GEPIndexOutOfBoundError::ID = 0;
-char GEPStaticIndexError::ID = 0;
-
-/// For the given `structIndices` and `indices`, check if they're complied
-/// with `baseGEPType`, especially check against LLVMStructTypes nested within.
-static llvm::Error verifyStructIndices(Type baseGEPType, unsigned indexPos,
- GEPIndicesAdaptor<ValueRange> indices) {
+/// For the given `indices`, check if they comply with `baseGEPType`,
+// especially check against LLVMStructTypes nested within.
+static LogicalResult
+verifyStructIndices(Type baseGEPType, unsigned indexPos,
+ GEPIndicesAdaptor<ValueRange> indices,
+ function_ref<InFlightDiagnostic()> emitOpError) {
if (indexPos >= indices.size())
// Stop searching
- return llvm::Error::success();
+ return success();
- return llvm::TypeSwitch<Type, llvm::Error>(baseGEPType)
- .Case<LLVMStructType>([&](LLVMStructType structType) -> llvm::Error {
+ return llvm::TypeSwitch<Type, LogicalResult>(baseGEPType)
----------------
gysit wrote:
```suggestion
return TypeSwitch<Type, LogicalResult>(baseGEPType)
```
I believe the namespace is not needed here.
https://github.com/llvm/llvm-project/pull/70174
More information about the Mlir-commits
mailing list