diff --git a/paddle/fluid/pybind/pir.cc b/paddle/fluid/pybind/pir.cc index 8aa14748aee2f..c4c9eb0145aa5 100644 --- a/paddle/fluid/pybind/pir.cc +++ b/paddle/fluid/pybind/pir.cc @@ -1538,11 +1538,12 @@ static bool HasDynamicShape(const Program &program) { continue; } for (uint32_t i = 0; i < op.num_results(); ++i) { - if (op.result(i) && op.result(i) - .type() - .dyn_cast() - .IsDynamicShape()) { - return true; + if (op.result(i) && op.result(i).type()) { + auto shape_type = + op.result(i).type().dyn_cast(); + if (shape_type && shape_type.IsDynamicShape()) { + return true; + } } } }