public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4] elf: fixes compile error when both enable -Werror and -DNDEBUG
@ 2022-04-12  9:47 Yang Yanchao
  2022-04-13 10:16 ` Florian Weimer
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Yanchao @ 2022-04-12  9:47 UTC (permalink / raw)
  To: libc-alpha; +Cc: linfeilong, carlos, fweimer, schwab

Use -Werror and -DNDEBUG at the same time will
causes the following compilation errors:

cache.c: In function 'save_cache':
cache.c:758:15: error: unused variable 'old_offset' [-Werror=unused-variable]
  758 |       off64_t old_offset = lseek64 (fd, extension_offset, SEEK_SET);
      |               ^~~~~~~~~~

-DNDEBUG will disables the assertion.
Therefore, only the variables used by assertions do not take effect.
use DIAG_IGNORE_NEEDS_COMMENT to disable this warning.
---
 elf/cache.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/elf/cache.c b/elf/cache.c
index dbf4c83a7a..1e5427555b 100644
--- a/elf/cache.c
+++ b/elf/cache.c
@@ -36,6 +36,7 @@
 #include <dl-cache.h>
 #include <version.h>
 #include <stringtable.h>
+#include <libc-diag.h>
 
 /* Used to store library names, paths, and other strings.  */
 static struct stringtable strings;
@@ -751,6 +752,10 @@ save_cache (const char *cache_name)
       != (ssize_t) strings_finalized.size)
     error (EXIT_FAILURE, errno, _("Writing of cache data failed"));
 
+  /* Building with -DNDEBUG, assert will be ignored,
+     so that old_offset is not used */
+  DIAG_PUSH_NEEDS_COMMENT
+  DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wunused-variable");
   if (opt_format != opt_format_old)
     {
       /* Align file position to 4.  */
@@ -758,6 +763,7 @@ save_cache (const char *cache_name)
       assert ((unsigned long long int) (extension_offset - old_offset) < 4);
       write_extensions (fd, str_offset, extension_offset);
     }
+  DIAG_POP_NEEDS_COMMENT
 
   /* Make sure user can always read cache file */
   if (chmod (temp_name, S_IROTH|S_IRGRP|S_IRUSR|S_IWUSR))
-- 
2.33.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-13 12:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12  9:47 [PATCH v4] elf: fixes compile error when both enable -Werror and -DNDEBUG Yang Yanchao
2022-04-13 10:16 ` Florian Weimer
2022-04-13 12:46   ` Andreas Schwab

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).