diff mbox

-Og bug? (was: [PATCH] libsanitizer demangling using cp-demangle.c)

Message ID 87bnyw41hf.fsf@kepler.schwinge.homeip.net
State New
Headers show

Commit Message

Thomas Schwinge Jan. 28, 2014, 2:36 p.m. UTC
Hi!

This got committed to trunk as r206477; one small nit:

On Tue, 10 Dec 2013 12:38:34 +0100, Jakub Jelinek <jakub@redhat.com> wrote:
> 	* libbacktrace/Makefile.am (libsanitizer_libbacktrace_la_SOURCES): Add
> 	../../libiberty/cp-demangle.c.

Trying to build trunk r207180 with C*FLAGS='-Og -ggdb', a compiler
warning in cp-demangle.c (as seen for other instances of cp-demangle.c
being built) is promoted to a hard error in the libsanitizer context, due
to -Werror usage:

    libtool: compile:  [...]/build/./gcc/xgcc -B[...]/build/./gcc/ -B[...]/install/x86_64-unknown-linux-gnu/bin/ -B[...]/install/x86_64-unknown-linux-gnu/lib/ -isystem [...]/install/x86_64-unknown-linux-gnu/include -isystem [...]/install/x86_64-unknown-linux-gnu/sys-include -DHAVE_CONFIG_H -I. -I../../../../source/libsanitizer/libbacktrace -I.. -I ../../../../source/libsanitizer/../include -I ../../../../source/libsanitizer/../libgcc -I ../../libgcc -I .. -I ../../../../source/libsanitizer -I ../../../../source/libsanitizer/../libbacktrace -W -Wall -Wwrite-strings -Wmissing-format-attribute -Wcast-qual -Werror -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -g -O2 -Og -ggdb -MT cp-demangle.lo -MD -MP -MF .deps/cp-demangle.Tpo -c ../../../../source/libsanitizer/libbacktrace/../../libiberty/cp-demangle.c  -fPIC -DPIC -o .libs/cp-demangle.o
    ../../../../source/libsanitizer/libbacktrace/../../libiberty/cp-demangle.c: In function 'd_demangle_callback':
    ../../../../source/libsanitizer/libbacktrace/../../libiberty/cp-demangle.c:5842:14: error: 'dc' may be used uninitialized in this function [-Werror=maybe-uninitialized]
                  : 0;
                  ^
    cc1: all warnings being treated as errors
    make[4]: *** [cp-demangle.lo] Error 1
    make[4]: Leaving directory `[...]/build/x86_64-unknown-linux-gnu/libsanitizer/libbacktrace'

GCC fails to track that all the possible values for enum type indeed have
been covered, and so dc must have been initialized.  As the warning/error
does not appear with -O0, is this in fact a -Og bug?  If not, solve this
by initializing dc to NULL (lame...) ;-), or maybe as follows?

Avoid "'dc' may be uninitialized" warning.

	libiberty/
	* cp-demangle.c (d_demangle_callback): Put __builtin_unreachable
	in place, to help the compiler.



Grüße,
 Thomas

Comments

Ian Lance Taylor Jan. 28, 2014, 2:52 p.m. UTC | #1
On Tue, Jan 28, 2014 at 6:36 AM, Thomas Schwinge
<thomas@codesourcery.com> wrote:
> Avoid "'dc' may be uninitialized" warning.
>
>         libiberty/
>         * cp-demangle.c (d_demangle_callback): Put __builtin_unreachable
>         in place, to help the compiler.
>
> --- libiberty/cp-demangle.c
> +++ libiberty/cp-demangle.c
> @@ -5824,6 +5824,8 @@ d_demangle_callback (const char *mangled, int options,
>                           NULL);
>         d_advance (&di, strlen (d_str (&di)));
>         break;
> +      default:
> +       __builtin_unreachable ();

You can't call __builtin_unreachable in this code, because libiberty
in stage 1 will be compiled by the host compiler and
__builtin_unreachable is specific to GCC.

This patch is OK if you call abort instead of __builtin_unreachable.

Thanks.

Ian
diff mbox

Patch

--- libiberty/cp-demangle.c
+++ libiberty/cp-demangle.c
@@ -5824,6 +5824,8 @@  d_demangle_callback (const char *mangled, int options,
 			  NULL);
 	d_advance (&di, strlen (d_str (&di)));
 	break;
+      default:
+	__builtin_unreachable ();
       }
 
     /* If DMGL_PARAMS is set, then if we didn't consume the entire