linux-toolchains.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Borislav Petkov <bp@alien8.de>
Cc: linux-toolchains@vger.kernel.org, Michael Matz <matz@suse.de>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: older gccs and case labels producing integer constants
Date: Tue, 5 Apr 2022 12:06:45 +0200 (CEST)	[thread overview]
Message-ID: <onrq8p1-582o-6rs9-r682-rs9sqoq7sq6p@fhfr.qr> (raw)
In-Reply-To: <7o5nn52-nqn1-oo13-s6o9-59r85r91o768@fhfr.qr>

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

On Tue, 5 Apr 2022, Richard Biener wrote:

> On Tue, 5 Apr 2022, Borislav Petkov wrote:
> 
> > Hi folks,
> > 
> > I'm starting to see failures like this on allmodconfig builds:
> > 
> > sound/usb/midi.c: In function ‘snd_usbmidi_out_endpoint_create’:
> > sound/usb/midi.c:1389:2: error: case label does not reduce to an integer constant
> >   case (((0xfc08) << 16) | (0x0101)):
> >   ^~~~
> > 
> > (The case statement is a macro but it evaluates to what I have there)
> > 
> > and that thing fails with
> > 
> > $ gcc --version
> > gcc (SUSE Linux) 7.5.0
> > 
> > although it doesn't have any problems building with newer compilers.
> > 
> > I'm presuming older gccs consider those case statements signed ints and
> > the following fixes it:
> > 
> >   case ((((unsigned int)0xfc08) << 16) | (0x0101)):
> > 
> > and I guess we can whack the couple of occurrences but what I'm
> > wondering is why does this work with newer gccs?
> 
> I tried
> 
> void foo (int i)
> {
>   switch (i)
>     {
>       case (((0xfc08) << 16) | (0x0101)):;
>     }
> }
> 
> also with 'unsigned int i' but that's accepted with GCC 7.  So
> what do you switch on?

Aha, also

> gcc-7 -S t.c -std=c11 -pedantic -pedantic-errors
t.c: In function 'foo':
t.c:6:7: error: case label is not an integer constant expression 
[-Wpedantic]
       case USB_ID(0xfc08, 0x0101):;
       ^~~~

aber _nur_ mit -std=c11 (oder c99, aber nicht c89) und -pedantic 
-pedantic-errors.

#define USB_ID(v,p) (((v)<<16)|(p))
void foo (unsigned int *i)
{
  switch (*i)
    {
      case USB_ID(0xfc08, 0x0101):;
    }
}

Wird auch mit gcc 11 rejected.  Kanns sein dass mit gcc 7 andere
compiler flags genommen werden?

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)

  parent reply	other threads:[~2022-04-05 11:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-05  9:50 older gccs and case labels producing integer constants Borislav Petkov
2022-04-05  9:58 ` Richard Biener
2022-04-05 10:04   ` Borislav Petkov
2022-04-05 10:06   ` Richard Biener [this message]
2022-04-05 10:36     ` Borislav Petkov
2022-04-05 10:45       ` Borislav Petkov
2022-04-05 11:41         ` Richard Biener
2022-04-07 15:16           ` Borislav Petkov
2022-04-05 11:37       ` Richard Biener
2022-04-06  9:53       ` Jakub Jelinek
2022-04-06 10:04         ` Jakub Jelinek
2022-04-05 12:23 ` Peter Zijlstra
2022-04-05 12:39   ` Michael Matz
2022-04-05 12:53     ` Richard Biener
2022-04-05 13:04       ` Borislav Petkov
2022-04-06 10:13   ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=onrq8p1-582o-6rs9-r682-rs9sqoq7sq6p@fhfr.qr \
    --to=rguenther@suse.de \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=matz@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).