2021-09-11 12:20:02

by kernel test robot

[permalink] [raw]
Subject: drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 926de8c4326c14fcf35f1de142019043597a4fac
commit: 84f969e1c48ed3825986e91a0786e363d57f69d1 IB/qib: Fix null pointer subtraction compiler warning
date: 3 days ago
config: x86_64-randconfig-a014-20210911 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 261cbe98c38f8c1ee1a482fe76511110e790f58a)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=84f969e1c48ed3825986e91a0786e363d57f69d1
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 84f969e1c48ed3825986e91a0786e363d57f69d1
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression
QIB_DIAGC_ATTR(rc_resends);
^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/qib/qib_sysfs.c:406:16: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
^~~~
drivers/infiniband/hw/qib/qib_sysfs.c:413:1: note: cannot access field of null pointer
drivers/infiniband/hw/qib/qib_sysfs.c:406:43: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
^
drivers/infiniband/hw/qib/qib_sysfs.c:414:1: error: static_assert expression is not an integral constant expression
QIB_DIAGC_ATTR(seq_naks);
^~~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/qib/qib_sysfs.c:406:16: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
^~~~
drivers/infiniband/hw/qib/qib_sysfs.c:414:1: note: cannot access field of null pointer
drivers/infiniband/hw/qib/qib_sysfs.c:406:43: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
^
drivers/infiniband/hw/qib/qib_sysfs.c:415:1: error: static_assert expression is not an integral constant expression
QIB_DIAGC_ATTR(rdma_seq);
^~~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/qib/qib_sysfs.c:406:16: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
^~~~
drivers/infiniband/hw/qib/qib_sysfs.c:415:1: note: cannot access field of null pointer
drivers/infiniband/hw/qib/qib_sysfs.c:406:43: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
^
drivers/infiniband/hw/qib/qib_sysfs.c:416:1: error: static_assert expression is not an integral constant expression
QIB_DIAGC_ATTR(rnr_naks);
^~~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/qib/qib_sysfs.c:406:16: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
^~~~
drivers/infiniband/hw/qib/qib_sysfs.c:416:1: note: cannot access field of null pointer
drivers/infiniband/hw/qib/qib_sysfs.c:406:43: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
^
drivers/infiniband/hw/qib/qib_sysfs.c:417:1: error: static_assert expression is not an integral constant expression
QIB_DIAGC_ATTR(other_naks);
^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/qib/qib_sysfs.c:406:16: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
^~~~
drivers/infiniband/hw/qib/qib_sysfs.c:417:1: note: cannot access field of null pointer
drivers/infiniband/hw/qib/qib_sysfs.c:406:43: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
^
drivers/infiniband/hw/qib/qib_sysfs.c:418:1: error: static_assert expression is not an integral constant expression
QIB_DIAGC_ATTR(rc_timeouts);
^~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/qib/qib_sysfs.c:406:16: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
^~~~
drivers/infiniband/hw/qib/qib_sysfs.c:418:1: note: cannot access field of null pointer
drivers/infiniband/hw/qib/qib_sysfs.c:406:43: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
^
drivers/infiniband/hw/qib/qib_sysfs.c:419:1: error: static_assert expression is not an integral constant expression
QIB_DIAGC_ATTR(loop_pkts);
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/qib/qib_sysfs.c:406:16: note: expanded from macro 'QIB_DIAGC_ATTR'
static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \


vim +413 drivers/infiniband/hw/qib/qib_sysfs.c

