Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* FYI: -Wunused warning in cp-namespace.c with old glibc...
@ 2009-12-30 10:48 Joel Brobecker
  2009-12-30 13:22 ` Daniel Jacobowitz
  2010-03-24 23:26 ` Joseph S. Myers
  0 siblings, 2 replies; 3+ messages in thread
From: Joel Brobecker @ 2009-12-30 10:48 UTC (permalink / raw)
  To: gdb-patches

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

Hello,

We're still supporting some pretty old x86-linux distributions at
AdaCore, and one of them comes with a now antiquated version of
the glic.  And unfortunately, this version of glic plays some tricks
with strncpy, while these tricks are disabled on older glibcs
for GCC 3.2+:

/* Copy no more than N characters of SRC to DEST.  */
#ifndef _HAVE_STRING_ARCH_strncpy
# if __GNUC_PREREQ (3, 2)
#  define strncpy(dest, src, n) __builtin_strncpy (dest, src, n)
# else
#  define strncpy(dest, src, n) \
  (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n)     \
                  ? (strlen (src) + 1 >= ((size_t) (n))                      \
                     ? (char *) memcpy (dest, src, n)                        \
                     : strncpy (dest, src, n))                               \
                  : strncpy (dest, src, n)))
# endif
#endif

On the older system, we end up getting a warning-turned-error:

    [...]/gdb/cp-namespace.c: In function 'cp_lookup_transparent_type_loop':
    [...]/gdb/cp-namespace.c:542: error: value computed is not used

The fix we applied locally, is to cast the function return to void.
I don't think that this part would be of interest for the FSF tree
(it's not exactly great to add an apparently useless cast), so I propose
we don't apply it, but I thought I'd still post it, in case someone else
might need it (or others think it should go in).  For now, I'll assume
we don't want it.

2009-12-30  Joel Brobecker  <brobecker@adacore.com>

        Work around a -Wunused warning when glibc is too old.
        * cp-namespace.c (cp_lookup_transparent_type_loop): Add cast to
        void in function return to avoid a compiler warning.

"tested" by rebuilding GDB. I'll also get the nightly build results
tomorrow, but I didn't want to spend too much effort on this one.

-- 
Joel

[-- Attachment #2: wunused.diff --]
[-- Type: text/x-diff, Size: 1123 bytes --]

commit cdf20aaf0a8b39a1f1ee427570a717f1c44ba272
Author: brobecke <brobecke@f8352e7e-cb20-0410-8ce7-b5d9e71c585c>
Date:   Wed Dec 30 10:28:08 2009 +0000

            Work around a -Wunused warning when glibc is too old.
            * cp-namespace.c (cp_lookup_transparent_type_loop): Add cast to
            void in function return to avoid a compiler warning.
    
    
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index a7a387b..35bb36c 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -539,7 +539,10 @@ cp_lookup_transparent_type_loop (const char *name, const char *scope,
 
   full_name = alloca (scope_length + 2 + strlen (name) + 1);
   strncpy (full_name, scope, scope_length);
-  strncpy (full_name + scope_length, "::", 2);
+  /* Cast to void the return value of the following strncpy to avoid
+     a -Wunused warning from GCC when the glibc is too old (observed
+     with a 2.3.2 libc, while everything was fine with a 2.4 glibc).  */
+  (void) strncpy (full_name + scope_length, "::", 2);
   strcpy (full_name + scope_length + 2, name);
 
   return basic_lookup_transparent_type (full_name);

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

* Re: FYI: -Wunused warning in cp-namespace.c with old glibc...
  2009-12-30 10:48 FYI: -Wunused warning in cp-namespace.c with old glibc Joel Brobecker
@ 2009-12-30 13:22 ` Daniel Jacobowitz
  2010-03-24 23:26 ` Joseph S. Myers
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Jacobowitz @ 2009-12-30 13:22 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Wed, Dec 30, 2009 at 02:48:16PM +0400, Joel Brobecker wrote:
> Hello,
> 
> We're still supporting some pretty old x86-linux distributions at
> AdaCore, and one of them comes with a now antiquated version of
> the glic.  And unfortunately, this version of glic plays some tricks
> with strncpy, while these tricks are disabled on older glibcs
> for GCC 3.2+:

FYI, we ran into this too - we ended up dropping a newer
bits/string2.h (from RHEL4 rather than RH8/RHEL3, I believe) into our
build system.  The newer one works fine with an older runtime.

-- 
Daniel Jacobowitz
CodeSourcery


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

* Re: FYI: -Wunused warning in cp-namespace.c with old glibc...
  2009-12-30 10:48 FYI: -Wunused warning in cp-namespace.c with old glibc Joel Brobecker
  2009-12-30 13:22 ` Daniel Jacobowitz
@ 2010-03-24 23:26 ` Joseph S. Myers
  1 sibling, 0 replies; 3+ messages in thread
From: Joseph S. Myers @ 2010-03-24 23:26 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Wed, 30 Dec 2009, Joel Brobecker wrote:

> On the older system, we end up getting a warning-turned-error:
> 
>     [...]/gdb/cp-namespace.c: In function 'cp_lookup_transparent_type_loop':
>     [...]/gdb/cp-namespace.c:542: error: value computed is not used

FWIW, I've applied a patch to GCC trunk's fixincludes to make it fix this 
issue in the old bits/string2.h.  That allows the error to be avoided when 
using a new GCC with glibc that predates the GCC version conditional and 
use of __builtin_strncpy.

-- 
Joseph S. Myers
joseph@codesourcery.com


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

end of thread, other threads:[~2010-03-24 23:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-30 10:48 FYI: -Wunused warning in cp-namespace.c with old glibc Joel Brobecker
2009-12-30 13:22 ` Daniel Jacobowitz
2010-03-24 23:26 ` Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox