[go: nahoru, domu]

Bug 84772 - powerpc-spe: Spurious "is used uninitialized" warning, or possibly incorrect codegen for va_arg(long double)
Summary: powerpc-spe: Spurious "is used uninitialized" warning, or possibly incorrect ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 7.3.1
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2018-03-09 00:05 UTC by Zack Weinberg
Modified: 2018-06-25 18:20 UTC (History)
1 user (show)

See Also:
Host:
Target: powerpc-glibc-linux-gnuspe
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-03-09 00:00:00


Attachments
-fdump-tree-stdarg output for test case from problem compiler (614 bytes, text/plain)
2018-03-09 15:21 UTC, Zack Weinberg
Details
gcc8-pr84772.patch (723 bytes, patch)
2018-03-09 16:38 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zack Weinberg 2018-03-09 00:05:33 UTC
The following test case is a mechanical reduction from the implementation of vfprintf in GNU libc:

    extern void *memset(void *, int, __SIZE_TYPE__);
    void f(int *a, __builtin_va_list b)
    {
      memset(a, 2, sizeof(int));
      for (;;)
        __builtin_va_arg(b, long double);
    }

I get a spurious uninitialized value warning on the __builtin_va_arg line with a powerpc-spe compiler, but not with the exact same build targeting a different architecture -- not even a different powerpc variant:

$ powerpc-glibc-linux-gnuspe-gcc -S -O -Wall -Werror vfp_min3.c; echo $?
vfp_min3.c: In function ‘f’:
vfp_min3.c:6:25: error: ‘va_arg_tmp.3’ is used uninitialized in this function [-Werror=uninitialized]
     __builtin_va_arg(b, long double);
     ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
cc1: all warnings being treated as errors
1
$ powerpc-glibc-linux-gnu-gcc -S -O -Wall -Werror vfp_min3.c; echo $?
0

$ powerpc-glibc-linux-gnuspe-gcc --version
powerpc-glibc-linux-gnuspe-gcc (GCC) 7.3.1 20180307 [gcc-7-branch revision 258338]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ powerpc-glibc-linux-gnu-gcc --version
powerpc-glibc-linux-gnu-gcc (GCC) 7.3.1 20180307 [gcc-7-branch revision 258338]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This is an extra frustrating spurious-uninitialized bug because it's complaining about a variable that doesn't even exist in the source code -- I guess it's a  temporary used inside the expansion of __builtin_va_arg?  So it might not even be *spurious*, I suppose, it might be telling me that that expansion is wrong!
Comment 1 Jakub Jelinek 2018-03-09 08:17:13 UTC
Can't reproduce.
$ ./xgcc -B ./ -v
Reading specs from ./specs
COLLECT_GCC=./xgcc
COLLECT_LTO_WRAPPER=./lto-wrapper
Target: powerpc-e500v2-linux-gnuspe
Configured with: ../configure --target powerpc-e500v2-linux-gnuspe --disable-bootstrap --enable-languages=c,c++,fortran : (reconfigured) 
Thread model: posix
gcc version 8.0.1 20180309 (experimental) (GCC) 
$ ./cc1 -quiet -m32 -O2 -Wall -W pr84772.c -nostdinc -mcpu=8540
$ ./cc1 -quiet -m32 -O2 -Wall -W pr84772.c -nostdinc -mcpu=8548
No warnings at all in either.

Nor in 7.3.1:
$ ./xgcc -B ./ -v
Reading specs from ./specs
COLLECT_GCC=./xgcc
COLLECT_LTO_WRAPPER=./lto-wrapper
Target: powerpc-glibc-linux-gnuspe
Configured with: ../configure --target powerpc-glibc-linux-gnuspe --disable-bootstrap --enable-languages=c,c++,fortran
Thread model: posix
gcc version 7.3.1 20180309 (GCC) 
$ ./cc1 -quiet -O -Wall -W pr84772.c -nostdinc
Comment 2 Zack Weinberg 2018-03-09 15:15:18 UTC
You don't appear to have the exact same build as me.  But there's something fishy going on with that, because as far as I can tell, SVN rev 258338 is a *trunk* revision, not a gcc-7-branch revision.

Anyway, I'm gonna attach a .stdarg dump from the compiler that does trigger the problem, maybe comparing that to the .stdarg dump you get will help?
Comment 3 Zack Weinberg 2018-03-09 15:21:11 UTC
Created attachment 43607 [details]
-fdump-tree-stdarg output for test case from problem compiler