f24a6d4887668c Harish Chegondi 2016-01-22 404
4a7aaf88c89f12 Jason Gunthorpe 2021-06-11 405 #define QIB_DIAGC_ATTR(N) \
84f969e1c48ed3 Jason Gunthorpe 2021-09-03 406 static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
f24a6d4887668c Harish Chegondi 2016-01-22 407 static struct qib_diagc_attr qib_diagc_attr_##N = { \
4a7aaf88c89f12 Jason Gunthorpe 2021-06-11 408 .attr = __ATTR(N, 0664, diagc_attr_show, diagc_attr_store), \
84f969e1c48ed3 Jason Gunthorpe 2021-09-03 409 .counter = \
84f969e1c48ed3 Jason Gunthorpe 2021-09-03 410 offsetof(struct qib_ibport, rvp.n_##N) / sizeof(u64) \
f931551bafe1f1 Ralph Campbell 2010-05-23 411 }
f931551bafe1f1 Ralph Campbell 2010-05-23 412
f931551bafe1f1 Ralph Campbell 2010-05-23 @413 QIB_DIAGC_ATTR(rc_resends);
f931551bafe1f1 Ralph Campbell 2010-05-23 414 QIB_DIAGC_ATTR(seq_naks);
f931551bafe1f1 Ralph Campbell 2010-05-23 415 QIB_DIAGC_ATTR(rdma_seq);
f931551bafe1f1 Ralph Campbell 2010-05-23 416 QIB_DIAGC_ATTR(rnr_naks);
f931551bafe1f1 Ralph Campbell 2010-05-23 417 QIB_DIAGC_ATTR(other_naks);
f931551bafe1f1 Ralph Campbell 2010-05-23 418 QIB_DIAGC_ATTR(rc_timeouts);
f931551bafe1f1 Ralph Campbell 2010-05-23 419 QIB_DIAGC_ATTR(loop_pkts);
f931551bafe1f1 Ralph Campbell 2010-05-23 420 QIB_DIAGC_ATTR(pkt_drops);
f931551bafe1f1 Ralph Campbell 2010-05-23 421 QIB_DIAGC_ATTR(dmawait);
f931551bafe1f1 Ralph Campbell 2010-05-23 422 QIB_DIAGC_ATTR(unaligned);
f931551bafe1f1 Ralph Campbell 2010-05-23 423 QIB_DIAGC_ATTR(rc_dupreq);
f931551bafe1f1 Ralph Campbell 2010-05-23 424 QIB_DIAGC_ATTR(rc_seqnak);
7199435414868b Kaike Wan 2019-09-11 425 QIB_DIAGC_ATTR(rc_crwaits);
f931551bafe1f1 Ralph Campbell 2010-05-23 426

:::::: The code at line 413 was first introduced by commit
:::::: f931551bafe1f10ded7f5282e2aa162c267a2e5d IB/qib: Add new qib driver for QLogic PCIe InfiniBand adapters

:::::: TO: Ralph Campbell <[email protected]>
:::::: CC: Roland Dreier <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (11.05 kB)
.config.gz (39.52 kB)
Download all attachments

2021-09-14 00:44:53

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression

On Sat, Sep 11, 2021 at 08:17:08PM +0800, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 926de8c4326c14fcf35f1de142019043597a4fac
> commit: 84f969e1c48ed3825986e91a0786e363d57f69d1 IB/qib: Fix null pointer subtraction compiler warning
> date: 3 days ago
> config: x86_64-randconfig-a014-20210911 (attached as .config)
> compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 261cbe98c38f8c1ee1a482fe76511110e790f58a)
> reproduce (this is a W=1 build):
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=84f969e1c48ed3825986e91a0786e363d57f69d1
> git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> git fetch --no-tags linus master
> git checkout 84f969e1c48ed3825986e91a0786e363d57f69d1
> # save the attached .config to linux build tree
> mkdir build_dir
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=x86_64 SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <[email protected]>
>
> All errors (new ones prefixed by >>):
>
> >> drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression
> QIB_DIAGC_ATTR(rc_resends);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/infiniband/hw/qib/qib_sysfs.c:406:16: note: expanded from macro 'QIB_DIAGC_ATTR'
> static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
> ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
> #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
> ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
> include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
> #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
> ^~~~
> drivers/infiniband/hw/qib/qib_sysfs.c:413:1: note: cannot access field of null pointer
> drivers/infiniband/hw/qib/qib_sysfs.c:406:43: note: expanded from macro 'QIB_DIAGC_ATTR'
> static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
> ^
> drivers/infiniband/hw/qib/qib_sysfs.c:414:1: error: static_assert expression is not an integral constant expression
> QIB_DIAGC_ATTR(seq_naks);
> ^~~~~~~~~~~~~~~~~~~~~~~~

