https://gcc.gnu.org/g:66fb0687ce6d72e13671c38d4e192588456cc016
commit r13-9564-g66fb0687ce6d72e13671c38d4e192588456cc016
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Fri Oct 25 14:09:42 2024 +0200

    Assorted --disable-checking fixes [PR117249]
    
    We have currently 3 different definitions of gcc_assert macro, one used most
    of the time (unless --disable-checking) which evaluates the condition at
    runtime and also checks it at runtime, then one for --disable-checking GCC 
4.5+
    which looks like
    ((void)(UNLIKELY (!(EXPR)) ? __builtin_unreachable (), 0 : 0))
    and a fallback one
    ((void)(0 && (EXPR)))
    Now, the last one actually doesn't evaluate any of the side-effects in the
    argument, just quiets up unused var/parameter warnings.
    I've tried to replace the middle definition with
    ({ [[assume (EXPR)]]; (void) 0; })
    for compilers which support assume attribute and statement expressions
    (surprisingly quite a few spots use gcc_assert inside of comma expressions),
    but ran into PR117287, so for now such a change isn't being proposed.
    
    The following patch attempts to move important side-effects from gcc_assert
    arguments.
    
    Bootstrapped/regtested on x86_64-linux and i686-linux with normal
    --enable-checking=yes,rtl,extra, plus additionally I've attempted to do
    x86_64-linux bootstrap with --disable-checking and gcc_assert changed to the
    ((void)(0 && (EXPR)))
    version when --disable-checking.  That version ran into spurious middle-end
    warnings
    ../../gcc/../include/libiberty.h:733:36: error: argument to ‘alloca’ is too 
large [-Werror=alloca-larger-than=]
    ../../gcc/tree-ssa-reassoc.cc:5659:20: note: in expansion of macro 
‘XALLOCAVEC’
      int op_num = ops.length ();
      int op_normal_num = op_num;
      gcc_assert (op_num > 0);
      int stmt_num = op_num - 1;
      gimple **stmts = XALLOCAVEC (gimple *, stmt_num);
    where we have gcc_assert exactly to work-around middle-end warnings.
    Guess I'd need to also disable -Werror for this experiment, which actually
    isn't a problem with unmodified system.h, because even for
    --disable-checking we use the __builtin_unreachable at least in
    stage2/stage3 and so the warnings aren't emitted, and even if it used
    [[assume ()]]; it would work too because in stage2/stage3 we could again
    rely on assume and statement expression support.
    
    2024-10-25  Jakub Jelinek  <ja...@redhat.com>
    
            PR middle-end/117249
            * tree-ssa-structalias.cc (insert_vi_for_tree): Move put calls out 
of
            gcc_assert.
            * lto-cgraph.cc (lto_symtab_encoder_delete_node): Likewise.
            * gimple-ssa-strength-reduction.cc (get_alternative_base,
            add_cand_for_stmt): Likewise.
            * tree-eh.cc (add_stmt_to_eh_lp_fn): Likewise.
            * except.cc (duplicate_eh_regions_1): Likewise.
            * tree-ssa-reassoc.cc (insert_operand_rank): Likewise.
            * config/nvptx/nvptx.cc (nvptx_expand_call): Use == rather than = in
            gcc_assert.
            * opts-common.cc (jobserver_info::disconnect): Call close outside of
            gcc_assert and only check result in it.
            (jobserver_info::return_token): Call write outside of gcc_assert and
            only check result in it.
            * genautomata.cc (output_default_latencies): Move j++ side-effect
            outside of gcc_assert.
            * tree-ssa-loop-ivopts.cc (get_alias_ptr_type_for_ptr_address): Use
            == rather than = in gcc_assert.
            * cgraph.cc (symbol_table::create_edge): Move ++edges_max_uid
            side-effect outside of gcc_assert.
    
    (cherry picked from commit e2a8772c9328960c625f5b95091d4312efa0e284)

