ppc: avoid C99-style loop

Message ID 3b77ae27-1598-ed65-0302-e68c8168ee4a@suse.com
State New
Headers show
Series
  • ppc: avoid C99-style loop
Related show

Commit Message

Richard Earnshaw via Binutils April 22, 2021, 8:17 a.m.
While work towards using/requiring C99 is underway, this "dialect" at
present doesn't look to get enforced anywhere, relying on the compiler
default instead. Old enough gcc will complain:

.../opcodes/ppc-dis.c: In function ‘print_insn_powerpc’:
.../opcodes/ppc-dis.c:1071: error: ‘for’ loop initial declaration used outside C99 mode

Oddly enough I ran into this with a i686-darwin (cross) build, which for
whatever reason also enables ppc support by default.

opcodes/
2021-04-XX  Jan Beulich  <jbeulich@suse.com>

	* ppc-dis.c (print_insn_powerpc): Don't use C99-style loop.
---
Quite obviously the alternative to this is to pass -std=c99 to the
compiler, but since this wasn't done so far, and since I wouldn't know
where to put the addition, I opted for the more simplistic fix.

Comments

Richard Earnshaw via Binutils April 23, 2021, 1:29 p.m. | #1
Hi Jan,

> While work towards using/requiring C99 is underway, this "dialect" at

> present doesn't look to get enforced anywhere,


Well except for the fact that feature of the dialect are now being used 
in the sources...


> .../opcodes/ppc-dis.c: In function ‘print_insn_powerpc’:

> .../opcodes/ppc-dis.c:1071: error: ‘for’ loop initial declaration used outside C99 mode


That error implies that the compiler can operate in C99 mode, but that 
it is not doing so.  Is this the case ?  If so, then the real bug is 
that the compiler is not being given the flag(s) that it needs to enable 
this mode.

Cheers
   Nick
Richard Earnshaw via Binutils April 23, 2021, 1:32 p.m. | #2
On 23.04.2021 15:29, Nick Clifton wrote:
>> While work towards using/requiring C99 is underway, this "dialect" at

>> present doesn't look to get enforced anywhere,

> 

> Well except for the fact that feature of the dialect are now being used 

> in the sources...


Albeit for now only in a limited way.

>> .../opcodes/ppc-dis.c: In function ‘print_insn_powerpc’:

>> .../opcodes/ppc-dis.c:1071: error: ‘for’ loop initial declaration used outside C99 mode

> 

> That error implies that the compiler can operate in C99 mode, but that 

> it is not doing so.  Is this the case ?


Yes.

>  If so, then the real bug is 

> that the compiler is not being given the flag(s) that it needs to enable 

> this mode.


Right, as also expressed in a post-commit-message remark. I've
also said there "but since this wasn't done so far, and since I
wouldn't know where to put the addition, I opted for the more
simplistic fix."

Jan
Richard Earnshaw via Binutils April 23, 2021, 3:03 p.m. | #3
On 23 Apr 2021 15:32, Jan Beulich via Binutils wrote:
> On 23.04.2021 15:29, Nick Clifton wrote:

> >> While work towards using/requiring C99 is underway, this "dialect" at

> >> present doesn't look to get enforced anywhere,

> > 

> > Well except for the fact that feature of the dialect are now being used 

> > in the sources...

> 

> Albeit for now only in a limited way.

> 

> >> .../opcodes/ppc-dis.c: In function ‘print_insn_powerpc’:

> >> .../opcodes/ppc-dis.c:1071: error: ‘for’ loop initial declaration used outside C99 mode

> > 

> > That error implies that the compiler can operate in C99 mode, but that 

> > it is not doing so.  Is this the case ?

> 

> Yes.

> 

> >  If so, then the real bug is 

> > that the compiler is not being given the flag(s) that it needs to enable 

> > this mode.

> 

> Right, as also expressed in a post-commit-message remark. I've

> also said there "but since this wasn't done so far, and since I

> wouldn't know where to put the addition, I opted for the more

> simplistic fix."


prob easy to fix though:
--- a/opcodes/configure.ac
+++ b/opcodes/configure.ac
@@ -25,7 +25,7 @@ AC_CANONICAL_TARGET
 
 AM_INIT_AUTOMAKE
 
-AC_PROG_CC
+AC_PROG_CC_C99
 AC_GNU_SOURCE
 AC_USE_SYSTEM_EXTENSIONS
 
-mike
Hans-Peter Nilsson April 25, 2021, 8:27 p.m. | #4
On Fri, 23 Apr 2021, Nick Clifton via Binutils wrote:
> Hi Jan,

>

> > While work towards using/requiring C99 is underway, this "dialect" at

> > present doesn't look to get enforced anywhere,

>

> Well except for the fact that feature of the dialect are now being used in the

> sources...

>

>

> > .../opcodes/ppc-dis.c: In function ?print_insn_powerpc?:

> > .../opcodes/ppc-dis.c:1071: error: ?for? loop initial declaration used

> > outside C99 mode

>

> That error implies that the compiler can operate in C99 mode, but that it is

> not doing so.  Is this the case ?  If so, then the real bug is that the

> compiler is not being given the flag(s) that it needs to enable this mode.


Perhaps blindingly obvious, perhaps obsoleted, but... is this
because we're missing AC_PROG_CC_C99 in all configure.ac?

brgds, H-P
Richard Earnshaw via Binutils April 26, 2021, 11:25 a.m. | #5
Hi Guys,

> Perhaps blindingly obvious, perhaps obsoleted, but... is this

> because we're missing AC_PROG_CC_C99 in all configure.ac?


I like this.  But of course it does mean coordinating the change with 
gcc and gdb.  Still why not.  I'll post an email and see what happens.

Cheers
   Nick

Patch

--- a/opcodes/ppc-dis.c
+++ b/opcodes/ppc-dis.c
@@ -1068,7 +1068,9 @@  print_insn_powerpc (bfd_vma memaddr,
 	      && ((insn & ((-1ULL << 50) | (0x3fULL << 26)))
 		  == ((1ULL << 58) | (1ULL << 52) | (57ULL << 26)) /* pld */))
 	    {
-	      for (int i = 0; i < 2; i++)
+	      int i;
+
+	      for (i = 0; i < 2; i++)
 		if (print_got_plt (private_data (info)->special + i, d34, info))
 		  break;
 	    }