Bug 14775 - [2.23] gas build failure for aarch64-linux: set but not used variable in tc-aarch64.c:first_error_fmt
Summary: [2.23] gas build failure for aarch64-linux: set but not used variable in tc-a...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.23
: P2 normal
Target Milestone: ---
Assignee: Yufeng Zhang
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-27 17:48 UTC by Mikael Pettersson
Modified: 2013-01-10 15:29 UTC (History)
1 user (show)

See Also:
Host:
Target: aarch64-linux
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mikael Pettersson 2012-10-27 17:48:16 UTC
I've previously built cvs head snapshots for aarch64-linux.  Attempting to do so with the binutils-2.23 release fails as follows:

gcc -DHAVE_CONFIG_H -I. -I/tmp/binutils-2.23/gas  -I. -I/tmp/binutils-2.23/gas -I../bfd -I/tmp/binutils-2.23/gas/config -I/tmp/binutils-2.23/gas/../include -I/tmp/binutils-2.23/gas/.. -I/tmp/binutils-2.23/gas/../bfd -DLOCALEDIR="\"/tmp/install/share/locale\""  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -MT tc-aarch64.o -MD -MP -MF .deps/tc-aarch64.Tpo -c -o tc-aarch64.o `test -f 'config/tc-aarch64.c' || echo '/tmp/binutils-2.23/gas/'`config/tc-aarch64.c
/tmp/binutils-2.23/gas/config/tc-aarch64.c: In function 'first_error_fmt':
/tmp/binutils-2.23/gas/config/tc-aarch64.c:646:11: error: variable 'ret' set but not used [-Werror=unused-but-set-variable]

The code in question is:

    {
      int ret;
      va_start (args, format);
      ret = vsnprintf (buffer, size, format, args);
      know (ret <= size - 1 && ret >= 0);
      va_end (args);
      set_syntax_error (buffer);
    }

That is, the variable ret is only used in the assert-like know call.  However, know is a macro that expands to a dummy statement (do{}while(0)), so the actual parameter expression disappears and ret is unused-but-set.

This doesn't happen when building from cvs head, presumably because know then expands to gas_assert which does evaluate the expression.

I don't want to use --disable-werror by default.  Is there a reason why know(p) can't use the standard technique of expanding to (void)(p)?  That change fixes the problem for me.
Comment 1 Yufeng Zhang 2013-01-10 15:21:47 UTC
Sorry for the rather late response; I only realized today the existence of this bugzilla.
Comment 2 Yufeng Zhang 2013-01-10 15:29:47 UTC
This should have been fixed in both the trunk and binutils-2_23-branch.  See the following two commits:

http://sourceware.org/ml/binutils-cvs/2012-11/msg00129.html
http://sourceware.org/ml/binutils-cvs/2012-11/msg00130.html

The fix happened after the release of binutils 2.23.1, so if you are using  binutils 2.23.1, please apply the same patch, or use binutils-2_23-branch instead.  Sorry for the inconvenience.