[3/3] ir: make is_at_{class,global}_scope more crash proof

Message ID 87bjbonx9i.fsf@seketeli.org
State New
Headers
Series [1/3] configure: Consider prefixed headers dir when checking decls |

Commit Message

Dodji Seketeli July 30, 2026, 6:32 p.m. UTC
  Hello,

While hacking on something else, I figured the middle-end could use some
crash avoidance care.

	* src/abg-ir.cc (is_at_{class,global}_scope): Add checks to avoid
	crashes here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>

Applied to the master branch.
---
 src/abg-ir.cc | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Patch

diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index d9230404..9f0175d4 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -10603,7 +10603,7 @@  is_at_global_scope(const decl_base_sptr decl)
 /// @return true iff decl is at global scope.
 bool
 is_at_global_scope(const decl_base* decl)
-{return is_at_global_scope(*decl);}
+{return decl && is_at_global_scope(*decl);}
 
 /// Tests whether a given decl is at class scope.
 ///
@@ -10623,7 +10623,7 @@  class_or_union*
 is_at_class_scope(const decl_base* decl)
 {
   if (!decl)
-    return 0;
+    return nullptr;
 
   return is_at_class_scope(*decl);
 }
@@ -10637,6 +10637,9 @@  class_or_union*
 is_at_class_scope(const decl_base& decl)
 {
   scope_decl* scope = decl.get_scope();
+  if (!scope)
+    return nullptr;
+
   if (class_or_union* cl = is_class_type(scope))
     return cl;
   if (class_or_union* cl = is_union_type(scope))