https://github.com/NotLebedev created https://github.com/llvm/llvm-project/pull/188742
Closes #187699 . Fix incorrect parsing of `ConstArrayAttr`. `parse` method incorrectly used type of `elts` parameter as type of the whole array. This means that when reading back text or bytecode clangir files attribute did not have correct type and correct `trailingZerosNum`. Type was always of inner `elts`, meaning smaller then actual type if any trailing zeros were present and `trailingZerosNum` was always zero. >From 28693c901fa031f987088bf06d23d52f563ca6a0 Mon Sep 17 00:00:00 2001 From: NotLebedev <[email protected]> Date: Thu, 26 Mar 2026 16:20:32 +0300 Subject: [PATCH] [CIR] Fix incorrect ConstArrayAttr trailing_zeros parsing --- clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp index d608038dafc5f..27cba6a20b445 100644 --- a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp @@ -616,13 +616,12 @@ Attribute ConstArrayAttr::parse(AsmParser &parser, Type type) { unsigned zeros = 0; if (parser.parseOptionalComma().succeeded()) { if (parser.parseOptionalKeyword("trailing_zeros").succeeded()) { - unsigned typeSize = - mlir::cast<cir::ArrayType>(resultTy.value()).getSize(); + unsigned totalSize = mlir::cast<cir::ArrayType>(type).getSize(); mlir::Attribute elts = resultVal.value(); if (auto str = mlir::dyn_cast<mlir::StringAttr>(elts)) - zeros = typeSize - str.size(); + zeros = totalSize - str.size(); else - zeros = typeSize - mlir::cast<mlir::ArrayAttr>(elts).size(); + zeros = totalSize - mlir::cast<mlir::ArrayAttr>(elts).size(); } else { return {}; } @@ -632,9 +631,9 @@ Attribute ConstArrayAttr::parse(AsmParser &parser, Type type) { if (parser.parseGreater()) return {}; - return parser.getChecked<ConstArrayAttr>( - parser.getCurrentLocation(), parser.getContext(), resultTy.value(), - resultVal.value(), zeros); + return parser.getChecked<ConstArrayAttr>(parser.getCurrentLocation(), + parser.getContext(), type, + resultVal.value(), zeros); } void ConstArrayAttr::print(AsmPrinter &printer) const { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
