https://gcc.gnu.org/g:6756250fcbed4a214c30de94e4ec68ea130528d5

commit r15-4390-g6756250fcbed4a214c30de94e4ec68ea130528d5
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Wed Oct 16 17:46:06 2024 +0200

    c: Add some checking asserts to named loops handling code
    
    Jonathan mentioned an unnamed static analyzer reported issue in
    c_finish_bc_name.
    It is actually a false positive, because the construction of the
    loop_names vector guarantees that the last element of the vector
    (if the vector is non-empty) always has either
    C_DECL_LOOP_NAME (l) or C_DECL_SWITCH_NAME (l) (or both) flags
    set, so c will be always non-NULL after the if at the start of the
    loops.
    The following patch is an attempt to help those static analyzers
    (though dunno if it actually helps), by adding a checking assert.
    
    2024-10-16  Jakub Jelinek  <ja...@redhat.com>
    
            * c-decl.cc (c_get_loop_names): Add checking assert that
            c is non-NULL in the loop.
            (c_finish_bc_name): Likewise.

Diff:
---
 gcc/c/c-decl.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 888966cb7109..1827bbf06465 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -13881,6 +13881,7 @@ c_get_loop_names (tree before_labels, bool switch_p, 
tree *last_p)
            {
              if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
                c = l;
+             gcc_checking_assert (c);
              loop_names_hash->put (l, c);
              if (i == first)
                break;
@@ -13952,6 +13953,7 @@ c_finish_bc_name (location_t loc, tree name, bool 
is_break)
          {
            if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
              c = l;
+           gcc_checking_assert (c);
            if (l == lab)
              {
                label = c;
@@ -13970,6 +13972,7 @@ c_finish_bc_name (location_t loc, tree name, bool 
is_break)
        {
          if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
            c = l;
+         gcc_checking_assert (c);
          if (is_break || C_DECL_LOOP_NAME (c))
            candidates.safe_push (IDENTIFIER_POINTER (DECL_NAME (l)));
        }

Reply via email to