A possible gcc bug?

David Brown david@westcontrol.com
Fri Sep 7 08:14:00 GMT 2018



On 07/09/2018 09:47, Jakub Jelinek wrote:
> On Fri, Sep 07, 2018 at 08:57:25AM +0200, David Brown wrote:
>> I am always wary of saying there might be a compiler bug - usually it is a
>> bug in the user code.  But this time I am very suspicious.  The example here
>> comes from a discussion in the comp.lang.c Usenet group.
>>
>> Here is the code I have been testing:
>>
>>
>> unsigned char foo_u(unsigned int v) {
>>      return (v & 0x7f) | (v & ~0x7f ? 0x80 : 0);
>> }
>>
>> unsigned char foo_s(int v) {
>>      return (v & 0x7f) | (v & ~0x7f ? 0x80 : 0);
>> }
> 
> Seems to have started with http://gcc.gnu.org/r134376, I'll have a look.
> That said, can you file a bug in http://gcc.gnu.org/bugzilla/ for this, that
> is where it should be tracked.

I didn't want to bother the developers with a bug report until someone 
agreed it probably is a bug, rather than my misunderstanding.  But since 
it is at least worth investigating, I've filed one now (with the typo 
fixed).

<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87248>

> 
>>
>> unsigned char bar_s(int v) {
>>      int x = v & 0x7f;
>>      return (v & 0x7f) | (x ? 0x80 : 0);
>> }
> 
> This does something different (did you mean int x = v & ~0x7f; ?).
> 

Yes.  The effect is still the same, but it helps to be accurate in bug 
reports!

> 	Jakub
> 



More information about the Gcc mailing list