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 = \