Nick/Nathan

Clang is being a real PITA here - do you know of a solution?

This macro would like to know that the passed in member name has a u64
type, all the things I've come up with fail on clang - but many work
fine on gcc. Frankly I think this case is a clang bug myself..

Thanks,
Jason

2021-09-14 00:45:13

by Nick Desaulniers

[permalink] [raw]
Subject: Re: drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression

On Mon, Sep 13, 2021 at 9:53 AM Jason Gunthorpe <[email protected]> wrote:
>
> On Sat, Sep 11, 2021 at 08:17:08PM +0800, kernel test robot wrote:
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head: 926de8c4326c14fcf35f1de142019043597a4fac
> > commit: 84f969e1c48ed3825986e91a0786e363d57f69d1 IB/qib: Fix null pointer subtraction compiler warning
> > date: 3 days ago
> > config: x86_64-randconfig-a014-20210911 (attached as .config)
> > compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 261cbe98c38f8c1ee1a482fe76511110e790f58a)
> > reproduce (this is a W=1 build):
> > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> > chmod +x ~/bin/make.cross
> > # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=84f969e1c48ed3825986e91a0786e363d57f69d1
> > git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> > git fetch --no-tags linus master
> > git checkout 84f969e1c48ed3825986e91a0786e363d57f69d1
> > # save the attached .config to linux build tree
> > mkdir build_dir
> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=x86_64 SHELL=/bin/bash
> >
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot <[email protected]>
> >
> > All errors (new ones prefixed by >>):
> >
> > >> drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression
> > QIB_DIAGC_ATTR(rc_resends);
> > ^~~~~~~~~~~~~~~~~~~~~~~~~~
> > drivers/infiniband/hw/qib/qib_sysfs.c:406:16: note: expanded from macro 'QIB_DIAGC_ATTR'
> > static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
> > ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
> > #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
> > ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
> > include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
> > #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
> > ^~~~
> > drivers/infiniband/hw/qib/qib_sysfs.c:413:1: note: cannot access field of null pointer
> > drivers/infiniband/hw/qib/qib_sysfs.c:406:43: note: expanded from macro 'QIB_DIAGC_ATTR'
> > static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
> > ^
> > drivers/infiniband/hw/qib/qib_sysfs.c:414:1: error: static_assert expression is not an integral constant expression
> > QIB_DIAGC_ATTR(seq_naks);
> > ^~~~~~~~~~~~~~~~~~~~~~~~
>
> Nick/Nathan
>
> Clang is being a real PITA here - do you know of a solution?

Hi Jason,
Thanks for wrestling with this. We filed a quick thread last week to
track this:
https://github.com/ClangBuiltLinux/linux/issues/1452
With conferences this and next week, and -Werror fallout, there's a
lot of fire right now and not a lot of time to triage.

I guess I'm curious, what is the intent of what this code is trying to
do, and can this be replaced with BUILD_BUG_ON?

>
> This macro would like to know that the passed in member name has a u64
> type, all the things I've come up with fail on clang - but many work
> fine on gcc. Frankly I think this case is a clang bug myself..

Perhaps, though this assertion looks a bit like offsetof() to me. I
wonder if that can help here?
--
Thanks,
~Nick Desaulniers

2021-09-14 00:56:23

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression

On Mon, Sep 13, 2021 at 10:00:02AM -0700, Nick Desaulniers wrote:

> > This macro would like to know that the passed in member name has a u64
> > type, all the things I've come up with fail on clang - but many work
> > fine on gcc. Frankly I think this case is a clang bug myself..
>
> Perhaps, though this assertion looks a bit like offsetof() to me. I
> wonder if that can help here?