I do not entirely understand how to read this (what do the _123(D) suffixes on everything mean?) but right after <L3> there sure does appear to be a read of the variable va_arg_tmp.3, which was introduced by this pass, and which does not appear to have been previously initialized.
Comment 4 Zack Weinberg 2018-03-09 15:59:09 UTC
The last actual _change_ in my GCC build is

r258315 | denisc | 2018-03-07 04:13:12 -0500 (Wed, 07 Mar 2018) | 9 lines

        Backport from mainline
        2018-02-07  Georg-Johann Lay  <avr@gjlay.de>

        PR target/84209
        * config/avr/avr.h (GENERAL_REGNO_P, GENERAL_REG_P): New macros.
        * config/avr/avr.md: Only post-reload split REG-REG moves if
        either register is GENERAL_REG_P.
Comment 5 Jakub Jelinek 2018-03-09 16:37:32 UTC
Ah, I can actually reproduce it with additional -mlong-double-128, both in 7.3 and on the trunk.
Comment 6 Jakub Jelinek 2018-03-09 16:38:20 UTC
Created attachment 43608 [details]
gcc8-pr84772.patch

Untested fix.
Comment 7 Zack Weinberg 2018-03-09 18:01:35 UTC
I no longer remember enough about GIMPLE to comment on your actual proposed fix, but I do have a small nitpick on the test case:

+    va_arg (ap, long double);			/* { dg-bogus "may be used uninitialized in this function" } */  

I think that needs to be just { dg-bogus "used uninitialized" }, as you might get either the "may be used initialized" or the "is used uninitialized" message.
Comment 8 Jakub Jelinek 2018-03-09 22:23:46 UTC
Author: jakub
Date: Fri Mar  9 22:23:14 2018
New Revision: 258399

URL: https://gcc.gnu.org/viewcvs?rev=258399&root=gcc&view=rev
Log:
	PR target/84772
	* config/rs6000/rs6000.c (rs6000_gimplify_va_arg): Mark va_arg_tmp
	temporary TREE_ADDRESSABLE before gimplification of BUILT_IN_MEMCPY.
	* config/powerpcspe/powerpcspe.c (rs6000_gimplify_va_arg): Likewise.

	* gcc.dg/pr84772.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr84772.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/powerpcspe/powerpcspe.c
    trunk/gcc/config/rs6000/rs6000.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2018-03-09 22:29:28 UTC
Fixed on the trunk so far.
Comment 10 Jakub Jelinek 2018-06-22 20:36:01 UTC
Author: jakub
Date: Fri Jun 22 20:35:29 2018
New Revision: 261918

URL: https://gcc.gnu.org/viewcvs?rev=261918&root=gcc&view=rev
Log:
	Backported from mainline
	2018-03-09  Jakub Jelinek  <jakub@redhat.com>

	PR target/84772
	* config/rs6000/rs6000.c (rs6000_gimplify_va_arg): Mark va_arg_tmp
	temporary TREE_ADDRESSABLE before gimplification of BUILT_IN_MEMCPY.

	* gcc.dg/pr84772.c: New test.

Added:
    branches/gcc-7-branch/gcc/testsuite/gcc.dg/pr84772.c
Modified:
    branches/gcc-7-branch/gcc/ChangeLog
    branches/gcc-7-branch/gcc/config/rs6000/rs6000.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 11 Jakub Jelinek 2018-06-25 17:31:55 UTC
Author: jakub
Date: Mon Jun 25 17:31:23 2018
New Revision: 262074

URL: https://gcc.gnu.org/viewcvs?rev=262074&root=gcc&view=rev
Log:
	Backported from mainline
	2018-03-09  Jakub Jelinek  <jakub@redhat.com>

	PR target/84772
	* config/rs6000/rs6000.c (rs6000_gimplify_va_arg): Mark va_arg_tmp
	temporary TREE_ADDRESSABLE before gimplification of BUILT_IN_MEMCPY.

	* gcc.dg/pr84772.c: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/gcc.dg/pr84772.c
Modified:
    branches/gcc-6-branch/gcc/ChangeLog
    branches/gcc-6-branch/gcc/config/rs6000/rs6000.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 12 Jakub Jelinek 2018-06-25 18:20:30 UTC
Fixed for 6.5 and 7.4+ too.