diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index 214553b66e83..6f1db25903c5 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -2019,8 +2019,8 @@ LogicalResult cir::GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) { // Verify that the result type underlying pointer type matches the type of // the referenced cir.global or cir.func op. - auto op = symbolTable.lookupNearestSymbolFrom(*this, getNameAttr()); - if (!(isa(op) || isa(op))) + auto *op = symbolTable.lookupNearestSymbolFrom(*this, getNameAttr()); + if (op == nullptr || !(isa(op) || isa(op))) return emitOpError("'") << getName() << "' does not reference a valid cir.global or cir.func"; diff --git a/clang/test/CIR/IR/invalid.cir b/clang/test/CIR/IR/invalid.cir index af516b2aaed6..01828fbe22b4 100644 --- a/clang/test/CIR/IR/invalid.cir +++ b/clang/test/CIR/IR/invalid.cir @@ -1103,6 +1103,15 @@ module { // ----- +!s8i = !cir.int +cir.func @no_reference_global() { + // expected-error @below {{'cir.get_global' op 'str' does not reference a valid cir.global or cir.func}} + %0 = cir.get_global @str : !cir.ptr + cir.return +} + +// ----- + // expected-error@+1 {{invalid underlying type for long double}} cir.func @bad_long_double(%arg0 : !cir.long_double) -> () { cir.return