The assertion would logically like to be this:

static_assert(typecheck(((struct qib_port *)0)->N, u64))

Which doesn't compile because typecheck is not a constexpr :\

typecheck also can't be used as a build bug on zero in the initializer
for the same reason.

My original attempt was

.counter = &((struct qib_ibport *)0)->rvp.n_##N - (u64 *)0, \

Which is fairly simple opencoding of offsetof_end but clang whines
overly pedantically that NULL subtraction is undefined behavior.

The current version is this:

static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL);

Which *should* be perfectly fine, but clang explodes for some reason
complaining about -> on NULL. I think it is broken and doesn't
understand that this -> is not an actual deref but pointer/type logic,
much like this:

#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))

Which does work.

So to my mind clang is being buggy, and I'm probably going to just
delete the line and a give up on type checking here unless someone has
a better idea.

Jason

2021-09-14 00:56:31

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression

On Mon, Sep 13, 2021 at 11:53:25AM -0700, Nathan Chancellor wrote:
> On Mon, Sep 13, 2021 at 03:38:13PM -0300, Jason Gunthorpe wrote:
> > On Mon, Sep 13, 2021 at 10:00:02AM -0700, Nick Desaulniers wrote:
> >
> > > > This macro would like to know that the passed in member name has a u64
> > > > type, all the things I've come up with fail on clang - but many work
> > > > fine on gcc. Frankly I think this case is a clang bug myself..
> > >
> > > Perhaps, though this assertion looks a bit like offsetof() to me. I
> > > wonder if that can help here?
> >
> > The assertion would logically like to be this:
> >
> > static_assert(typecheck(((struct qib_port *)0)->N, u64))
>
> This works for me with both GCC and clang, if that is acceptable to you?
> It fails if you change one of the variables to 'u32'.

Yes, thanks. Can't say I've even heard of __same_type before :\ would
be nice if this was in typecheck.h along with the other variations of
the same idea. Presumably it is a little bit different from those
somehow?

Jason

2021-09-14 00:56:55

by Nathan Chancellor

[permalink] [raw]
Subject: Re: drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression

On 9/13/2021 12:02 PM, Jason Gunthorpe wrote:
> On Mon, Sep 13, 2021 at 11:53:25AM -0700, Nathan Chancellor wrote:
>> On Mon, Sep 13, 2021 at 03:38:13PM -0300, Jason Gunthorpe wrote:
>>> On Mon, Sep 13, 2021 at 10:00:02AM -0700, Nick Desaulniers wrote:
>>>
>>>>> This macro would like to know that the passed in member name has a u64
>>>>> type, all the things I've come up with fail on clang - but many work
>>>>> fine on gcc. Frankly I think this case is a clang bug myself..
>>>>
>>>> Perhaps, though this assertion looks a bit like offsetof() to me. I
>>>> wonder if that can help here?
>>>
>>> The assertion would logically like to be this:
>>>
>>> static_assert(typecheck(((struct qib_port *)0)->N, u64))
>>
>> This works for me with both GCC and clang, if that is acceptable to you?
>> It fails if you change one of the variables to 'u32'.
>
> Yes, thanks. Can't say I've even heard of __same_type before :\ would
> be nice if this was in typecheck.h along with the other variations of
> the same idea. Presumably it is a little bit different from those
> somehow?

