[clang] 6d95d08 - [CIR] Propagate type conversion failures in DirectToLLVM (#224237)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 20 14:50:56 PDT 2026
Author: Akimasa Watanuki
Date: 2026-10-20T16:50:48-05:00
New Revision: 6d95d08def2b1a929b65fa5fac17ddee26822f72
URL: https://github.com/llvm/llvm-project/commit/6d95d08def2b1a929b65fa5fac17ddee26822f72
DIFF: https://github.com/llvm/llvm-project/commit/6d95d08def2b1a929b65fa5fac17ddee26822f72.diff
LOG: [CIR] Propagate type conversion failures in DirectToLLVM (#224237)
Propagate failed type and constant conversions through DirectToLLVM so
unsupported types produce legalization failures instead of invalid LLVM
operations or a void function result.
Assisted-by: Codex / GPT-6
Added:
clang/test/CIR/Lowering/unsupported-type-conversions.cir
Modified:
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
Removed:
################################################################################
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ac005a4e838d1..541d4de60a337 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -29,6 +29,7 @@
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinDialect.h"
#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/Location.h"
#include "mlir/IR/Types.h"
#include "mlir/Pass/Pass.h"
@@ -81,6 +82,11 @@ mlir::Type elementTypeIfVectorOrMatrix(mlir::Type type) {
}
} // namespace
+static mlir::InFlightDiagnostic emitTypeConversionError(mlir::Operation *op,
+ mlir::Type type) {
+ return op->emitError() << "ClangIR lowering NYI: cannot convert " << type;
+}
+
/// Alignment to use for a memory access whose op carries no explicit alignment.
/// For _BitInt the storage integer iM's ABI alignment (e.g. i128's 16)
/// over-aligns the value, so use the CIR _BitInt ABI alignment (e.g. 8).
@@ -483,6 +489,7 @@ class CIRAttrToValue {
struct LoweredGlobalSymbol {
mlir::Value addr;
mlir::Type sourceType;
+ mlir::Type originalType;
unsigned addrSpace;
};
@@ -508,10 +515,7 @@ mlir::Value lowerCirAttrAsValue(mlir::Operation *parentOp,
LLVMBlockAddressInfo *blockInfoAddr) {
CIRAttrToValue valueConverter(parentOp, rewriter, symbolTables, converter,
blockInfoAddr);
- mlir::Value value = valueConverter.visit(attr);
- if (!value)
- llvm_unreachable("unhandled attribute type");
- return value;
+ return valueConverter.visit(attr);
}
static mlir::LLVM::ModRefInfo convertModRefInfo(cir::ModRefInfo info) {
@@ -950,11 +954,16 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
auto prefix = cir::ConstArrayAttr::get(
cir::ArrayType::get(arrayTy.getElementType(), arrayAttr.size()),
arrayAttr);
- return mlir::LLVM::InsertValueOp::create(rewriter, loc, result,
- visit(prefix), int64_t{0});
+ mlir::Value init = visit(prefix);
+ if (!init)
+ return {};
+ return mlir::LLVM::InsertValueOp::create(rewriter, loc, result, init,
+ int64_t{0});
}
for (auto [idx, elt] : llvm::enumerate(arrayAttr)) {
mlir::Value init = visit(elt);
+ if (!init)
+ return {};
result =
mlir::LLVM::InsertValueOp::create(rewriter, loc, result, init, idx);
}
@@ -999,8 +1008,11 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstRecordAttr constRecord) {
++paddingItr;
}
- result = mlir::LLVM::InsertValueOp::create(rewriter, loc, result,
- visit(elt), insertIdx);
+ mlir::Value init = visit(elt);
+ if (!init)
+ return {};
+ result = mlir::LLVM::InsertValueOp::create(rewriter, loc, result, init,
+ insertIdx);
++insertIdx;
}
@@ -1043,6 +1055,7 @@ CIRAttrToValue::getAddressOfSymbol(mlir::FlatSymbolRefAttr symbol) {
cir::CIRDataLayout cirDataLayout(moduleOp);
const mlir::DataLayout &dataLayout = cirDataLayout.layout;
mlir::Type sourceType;
+ mlir::Type originalType;
unsigned addrSpace = 0;
llvm::StringRef symName;
mlir::Operation *sourceSymbol = symbolTables.lookupSymbolIn(moduleOp, symbol);
@@ -1051,8 +1064,8 @@ CIRAttrToValue::getAddressOfSymbol(mlir::FlatSymbolRefAttr symbol) {
symName = llvmSymbol.getSymName();
addrSpace = llvmSymbol.getAddrSpace();
} else if (auto cirSymbol = dyn_cast<cir::GlobalOp>(sourceSymbol)) {
- sourceType =
- convertTypeForMemory(*converter, dataLayout, cirSymbol.getSymType());
+ originalType = cirSymbol.getSymType();
+ sourceType = convertTypeForMemory(*converter, dataLayout, originalType);
symName = cirSymbol.getSymName();
if (auto targetAS = mlir::dyn_cast_if_present<cir::TargetAddressSpaceAttr>(
cirSymbol.getAddrSpaceAttr()))
@@ -1062,7 +1075,8 @@ CIRAttrToValue::getAddressOfSymbol(mlir::FlatSymbolRefAttr symbol) {
symName = llvmFun.getSymName();
addrSpace = cirDataLayout.getProgramAddressSpace();
} else if (auto fun = dyn_cast<cir::FuncOp>(sourceSymbol)) {
- sourceType = converter->convertType(fun.getFunctionType());
+ originalType = fun.getFunctionType();
+ sourceType = converter->convertType(originalType);
symName = fun.getSymName();
addrSpace = cirDataLayout.getProgramAddressSpace();
} else if (auto alias = dyn_cast<mlir::LLVM::AliasOp>(sourceSymbol)) {
@@ -1077,7 +1091,7 @@ CIRAttrToValue::getAddressOfSymbol(mlir::FlatSymbolRefAttr symbol) {
rewriter, loc,
mlir::LLVM::LLVMPointerType::get(rewriter.getContext(), addrSpace),
symName);
- return {addr, sourceType, addrSpace};
+ return {addr, sourceType, originalType, addrSpace};
}
mlir::Value CIRAttrToValue::castGlobalAddrToType(mlir::Value addr,
@@ -1132,6 +1146,11 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::GlobalViewAttr globalAttr) {
mlir::Type sourceType = lowered.sourceType;
if (globalAttr.getIndices()) {
+ if (!sourceType) {
+ emitTypeConversionError(parentOp, lowered.originalType)
+ << " for symbol " << globalAttr.getSymbol();
+ return {};
+ }
llvm::SmallVector<mlir::LLVM::GEPArg> indices;
if (mlir::isa<mlir::LLVM::LLVMArrayType, mlir::LLVM::LLVMStructType>(
@@ -1200,6 +1219,8 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::TypeInfoAttr typeInfoAttr) {
for (auto [idx, elt] : llvm::enumerate(typeInfoAttr.getData())) {
mlir::Value init = visit(elt);
+ if (!init)
+ return {};
result =
mlir::LLVM::InsertValueOp::create(rewriter, loc, result, init, idx);
}
@@ -1233,6 +1254,8 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::VTableAttr vtableArr) {
for (auto [idx, elt] : llvm::enumerate(vtableArr.getData())) {
mlir::Value init = visit(elt);
+ if (!init)
+ return {};
result =
mlir::LLVM::InsertValueOp::create(rewriter, loc, result, init, idx);
}
@@ -1895,6 +1918,9 @@ mlir::LogicalResult CIRToLLVMCastOpLowering::matchAndRewrite(
// both individual scalars and entire vectors. This lowering pass handles
// both situations.
+ if (!getTypeConverter()->convertType(castOp.getType()))
+ return emitTypeConversionError(castOp, castOp.getType());
+
switch (castOp.getKind()) {
case cir::CastKind::array_to_ptrdecay: {
const auto ptrTy = mlir::cast<cir::PointerType>(castOp.getType());
@@ -2752,6 +2778,8 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
cir::ConstantOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
mlir::Attribute attr = op.getValue();
+ if (!getTypeConverter()->convertType(op.getType()))
+ return emitTypeConversionError(op, op.getType());
if (mlir::isa<cir::PoisonAttr>(attr)) {
rewriter.replaceOpWithNewOp<mlir::LLVM::PoisonOp>(
@@ -2810,6 +2838,8 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
auto newOp =
lowerCirAttrAsValue(op, op.getValue(), rewriter, symbolTables,
getTypeConverter(), &blockInfoAddr);
+ if (!newOp)
+ return mlir::failure();
rewriter.replaceOp(op, newOp);
return mlir::success();
}
@@ -2828,6 +2858,8 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
} else {
const mlir::Value initVal =
lowerCirAttrAsValue(op, value, rewriter, symbolTables, typeConverter);
+ if (!initVal)
+ return mlir::failure();
rewriter.replaceOp(op, initVal);
return mlir::success();
}
@@ -2836,17 +2868,23 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
auto initVal =
lowerCirAttrAsValue(op, spellOutSplitTrailingZeros(recordAttr),
rewriter, symbolTables, typeConverter);
+ if (!initVal)
+ return mlir::failure();
rewriter.replaceOp(op, initVal);
return mlir::success();
} else if (const auto vecTy = mlir::dyn_cast<cir::VectorType>(op.getType())) {
- rewriter.replaceOp(op,
- lowerCirAttrAsValue(op, op.getValue(), rewriter,
- symbolTables, getTypeConverter()));
+ mlir::Value initVal = lowerCirAttrAsValue(op, op.getValue(), rewriter,
+ symbolTables, getTypeConverter());
+ if (!initVal)
+ return mlir::failure();
+ rewriter.replaceOp(op, initVal);
return mlir::success();
} else if (mlir::isa<cir::RecordType>(op.getType())) {
if (mlir::isa<cir::ZeroAttr, cir::UndefAttr>(attr)) {
mlir::Value initVal =
lowerCirAttrAsValue(op, attr, rewriter, symbolTables, typeConverter);
+ if (!initVal)
+ return mlir::failure();
rewriter.replaceOp(op, initVal);
return mlir::success();
}
@@ -3079,17 +3117,18 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite(
for (const auto &argType : llvm::enumerate(fnType.getInputs())) {
mlir::Type convertedType = typeConverter->convertType(argType.value());
if (!convertedType)
- return mlir::failure();
+ return emitTypeConversionError(op, argType.value());
signatureConversion.addInputs(argType.index(), convertedType);
}
mlir::Type resultType =
getTypeConverter()->convertType(fnType.getReturnType());
+ if (!resultType)
+ return emitTypeConversionError(op, fnType.getReturnType());
// Create the LLVM function operation.
mlir::Type llvmFnTy = mlir::LLVM::LLVMFunctionType::get(
- resultType ? resultType : mlir::LLVM::LLVMVoidType::get(getContext()),
- signatureConversion.getConvertedTypes(),
+ resultType, signatureConversion.getConvertedTypes(),
/*isVarArg=*/fnType.isVarArg());
// If this is an alias, it needs to be lowered to llvm::AliasOp.
@@ -3323,6 +3362,8 @@ CIRToLLVMGlobalOpLowering::matchAndRewriteRegionInitializedGlobal(
CIRAttrToValue valueConverter(op, rewriter, symbolTables, typeConverter,
&blockInfoAddr);
mlir::Value value = valueConverter.visit(init);
+ if (!value)
+ return mlir::failure();
mlir::LLVM::ReturnOp::create(rewriter, loc, value);
return mlir::success();
}
@@ -4321,6 +4362,8 @@ static void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
});
converter.addConversion([&](cir::FuncType type) -> std::optional<mlir::Type> {
auto result = converter.convertType(type.getReturnType());
+ if (!result)
+ return std::nullopt;
llvm::SmallVector<mlir::Type> arguments;
arguments.reserve(type.getNumInputs());
if (converter.convertTypes(type.getInputs(), arguments).failed())
@@ -4813,8 +4856,10 @@ void ConvertCIRToLLVMPass::runOnOperation() {
ops.push_back(module);
cir::collectUnreachable(module, ops);
- if (failed(applyPartialConversion(ops, target, std::move(patterns))))
+ if (failed(applyPartialConversion(ops, target, std::move(patterns)))) {
signalPassFailure();
+ return;
+ }
// Drop the cir.ptr-keyed data-layout entries: they drove pointer-width
// queries up to this point, but the LLVM IR exporter rejects CIR types.
@@ -5209,6 +5254,11 @@ getValueForVTableSymbol(mlir::Operation *op,
eltType = llvmSymbol.getType();
} else if (auto cirSymbol = mlir::dyn_cast<cir::GlobalOp>(symbol)) {
eltType = converter->convertType(cirSymbol.getSymType());
+ if (!eltType) {
+ emitTypeConversionError(op, cirSymbol.getSymType())
+ << " for vtable symbol " << nameAttr;
+ return {};
+ }
} else {
op->emitError() << "unexpected symbol type for " << symbol;
return {};
@@ -5229,7 +5279,7 @@ mlir::LogicalResult CIRToLLVMVTableAddrPointOpLowering::matchAndRewrite(
mlir::Value symAddr = getValueForVTableSymbol(
op, rewriter, symbolTables, converter, op.getNameAttr(), eltType);
if (!symAddr)
- return op.emitError() << "Unable to get value for vtable symbol";
+ return mlir::failure();
offsets = llvm::SmallVector<mlir::LLVM::GEPArg>{
0, op.getAddressPointAttr().getIndex(),
@@ -5287,6 +5337,8 @@ mlir::LogicalResult CIRToLLVMVTTAddrPointOpLowering::matchAndRewrite(
llvmAddr =
getValueForVTableSymbol(op, rewriter, symbolTables, getTypeConverter(),
op.getNameAttr(), eltType);
+ if (!llvmAddr)
+ return mlir::failure();
assert(eltType && "Shouldn't ever be missing an eltType here");
offsets.push_back(0);
offsets.push_back(adaptor.getOffset());
@@ -6076,8 +6128,11 @@ mlir::LogicalResult CIRToLLVMInlineAsmOpLowering::matchAndRewrite(
cir::InlineAsmOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
mlir::Type llResTy;
- if (op.getNumResults())
+ if (op.getNumResults()) {
llResTy = getTypeConverter()->convertType(op.getType(0));
+ if (!llResTy)
+ return emitTypeConversionError(op, op.getType(0));
+ }
cir::AsmFlavor dialect = op.getAsmFlavor();
mlir::LLVM::AsmDialect llDialect = dialect == cir::AsmFlavor::x86_att
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
index b491e616cf972..c71ae0c93f9d4 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
@@ -24,9 +24,10 @@ namespace direct {
struct LLVMBlockAddressInfo;
-/// Convert a CIR attribute to an LLVM attribute. May use the datalayout for
-/// lowering attributes to-be-stored in memory. When the attribute may contain
-/// block address attributes, `blockInfoAddr` is used to resolve them.
+/// Convert a CIR attribute to an LLVM value, or return null on failure.
+/// May use the datalayout for lowering attributes to-be-stored in memory. When
+/// the attribute may contain block address attributes, `blockInfoAddr` is used
+/// to resolve them.
mlir::Value lowerCirAttrAsValue(mlir::Operation *parentOp, mlir::Attribute attr,
mlir::ConversionPatternRewriter &rewriter,
mlir::SymbolTableCollection &symbolTables,
diff --git a/clang/test/CIR/Lowering/unsupported-type-conversions.cir b/clang/test/CIR/Lowering/unsupported-type-conversions.cir
new file mode 100644
index 0000000000000..7740caf51f939
--- /dev/null
+++ b/clang/test/CIR/Lowering/unsupported-type-conversions.cir
@@ -0,0 +1,223 @@
+// RUN: cir-opt %s --split-input-file --cir-to-llvm -verify-diagnostics
+
+// Vector-of-_BitInt conversion is unsupported; propagate its failure to the
+// enclosing operation and diagnose the type that cannot be converted.
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.func'}}
+ cir.func private @function_result() -> !vec
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 32, bitint>>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 32, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.func'}}
+ cir.func private @function_argument(!vec)
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // The initializer requests FuncType conversion before the function lowers.
+ cir.global external @function_view = #cir.global_view<@callee> : !cir.ptr<!cir.void>
+
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.func'}}
+ cir.func private @callee() -> !vec
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ cir.func @constant_result() {
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.const'}}
+ %0 = cir.const #cir.zero : !vec
+ cir.return
+ }
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ cir.func @cast_result() {
+ %0 = cir.const #cir.zero : !cir.vector<4 x !cir.int<s, 7>>
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.cast'}}
+ %1 = cir.cast bitcast %0 : !cir.vector<4 x !cir.int<s, 7>> -> !vec
+ cir.return
+ }
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ cir.func @asm_result() {
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.asm'}}
+ %0 = cir.asm(x86_att, out = [], in = [], in_out = [], {"" "=r"}) -> !vec
+ cir.return
+ }
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+!ptr = !cir.ptr<!cir.void>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // Lower the constant before its target to exercise symbol-type failure.
+ cir.func @constant_global_view() {
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.const'}}
+ %0 = cir.const #cir.global_view<@target, [0 : i32]> : !ptr
+ cir.return
+ }
+
+ cir.global external @target = #cir.zero : !vec
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+!ptr = !cir.ptr<!cir.void>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // Lower the constant before its target to exercise symbol-type failure.
+ cir.func @constant_array_view() {
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.const'}}
+ %0 = cir.const #cir.const_array<[#cir.global_view<@target, [0 : i32]> : !ptr]> : !cir.array<!ptr x 1>
+ cir.return
+ }
+
+ cir.global external @target = #cir.zero : !vec
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+!ptr = !cir.ptr<!cir.void>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // Lower the constant before its target to exercise symbol-type failure.
+ cir.func @constant_record_view() {
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.const'}}
+ %0 = cir.const #cir.const_record<{#cir.global_view<@target, [0 : i32]> : !ptr}> : !cir.struct<{data !ptr}>
+ cir.return
+ }
+
+ cir.global external @target = #cir.zero : !vec
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+!ptr = !cir.ptr<!cir.void>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // Propagate initializer failure before lowering the referenced global.
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.global'}}
+ cir.global external @global_view = #cir.global_view<@target, [0 : i32]> : !ptr
+
+ cir.global external @target = #cir.zero : !vec
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+!ptr = !cir.ptr<!cir.void>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // Conversion failure rolls back the unresolved block address. Stop before
+ // attempting to resolve it against a label that has not been lowered.
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.global'}}
+ cir.global external @block_address_view = #cir.const_array<[#cir.block_addr_info<@f, "L"> : !ptr, #cir.global_view<@target, [0 : i32]> : !ptr]> : !cir.array<!ptr x 2>
+
+ cir.func @f() {
+ cir.br ^bb1
+ ^bb1:
+ cir.label "L"
+ cir.return
+ }
+
+ cir.global external @target = #cir.zero : !vec
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+!ptr = !cir.ptr<!cir.void>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // Propagate initializer failure before lowering the referenced global.
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.global'}}
+ cir.global external @typeinfo_view = #cir.typeinfo<{#cir.global_view<@target, [0 : i32]> : !ptr}> : !cir.struct<{data !ptr}>
+
+ cir.global external @target = #cir.zero : !vec
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+!ptr = !cir.ptr<!cir.void>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // Propagate initializer failure before lowering the referenced global.
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.vector<4 x !cir.int<s, 7, bitint>>'}}
+ // expected-error @below {{failed to legalize operation 'cir.global'}}
+ cir.global external @vtable_view = #cir.vtable<{#cir.const_array<[#cir.global_view<@target, [0 : i32]> : !ptr]> : !cir.array<!ptr x 1>}> : !cir.struct<{data !cir.array<!ptr x 1>}>
+
+ cir.global external @target = #cir.zero : !vec
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // The address point requests the symbol type before the global lowers.
+ cir.func @vtable_symbol() {
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.struct<{data !cir.array<!cir.vector<4 x !cir.int<s, 7, bitint>> x 1>}>' for vtable symbol @target}}
+ // expected-error @below {{failed to legalize operation 'cir.vtable.address_point'}}
+ %0 = cir.vtable.address_point(@target, address_point = <index = 0, offset = 0>) : !cir.vptr
+ cir.return
+ }
+
+ cir.global "private" external @target : !cir.struct<{data !cir.array<!vec x 1>}>
+}
+
+// -----
+
+!vec = !cir.vector<4 x !cir.int<s, 7, bitint>>
+!ptr = !cir.ptr<!cir.void>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+ // The address point requests the symbol type before the global lowers.
+ cir.func @vtt_symbol() {
+ // expected-error @below {{ClangIR lowering NYI: cannot convert '!cir.array<!cir.vector<4 x !cir.int<s, 7, bitint>> x 1>' for vtable symbol @target}}
+ // expected-error @below {{failed to legalize operation 'cir.vtt.address_point'}}
+ %0 = cir.vtt.address_point @target, offset = 0 -> !cir.ptr<!ptr>
+ cir.return
+ }
+
+ cir.global "private" external @target : !cir.array<!vec x 1>
+}
More information about the cfe-commits
mailing list