Skip to content

Commit 736dfd6

Browse files
HerrCai0907lanza
authored andcommitted
[CIR] fix deref nullptr when verify symbol for cir.get_global (#1143)
1 parent d7d993c commit 736dfd6

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2023,8 +2023,8 @@ LogicalResult
20232023
cir::GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
20242024
// Verify that the result type underlying pointer type matches the type of
20252025
// the referenced cir.global or cir.func op.
2026-
auto op = symbolTable.lookupNearestSymbolFrom(*this, getNameAttr());
2027-
if (!(isa<GlobalOp>(op) || isa<FuncOp>(op)))
2026+
auto *op = symbolTable.lookupNearestSymbolFrom(*this, getNameAttr());
2027+
if (op == nullptr || !(isa<GlobalOp>(op) || isa<FuncOp>(op)))
20282028
return emitOpError("'")
20292029
<< getName()
20302030
<< "' does not reference a valid cir.global or cir.func";

clang/test/CIR/IR/invalid.cir

+9
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,15 @@ module {
11041104

11051105
// -----
11061106

1107+
!s8i = !cir.int<s, 8>
1108+
cir.func @no_reference_global() {
1109+
// expected-error @below {{'cir.get_global' op 'str' does not reference a valid cir.global or cir.func}}
1110+
%0 = cir.get_global @str : !cir.ptr<!s8i>
1111+
cir.return
1112+
}
1113+
1114+
// -----
1115+
11071116
// expected-error@+1 {{invalid underlying type for long double}}
11081117
cir.func @bad_long_double(%arg0 : !cir.long_double<!cir.float>) -> () {
11091118
cir.return

0 commit comments

Comments
 (0)