Good question... commit d2c123c27db8 ("module_param: add __same_type
convenience wrapper for __builtin_types_compatible_p") introduced it so
that it could be used in commit fddd52012295 ("module_param: allow
'bool' module_params to be bool, not just int."); I am guessing that
typecheck() could not be used in those cases. Perhaps all instances of
typecheck() could be converted to __same_type()?

Do you want me to send a formal patch for that diff?

Cheers,
Nathan

2021-09-14 00:57:03

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression

On Mon, Sep 13, 2021 at 12:13:45PM -0700, Nathan Chancellor wrote:
> On 9/13/2021 12:02 PM, Jason Gunthorpe wrote:
> > On Mon, Sep 13, 2021 at 11:53:25AM -0700, Nathan Chancellor wrote:
> > > On Mon, Sep 13, 2021 at 03:38:13PM -0300, Jason Gunthorpe wrote:
> > > > On Mon, Sep 13, 2021 at 10:00:02AM -0700, Nick Desaulniers wrote:
> > > >
> > > > > > This macro would like to know that the passed in member name has a u64
> > > > > > type, all the things I've come up with fail on clang - but many work
> > > > > > fine on gcc. Frankly I think this case is a clang bug myself..
> > > > >
> > > > > Perhaps, though this assertion looks a bit like offsetof() to me. I
> > > > > wonder if that can help here?
> > > >
> > > > The assertion would logically like to be this:
> > > >
> > > > static_assert(typecheck(((struct qib_port *)0)->N, u64))
> > >
> > > This works for me with both GCC and clang, if that is acceptable to you?
> > > It fails if you change one of the variables to 'u32'.
> >
> > Yes, thanks. Can't say I've even heard of __same_type before :\ would
> > be nice if this was in typecheck.h along with the other variations of
> > the same idea. Presumably it is a little bit different from those
> > somehow?
>
> Good question... commit d2c123c27db8 ("module_param: add __same_type
> convenience wrapper for __builtin_types_compatible_p") introduced it so that
> it could be used in commit fddd52012295 ("module_param: allow 'bool'
> module_params to be bool, not just int."); I am guessing that typecheck()
> could not be used in those cases. Perhaps all instances of typecheck() could
> be converted to __same_type()?
>
> Do you want me to send a formal patch for that diff?

I think it is a reasonable thing to do if it works, but I do wonder if
they are not quite the same thing considering qualifiers/etc

$ git grep typecheck | wc -l
120
$ #git grep __same_type | wc -l
39

I would delete __same_type if typecheck can be functionally identical
otherwise I'd say this should all be in typecheck.h and the functional
difference clearly documented..

Jason

2021-09-14 01:50:34

by Nathan Chancellor

[permalink] [raw]
Subject: Re: drivers/infiniband/hw/qib/qib_sysfs.c:413:1: error: static_assert expression is not an integral constant expression

On Mon, Sep 13, 2021 at 03:38:13PM -0300, Jason Gunthorpe wrote:
> On Mon, Sep 13, 2021 at 10:00:02AM -0700, Nick Desaulniers wrote:
>
> > > This macro would like to know that the passed in member name has a u64
> > > type, all the things I've come up with fail on clang - but many work
> > > fine on gcc. Frankly I think this case is a clang bug myself..
> >
> > Perhaps, though this assertion looks a bit like offsetof() to me. I
> > wonder if that can help here?
>
> The assertion would logically like to be this:
>
> static_assert(typecheck(((struct qib_port *)0)->N, u64))

This works for me with both GCC and clang, if that is acceptable to you?
It fails if you change one of the variables to 'u32'.

Cheers,
Nathan

diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
index 452e2355d24e..0a3b28142c05 100644
--- a/drivers/infiniband/hw/qib/qib_sysfs.c
+++ b/drivers/infiniband/hw/qib/qib_sysfs.c
@@ -403,7 +403,7 @@ static ssize_t diagc_attr_store(struct ib_device *ibdev, u32 port_num,
}

#define QIB_DIAGC_ATTR(N) \
- static_assert(&((struct qib_ibport *)0)->rvp.n_##N != (u64 *)NULL); \
+ static_assert(__same_type(((struct qib_ibport *)0)->rvp.n_##N, u64)); \
static struct qib_diagc_attr qib_diagc_attr_##N = { \
.attr = __ATTR(N, 0664, diagc_attr_show, diagc_attr_store), \
.counter = \