Bug 108457 - [13 Regression] tree-ssa-loop-niter.cc:2255:23: warning: variable 'mode' set but not used
Summary: [13 Regression] tree-ssa-loop-niter.cc:2255:23: warning: variable 'mode' set ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: 13.0
Assignee: Jakub Jelinek
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2023-01-18 20:57 UTC by John David Anglin
Modified: 2023-01-20 09:29 UTC (History)
1 user (show)

See Also:
Host: hppa64-hp-hpux11.11
Target: hppa64-hp-hpux11.11
Build: hppa64-hp-hpux11.11
Known to work:
Known to fail:
Last reconfirmed: 2023-01-18 00:00:00


Attachments
gcc13-pr108457.patch (967 bytes, patch)
2023-01-19 12:23 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2023-01-18 20:57:17 UTC
g++ -std=c++11  -fno-PIE -c   -g -DIN_GCC     -fno-exceptions -fno-rtti -fasynch
ronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-fo
rmat -Wmissing-format-attribute -Wconditionally-supported -Woverloaded-virtual -
pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CO
NFIG_H -I. -I. -I../../gcc/gcc -I../../gcc/gcc/. -I../../gcc/gcc/../include  -I.
./../gcc/gcc/../libcpp/include -I../../gcc/gcc/../libcody -I/opt/gnu64/gcc/gmp/i
nclude  -I../../gcc/gcc/../libdecnumber -I../../gcc/gcc/../libdecnumber/dpd -I..
/libdecnumber -I../../gcc/gcc/../libbacktrace -I/opt/gnu64/gcc/gmp/include  -o t
ree-ssa-loop-niter.o -MT tree-ssa-loop-niter.o -MMD -MP -MF ./.deps/tree-ssa-loo
p-niter.TPo ../../gcc/gcc/tree-ssa-loop-niter.cc
../../gcc/gcc/tree-ssa-loop-niter.cc: In function 'tree_node* build_cltz_expr(tr
ee, bool, bool)':
../../gcc/gcc/tree-ssa-loop-niter.cc:2255:23: warning: variable 'mode' set but n
ot used [-Wunused-but-set-variable]
 2255 |       scalar_int_mode mode = SCALAR_INT_TYPE_MODE (utype);
      |                       ^~~~
Comment 1 Andrew Pinski 2023-01-18 21:07:12 UTC
Basically C[TL]Z_DEFINED_VALUE_AT_ZERO macro does not always use its arguments so they don't get marked as used ...

Simple patch:

diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
index 65b960461ae..22e7c0f6ea5 100644
--- a/gcc/tree-ssa-loop-niter.cc
+++ b/gcc/tree-ssa-loop-niter.cc
@@ -2253,6 +2253,8 @@ build_cltz_expr (tree src, bool leading, bool define_at_zero)
                                           integer_type_node, 1, src);
       int val;
       scalar_int_mode mode = SCALAR_INT_TYPE_MODE (utype);
+      /* mode might not be used by the macro C[TL]Z_DEFINED_AT_ZERO. */
+      (void)mode;
       int optab_defined_at_zero
        = leading ? CLZ_DEFINED_VALUE_AT_ZERO (mode, val)
                  : CTZ_DEFINED_VALUE_AT_ZERO (mode, val);
Comment 2 dave.anglin 2023-01-18 21:19:23 UTC
On 2023-01-18 4:07 p.m., pinskia at gcc dot gnu.org wrote:
> Basically C[TL]Z_DEFINED_VALUE_AT_ZERO macro does not always use its arguments
> so they don't get marked as used ...
Yes.  PA uses the default defines for these macros.
Comment 3 Jakub Jelinek 2023-01-19 12:06:22 UTC
Space between cast and mode.
Though I think various other uses of these macros solve this by simply using
SCALAR_INT_TYPE_MODE (utype) directly as argument to those macros rather than
using a temporary variable.
Comment 4 Jakub Jelinek 2023-01-19 12:23:45 UTC
Created attachment 54307 [details]
gcc13-pr108457.patch

So I'd prefer this instead.
Comment 5 Andrew Pinski 2023-01-19 14:16:01 UTC
(In reply to Jakub Jelinek from comment #3)
> Space between cast and mode.
> Though I think various other uses of these macros solve this by simply using
> SCALAR_INT_TYPE_MODE (utype) directly as argument to those macros rather than
> using a temporary variable.

I am ok with that too. This was just a quick patch to try to help to get it unstuck ...
Comment 6 GCC Commits 2023-01-20 09:24:29 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:16bd9e14f226e07bf0ffb9d68084c9ad69bf7b45

commit r13-5268-g16bd9e14f226e07bf0ffb9d68084c9ad69bf7b45
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jan 20 10:23:49 2023 +0100

    niter: Fix up unused var warning [PR108457]
    
    tree-ssa-loop-niter.cc (build_cltz_expr) gets unused variable mode
    warning on some architectures where C[LT]Z_DEFINED_VALUE_AT_ZERO
    macro(s) don't use the first argument (which includes the
    defaults.h definitions of:
     #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE)  0
     #define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE)  0
    Other uses of this macro avoid this problem by avoiding temporaries
    which are only used as argument to those macros, the following patch
    does it the same way for consistency.  Plus some formatting fixes
    while at it.
    
    2023-01-20  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/108457
            * tree-ssa-loop-niter.cc (build_cltz_expr): Use
            SCALAR_INT_TYPE_MODE (utype) directly as C[LT]Z_DEFINED_VALUE_AT_ZERO
            argument instead of a temporary.  Formatting fixes.
Comment 7 Jakub Jelinek 2023-01-20 09:29:12 UTC
Should be fixed now.