Hi! The following is a powerpcspe variant of the sparc PR39645, and rs6000 has the same code (not sure if ever used or dead after powerpcspe removal). When gimplifying the builtin, because va_arg_tmp.N is not marked as addressable from the beginning, we call prepare_gimple_addressable which assigns the previous value (uninitialized in this case) into the now addressable variable and nothing optimizes it away. Fixed by making it addressable from the beginning.
Bootstrapped/regtested on {x86_64,i686,powerpc64{,le}}-linux and tested with a cross to powerpcspe-linux on the testcase, committed as obvious to trunk. 2018-03-09 Jakub Jelinek <ja...@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. * config/powerpcspe/powerpcspe.c (rs6000_gimplify_va_arg): Likewise. * gcc.dg/pr84772.c: New test. --- gcc/config/rs6000/rs6000.c.jj 2018-03-07 22:52:01.294479625 +0100 +++ gcc/config/rs6000/rs6000.c 2018-03-09 17:29:09.811949947 +0100 @@ -13537,6 +13537,7 @@ rs6000_gimplify_va_arg (tree valist, tre tree copy = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY), 3, dest_addr, addr, size_int (rsize * 4)); + TREE_ADDRESSABLE (tmp) = 1; gimplify_and_add (copy, pre_p); addr = dest_addr; --- gcc/config/powerpcspe/powerpcspe.c.jj 2018-01-03 10:20:14.842537106 +0100 +++ gcc/config/powerpcspe/powerpcspe.c 2018-03-09 17:29:35.291959951 +0100 @@ -14254,6 +14254,7 @@ rs6000_gimplify_va_arg (tree valist, tre tree copy = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY), 3, dest_addr, addr, size_int (rsize * 4)); + TREE_ADDRESSABLE (tmp) = 1; gimplify_and_add (copy, pre_p); addr = dest_addr; --- gcc/testsuite/gcc.dg/pr84772.c.jj 2018-03-09 17:34:56.732749975 +0100 +++ gcc/testsuite/gcc.dg/pr84772.c 2018-03-09 17:33:05.095042322 +0100 @@ -0,0 +1,13 @@ +/* PR target/84772 */ +/* { dg-do compile } */ +/* { dg-options "-O -Wuninitialized" } */ + +#include <stdarg.h> + +void +foo (int *x, int y, va_list ap) +{ + __builtin_memset (x, 0, sizeof (int)); + for (int i = 0; i < y; i++) + va_arg (ap, long double); /* { dg-bogus "uninitialized" } */ +} Jakub