================
@@ -12,28 +12,47 @@
#include "clang/CIR/LoweringHelpers.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
+#include "mlir/IR/SymbolTable.h"
#include "clang/CIR/MissingFeatures.h"
+static unsigned getIntOrBoolBitWidth(mlir::Type ty) {
+ if (auto intTy = mlir::dyn_cast<cir::IntType>(ty))
+ return intTy.getWidth();
+ if (mlir::isa<cir::BoolType>(ty))
+ return 1;
+ llvm_unreachable("expected CIR integer or bool element type");
+}
+
mlir::DenseElementsAttr
convertStringAttrToDenseElementsAttr(cir::ConstArrayAttr attr,
mlir::Type type) {
- auto values = llvm::SmallVector<mlir::APInt, 8>{};
const auto stringAttr = mlir::cast<mlir::StringAttr>(attr.getElts());
+ const auto arrayTy = mlir::cast<cir::ArrayType>(attr.getType());
+ const unsigned totalSize = arrayTy.getSize();
+ const unsigned trailingZeros = attr.getTrailingZerosNum();
+ assert(stringAttr.size() + trailingZeros == totalSize &&
+ "string const_array size must match explicit elements plus "
+ "trailing_zeros");
+
+ const unsigned bitWidth = getIntOrBoolBitWidth(arrayTy.getElementType());
+ llvm::SmallVector<mlir::APInt> values;
+ values.reserve(totalSize);
for (const char element : stringAttr)
- values.push_back({8, (uint64_t)element});
+ values.emplace_back(bitWidth, (uint64_t)(unsigned char)element);
----------------
erichkeane wrote:
Nit: stop using "C" style casts, its against our coding standard.
Second, you shouldn't have to do either cast. `char` converts implicitly to
`uint64_t`. It was required before because it was using push_back.
https://github.com/llvm/llvm-project/pull/198427
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits