public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Stefan Liebler <stli@linux.vnet.ibm.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] Dynamic growable arrays for internal use
Date: Wed, 07 Jun 2017 09:41:00 -0000	[thread overview]
Message-ID: <5308ddfb-a125-e4f6-8615-3148e350bdd6@redhat.com> (raw)
In-Reply-To: <37f01ed4-1443-8585-42cb-1b7759416ee7@linux.vnet.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 1389 bytes --]

On 06/06/2017 05:30 PM, Stefan Liebler wrote:
> Hi Florian,
> 
> I get the following warning / werror with gcc 4.8.5 on s390x:
> gcc tst-dynarray.c -O3 -c ... -o <build>/malloc/tst-dynarray.o
> In file included from tst-dynarray.c:50:0:
> tst-dynarray.c: In function ‘do_test’:
> ../support/check.h:51:8: error: ‘result.length’ may be used
> uninitialized in this function [-Werror=maybe-uninitialized]
>      if (expr)                                                   \
>         ^
> tst-dynarray.c:377:23: note: ‘result.length’ was declared here
>      struct long_array result;
>                        ^
> In file included from tst-dynarray.c:50:0:
> ../support/check.h:51:8: error: ‘result.array’ may be used uninitialized
> in this function [-Werror=maybe-uninitialized]
>      if (expr)                                                   \
>         ^
> tst-dynarray.c:377:23: note: ‘result.array’ was declared here
>      struct long_array result;
>                        ^
> cc1: all warnings being treated as errors
> 
> 
> Have you seen those warnings on other architectures, too?

I could reproduce it with -O3 on s390x.  I have not tried it with other
architectures, but it is a generic problem with TEST_VERIFY_EXIT which
is not really related to the dynarray code.  I propose the attached
patch to fix it.

Thanks,
Florian

[-- Attachment #2: test_verify_exit.patch --]
[-- Type: text/x-patch, Size: 3367 bytes --]

support: Expose TEST_VERIFY_EXIT behavior to GCC optimizers

Previously, the implementation would conditionally exit based on the
status argument, which GCC did not know about.  This leads to
false uninitialized variable warnings when data is accessed after a
TEST_VERIFY_EXIT failure (from code which would never execute).

2017-06-07  Florian Weimer  <fweimer@redhat.com>

	Expose TEST_VERIFY_EXIT process termination to GCC optimizers.
	* support/support_test_verify_impl.c
	(support_test_verify_exit_impl): Split from
	support_test_verify_impl.
	* support/check.h (TEST_VERIFY): Drop status argument from
	support_test_verify_impl call.
	(TEST_VERIFY_EXIT): Call support_test_verify_exit_impl.
	(support_test_verify_impl): Remove status argument.
	(support_test_verify_exit_impl): Declare.

diff --git a/support/check.h b/support/check.h
index 1d244a3..bdcd129 100644
--- a/support/check.h
+++ b/support/check.h
@@ -51,7 +51,7 @@ __BEGIN_DECLS
     if (expr)                                                   \
       ;                                                         \
     else                                                        \
-      support_test_verify_impl (-1, __FILE__, __LINE__, #expr); \
+      support_test_verify_impl (__FILE__, __LINE__, #expr);     \
   })
 
 /* Record a test failure and exit if EXPR evaluates to false.  */
@@ -60,7 +60,8 @@ __BEGIN_DECLS
     if (expr)                                                   \
       ;                                                         \
     else                                                        \
-      support_test_verify_impl (1, __FILE__, __LINE__, #expr);  \
+      support_test_verify_exit_impl                             \
+        (1, __FILE__, __LINE__, #expr);                         \
   })
 
 int support_print_failure_impl (const char *file, int line,
@@ -70,8 +71,11 @@ void support_exit_failure_impl (int exit_status,
                                 const char *file, int line,
                                 const char *format, ...)
   __attribute__ ((noreturn, nonnull (2), format (printf, 4, 5)));
-void support_test_verify_impl (int status, const char *file, int line,
+void support_test_verify_impl (const char *file, int line,
                                const char *expr);
+void support_test_verify_exit_impl (int status, const char *file, int line,
+                                    const char *expr)
+  __attribute__ ((noreturn));
 
 /* Record a test failure.  This function returns and does not
    terminate the process.  The failure counter is stored in a shared
diff --git a/support/support_test_verify_impl.c b/support/support_test_verify_impl.c
index 5bae38f..55ab211 100644
--- a/support/support_test_verify_impl.c
+++ b/support/support_test_verify_impl.c
@@ -22,12 +22,16 @@
 #include <stdlib.h>
 
 void
-support_test_verify_impl (int status, const char *file, int line,
-                          const char *expr)
+support_test_verify_impl (const char *file, int line, const char *expr)
 {
   support_record_failure ();
   printf ("error: %s:%d: not true: %s\n", file, line, expr);
-  if (status >= 0)
-    exit (status);
+}
 
+void
+support_test_verify_exit_impl (int status, const char *file, int line,
+                               const char *expr)
+{
+  support_test_verify_impl (file, line, expr);
+  exit (status);
 }

  parent reply	other threads:[~2017-06-07  9:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-22 15:46 Florian Weimer
2017-04-24 14:06 ` Joseph Myers
2017-05-05 11:48   ` Florian Weimer
2017-05-05 15:13     ` Paul Eggert
2017-05-05 15:23       ` Florian Weimer
2017-05-05 22:31         ` Paul Eggert
2017-05-20  2:01 ` Carlos O'Donell
2017-05-21  0:43   ` Paul Eggert
2017-06-01 16:13     ` Carlos O'Donell
2017-06-01 17:09       ` Jeff Law
2017-06-01 20:21         ` Florian Weimer
2017-06-01 21:13           ` Adhemerval Zanella
2017-06-01 18:08       ` Paul Eggert
2017-05-30 12:48   ` Florian Weimer
2017-06-02  7:37     ` Carlos O'Donell
2017-06-02 10:04       ` Florian Weimer
2017-06-06 15:30       ` Stefan Liebler
2017-06-06 15:46         ` H.J. Lu
2017-06-07  9:54           ` Florian Weimer
2017-06-07  9:41         ` Florian Weimer [this message]
2017-06-07 14:41           ` Stefan Liebler
2017-06-07 18:56             ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5308ddfb-a125-e4f6-8615-3148e350bdd6@redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=stli@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).