Skip to content

Commit 2f281fc

Browse files
HerrCai0907smeenai
authored andcommitted
[CIR] fix deref nullptr when verify symbol for cir.get_global (#1143)
1 parent 7a3ee3f commit 2f281fc

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
@@ -1103,6 +1103,15 @@ module {
11031103

11041104
// -----
11051105

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

0 commit comments

Comments
 (0)