]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Fix up ix86_gimplify_va_arg [PR105331]
authorJakub Jelinek <jakub@redhat.com>
Thu, 28 Apr 2022 10:33:59 +0000 (12:33 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 28 Apr 2022 10:33:59 +0000 (12:33 +0200)
On the following testcase we emit a bogus
'va_arg_tmp.5' may be used uninitialized
warning.  The reason is that when gimplifying the addr = &temp;
statement, the va_arg_tmp temporary var for which we emit ADDR_EXPR
is not TREE_ADDRESSABLE, prepare_gimple_addressable emits some extra
code to initialize the newly addressable var from its previous value,
but it is a new variable which hasn't been initialized yet and will
be later, so we end up initializing it with uninitialized SSA_NAME:
  va_arg_tmp.6 = va_arg_tmp.5_14(D);
  addr.2_16 = &va_arg_tmp.6;
  _17 = MEM[(double *)sse_addr.4_13];
  MEM[(double * {ref-all})addr.2_16] = _17;
and with -O1 we actually don't DSE it before the warning is emitted.
If we make the temp TREE_ADDRESSABLE before the gimplification, then
this prepare_gimple_addressable path isn't taken and we effectively
omit the first statement above and so the bogus warning is gone.

I went through other backends and didn't find another instance of this
problem.

2022-04-28  Jakub Jelinek  <jakub@redhat.com>

PR target/105331
* config/i386/i386.cc (ix86_gimplify_va_arg): Mark va_arg_tmp
temporary TREE_ADDRESSABLE before trying to gimplify ADDR_EXPR
of it.

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

gcc/config/i386/i386.cc
gcc/testsuite/gcc.dg/pr105331.c [new file with mode: 0644]

index 52040da8c47f55ded0389b241d1a482142af4ba0..b16df5b183e14a448878fadea45fccf529d8f5f5 100644 (file)
@@ -4891,6 +4891,7 @@ ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
        {
          int i, prev_size = 0;
          tree temp = create_tmp_var (type, "va_arg_tmp");
+         TREE_ADDRESSABLE (temp) = 1;
 
          /* addr = &temp; */
          t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
diff --git a/gcc/testsuite/gcc.dg/pr105331.c b/gcc/testsuite/gcc.dg/pr105331.c
new file mode 100644 (file)
index 0000000..06cf6d6
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR target/105331 */
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+#include <stdarg.h>
+
+int
+foo (va_list *va)
+{
+  return va_arg (*va, double _Complex);        /* { dg-bogus "may be used uninitialized" } */
+}