diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index f8c34552eca11..cd94219655e02 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -2076,6 +2076,11 @@ static void printConstant(OpAsmPrinter &p, Attribute value) { } mlir::LogicalResult cir::GlobalOp::verify() { + // A function is not an object, so it cannot be the type of a global. A + // global that holds a function's address carries a pointer type instead. + if (mlir::isa(getSymType())) + return emitOpError("global type cannot be a function type"); + // Verify that the initial value, if present, is either a unit attribute or // an attribute CIR supports. if (getInitialValue().has_value()) { diff --git a/clang/test/CIR/IR/invalid-global.cir b/clang/test/CIR/IR/invalid-global.cir index d0a2f0d116c7f..12acc2e6333c8 100644 --- a/clang/test/CIR/IR/invalid-global.cir +++ b/clang/test/CIR/IR/invalid-global.cir @@ -40,3 +40,12 @@ cir.global external @bad_alias_with_dtor alias(@target) = #cir.int<7> : !s32i dt } } + +// ----- + +module { + +// expected-error @below {{global type cannot be a function type}} +cir.global "private" external @bad_func_type : !cir.func<()> + +}