[clang] [CIR] [Upstream local initialization for ArrayType (PR #132974)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 26 15:07:42 PDT 2025
================
@@ -0,0 +1,150 @@
+//====- LoweringHelpers.cpp - Lowering helper functions -------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains helper functions for lowering from CIR to LLVM or MLIR.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/CIR/LoweringHelpers.h"
+
+mlir::DenseElementsAttr
+convertStringAttrToDenseElementsAttr(cir::ConstArrayAttr attr,
+ mlir::Type type) {
+ auto values = llvm::SmallVector<mlir::APInt, 8>{};
+ const auto stringAttr = mlir::dyn_cast<mlir::StringAttr>(attr.getElts());
+ assert(stringAttr && "expected string attribute here");
+
+ for (auto element : stringAttr)
+ values.push_back({8, (uint64_t)element});
+
+ const auto arrayTy = mlir::dyn_cast<cir::ArrayType>(attr.getType());
+ assert(arrayTy && "String attribute must have an array type");
+ if (arrayTy.getSize() != stringAttr.size())
+ llvm_unreachable("array type of the length not equal to that of the string "
----------------
andykaylor wrote:
I'm not suggesting `errorNYI`. I'm suggesting `op.emitError()`. We can't do that here either, but maybe we could do it in the function from which this is called?
https://github.com/llvm/llvm-project/pull/132974
More information about the cfe-commits
mailing list