Diff:
---
 gcc/cgraph.cc                        | 3 ++-
 gcc/config/nvptx/nvptx.cc            | 2 +-
 gcc/except.cc                        | 6 ++++--
 gcc/genautomata.cc                   | 3 ++-
 gcc/gimple-ssa-strength-reduction.cc | 6 ++++--
 gcc/lto-cgraph.cc                    | 3 ++-
 gcc/opts-common.cc                   | 6 ++++--
 gcc/tree-eh.cc                       | 3 ++-
 gcc/tree-ssa-loop-ivopts.cc          | 2 +-
 gcc/tree-ssa-reassoc.cc              | 3 ++-
 gcc/tree-ssa-structalias.cc          | 3 ++-
 11 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index ad71cf82823c..cc21d2a4a903 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -892,7 +892,8 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node 
*callee,
   edge->m_summary_id = -1;
   edges_count++;
 
-  gcc_assert (++edges_max_uid != 0);
+  ++edges_max_uid;
+  gcc_assert (edges_max_uid != 0);
   edge->m_uid = edges_max_uid;
   edge->aux = NULL;
   edge->caller = caller;
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index 89349dae9e62..a1566d3fdf9e 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -1899,7 +1899,7 @@ nvptx_expand_call (rtx retval, rtx address)
   if (varargs)
     XVECEXP (pat, 0, vec_pos++) = gen_rtx_USE (VOIDmode, varargs);
 
-  gcc_assert (vec_pos = XVECLEN (pat, 0));
+  gcc_assert (vec_pos == XVECLEN (pat, 0));
 
   nvptx_emit_forking (parallel, true);
   emit_call_insn (pat);
diff --git a/gcc/except.cc b/gcc/except.cc
index e728aa43b6a2..1e08066b6ce6 100644
--- a/gcc/except.cc
+++ b/gcc/except.cc
@@ -541,7 +541,8 @@ duplicate_eh_regions_1 (struct duplicate_eh_regions_data 
*data,
   eh_region new_r;
 
   new_r = gen_eh_region (old_r->type, outer);
-  gcc_assert (!data->eh_map->put (old_r, new_r));
+  bool existed = data->eh_map->put (old_r, new_r);
+  gcc_assert (!existed);
 
   switch (old_r->type)
     {
@@ -586,7 +587,8 @@ duplicate_eh_regions_1 (struct duplicate_eh_regions_data 
*data,
        continue;
 
       new_lp = gen_eh_landing_pad (new_r);
-      gcc_assert (!data->eh_map->put (old_lp, new_lp));
+      bool existed = data->eh_map->put (old_lp, new_lp);
+      gcc_assert (!existed);
 
       new_lp->post_landing_pad
        = data->label_map (old_lp->post_landing_pad, data->label_map_data);
diff --git a/gcc/genautomata.cc b/gcc/genautomata.cc
index bf2dcdf2967e..1d615cba789d 100644
--- a/gcc/genautomata.cc
+++ b/gcc/genautomata.cc
@@ -8348,7 +8348,8 @@ output_default_latencies (void)
        if ((col = (col+1) % 8) == 0)
          fputs ("\n     ", output_file);
        decl = description->decls[i];
-       gcc_assert (j++ == DECL_INSN_RESERV (decl)->insn_num);
+       gcc_assert (j == DECL_INSN_RESERV (decl)->insn_num);
+       ++j;
        fprintf (output_file, "% 4d,",
                 DECL_INSN_RESERV (decl)->default_latency);
       }
diff --git a/gcc/gimple-ssa-strength-reduction.cc 
b/gcc/gimple-ssa-strength-reduction.cc
index 65d6c06b629a..c938ffe3dd12 100644
--- a/gcc/gimple-ssa-strength-reduction.cc
+++ b/gcc/gimple-ssa-strength-reduction.cc
@@ -473,7 +473,8 @@ get_alternative_base (tree base)
       aff.offset = 0;
       expr = aff_combination_to_tree (&aff);
 
-      gcc_assert (!alt_base_map->put (base, base == expr ? NULL : expr));
+      bool existed = alt_base_map->put (base, base == expr ? NULL : expr);
+      gcc_assert (!existed);
 
       return expr == base ? NULL : expr;
     }
@@ -791,7 +792,8 @@ base_cand_from_table (tree base_in)
 static void
 add_cand_for_stmt (gimple *gs, slsr_cand_t c)
 {
-  gcc_assert (!stmt_cand_map->put (gs, c));
+  bool existed = stmt_cand_map->put (gs, c);
+  gcc_assert (!existed);
 }
 
 /* Given PHI which contains a phi statement, determine whether it
diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index aed5e9ddb188..e0bd95109921 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -154,7 +154,8 @@ lto_symtab_encoder_delete_node (lto_symtab_encoder_t 
encoder,
   last_node = encoder->nodes.pop ();
   if (last_node.node != node)
     {
-      gcc_assert (encoder->map->put (last_node.node, index + 1));
+      bool existed = encoder->map->put (last_node.node, index + 1);
+      gcc_assert (existed);
 
       /* Move the last element to the original spot of NODE.  */
       encoder->nodes[index] = last_node;
diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc
index 0684b2356753..c4a5cb77f7ca 100644
--- a/gcc/opts-common.cc
+++ b/gcc/opts-common.cc
@@ -2109,7 +2109,8 @@ jobserver_info::disconnect ()
 {
   if (!pipe_path.empty ())
     {
-      gcc_assert (close (pipefd) == 0);
+      int res = close (pipefd);
+      gcc_assert (res == 0);
       pipefd = -1;
     }
 }
@@ -2134,5 +2135,6 @@ jobserver_info::return_token ()
 {
   int fd = pipe_path.empty () ? wfd : pipefd;
   char c = 'G';
-  gcc_assert (write (fd, &c, 1) == 1);
+  int res = write (fd, &c, 1);
+  gcc_assert (res == 1);
 }
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 550c1c61c354..abd2efafe5af 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -76,7 +76,8 @@ add_stmt_to_eh_lp_fn (struct function *ifun, gimple *t, int 
num)
   if (!get_eh_throw_stmt_table (ifun))
     set_eh_throw_stmt_table (ifun, hash_map<gimple *, int>::create_ggc (31));
 
-  gcc_assert (!get_eh_throw_stmt_table (ifun)->put (t, num));
+  bool existed = get_eh_throw_stmt_table (ifun)->put (t, num);
+  gcc_assert (!existed);
 }
 
 /* Add statement T in the current function (cfun) to EH landing pad NUM.  */
diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc
index 99806ad1caed..78d0f6544d8a 100644
--- a/gcc/tree-ssa-loop-ivopts.cc
+++ b/gcc/tree-ssa-loop-ivopts.cc
@@ -7557,7 +7557,7 @@ get_alias_ptr_type_for_ptr_address (iv_use *use)
     case IFN_LEN_LOAD:
     case IFN_LEN_STORE:
       /* The second argument contains the correct alias type.  */
-      gcc_assert (use->op_p = gimple_call_arg_ptr (call, 0));
+      gcc_assert (use->op_p == gimple_call_arg_ptr (call, 0));
       return TREE_TYPE (gimple_call_arg (call, 1));
 
     default:
diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc
index d8f5471951af..aeb4d2565df8 100644
--- a/gcc/tree-ssa-reassoc.cc
+++ b/gcc/tree-ssa-reassoc.cc
@@ -403,7 +403,8 @@ static inline void
 insert_operand_rank (tree e, int64_t rank)
 {
   gcc_assert (rank > 0);
-  gcc_assert (!operand_rank->put (e, rank));
+  bool existed = operand_rank->put (e, rank);
+  gcc_assert (!existed);
 }
 
 /* Given an expression E, return the rank of the expression.  */
diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index 1fed51905610..5b60b90cbc0c 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -2889,7 +2889,8 @@ static void
 insert_vi_for_tree (tree t, varinfo_t vi)
 {
   gcc_assert (vi);
-  gcc_assert (!vi_for_tree->put (t, vi));
+  bool existed = vi_for_tree->put (t, vi);
+  gcc_assert (!existed);
 }
 
 /* Find the variable info for tree T in VI_FOR_TREE.  If T does not

Reply via email to