llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Henrich Lauko (xlauko) <details> <summary>Changes</summary> Mirrors incubator changes from https://github.com/llvm/clangir/pull/1634 --- Full diff: https://github.com/llvm/llvm-project/pull/141032.diff 2 Files Affected: - (modified) clang/lib/CIR/Dialect/IR/CIRAttrs.cpp (+19-28) - (modified) clang/lib/CIR/Dialect/IR/CIRTypes.cpp (+10-14) ``````````diff diff --git a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp index 6f41cd4388ac2..c4fb4942aec75 100644 --- a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp @@ -138,17 +138,13 @@ void IntAttr::print(AsmPrinter &printer) const { LogicalResult IntAttr::verify(function_ref<InFlightDiagnostic()> emitError, Type type, APInt value) { - if (!mlir::isa<IntType>(type)) { - emitError() << "expected 'simple.int' type"; - return failure(); - } + if (!mlir::isa<IntType>(type)) + return emitError() << "expected 'simple.int' type"; auto intType = mlir::cast<IntType>(type); - if (value.getBitWidth() != intType.getWidth()) { - emitError() << "type and value bitwidth mismatch: " << intType.getWidth() - << " != " << value.getBitWidth(); - return failure(); - } + if (value.getBitWidth() != intType.getWidth()) + return emitError() << "type and value bitwidth mismatch: " + << intType.getWidth() << " != " << value.getBitWidth(); return success(); } @@ -182,10 +178,8 @@ FPAttr FPAttr::getZero(Type type) { LogicalResult FPAttr::verify(function_ref<InFlightDiagnostic()> emitError, CIRFPTypeInterface fpType, APFloat value) { if (APFloat::SemanticsToEnum(fpType.getFloatSemantics()) != - APFloat::SemanticsToEnum(value.getSemantics())) { - emitError() << "floating-point semantics mismatch"; - return failure(); - } + APFloat::SemanticsToEnum(value.getSemantics())) + return emitError() << "floating-point semantics mismatch"; return success(); } @@ -195,10 +189,10 @@ LogicalResult FPAttr::verify(function_ref<InFlightDiagnostic()> emitError, //===----------------------------------------------------------------------===// LogicalResult -ConstArrayAttr::verify(function_ref<::mlir::InFlightDiagnostic()> emitError, - Type type, Attribute elts, int trailingZerosNum) { +ConstArrayAttr::verify(function_ref<InFlightDiagnostic()> emitError, Type type, + Attribute elts, int trailingZerosNum) { - if (!(mlir::isa<ArrayAttr>(elts) || mlir::isa<StringAttr>(elts))) + if (!(mlir::isa<ArrayAttr, StringAttr>(elts))) return emitError() << "constant array expects ArrayAttr or StringAttr"; if (auto strAttr = mlir::dyn_cast<StringAttr>(elts)) { @@ -206,11 +200,10 @@ ConstArrayAttr::verify(function_ref<::mlir::InFlightDiagnostic()> emitError, const auto intTy = mlir::dyn_cast<IntType>(arrayTy.getElementType()); // TODO: add CIR type for char. - if (!intTy || intTy.getWidth() != 8) { - emitError() << "constant array element for string literals expects " - "!cir.int<u, 8> element type"; - return failure(); - } + if (!intTy || intTy.getWidth() != 8) + return emitError() + << "constant array element for string literals expects " + "!cir.int<u, 8> element type"; return success(); } @@ -303,22 +296,20 @@ void ConstArrayAttr::print(AsmPrinter &printer) const { // CIR ConstVectorAttr //===----------------------------------------------------------------------===// -LogicalResult cir::ConstVectorAttr::verify( - function_ref<::mlir::InFlightDiagnostic()> emitError, Type type, - ArrayAttr elts) { +LogicalResult +cir::ConstVectorAttr::verify(function_ref<InFlightDiagnostic()> emitError, + Type type, ArrayAttr elts) { - if (!mlir::isa<cir::VectorType>(type)) { + if (!mlir::isa<cir::VectorType>(type)) return emitError() << "type of cir::ConstVectorAttr is not a " "cir::VectorType: " << type; - } const auto vecType = mlir::cast<cir::VectorType>(type); - if (vecType.getSize() != elts.size()) { + if (vecType.getSize() != elts.size()) return emitError() << "number of constant elements should match vector size"; - } // Check if the types of the elements match LogicalResult elementTypeCheck = success(); diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp index 9a44f923ac143..fa8180c890506 100644 --- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp @@ -13,6 +13,7 @@ #include "clang/CIR/Dialect/IR/CIRTypes.h" #include "mlir/IR/DialectImplementation.h" +#include "mlir/Support/LLVM.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/IR/CIRTypesDetails.h" #include "clang/CIR/MissingFeatures.h" @@ -205,10 +206,8 @@ RecordType::verify(function_ref<mlir::InFlightDiagnostic()> emitError, llvm::ArrayRef<mlir::Type> members, mlir::StringAttr name, bool incomplete, bool packed, bool padded, RecordType::RecordKind kind) { - if (name && name.getValue().empty()) { - emitError() << "identified records cannot have an empty name"; - return mlir::failure(); - } + if (name && name.getValue().empty()) + return emitError() << "identified records cannot have an empty name"; return mlir::success(); } @@ -421,12 +420,10 @@ uint64_t IntType::getABIAlignment(const mlir::DataLayout &dataLayout, mlir::LogicalResult IntType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError, unsigned width, bool isSigned) { - if (width < IntType::minBitwidth() || width > IntType::maxBitwidth()) { - emitError() << "IntType only supports widths from " - << IntType::minBitwidth() << " up to " - << IntType::maxBitwidth(); - return mlir::failure(); - } + if (width < IntType::minBitwidth() || width > IntType::maxBitwidth()) + return emitError() << "IntType only supports widths from " + << IntType::minBitwidth() << " up to " + << IntType::maxBitwidth(); return mlir::success(); } @@ -631,10 +628,9 @@ mlir::LogicalResult FuncType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError, llvm::ArrayRef<mlir::Type> argTypes, mlir::Type returnType, bool isVarArg) { - if (returnType && mlir::isa<cir::VoidType>(returnType)) { - emitError() << "!cir.func cannot have an explicit 'void' return type"; - return mlir::failure(); - } + if (mlir::isa_and_nonnull<cir::VoidType>(returnType)) + return emitError() + << "!cir.func cannot have an explicit 'void' return type"; return mlir::success(); } `````````` </details> https://github.com/llvm/llvm-project/pull/141032 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits