Skip to contentSkip to conversation

arm: replace typeof() with __typeof__()

PATCH In review Elliott Mitchell 8 participants 10 messages Mar 9, 2021 – Mar 12, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: replace typeof() with __typeof__()

typeof() is available in Xen's build environment, which uses Xen's compiler. As these headers are public, they need strict standards conformance. Only __typeof__() is officially standardized.

A compiler in standards conformance mode should report:

warning: implicit declaration of function 'typeof' is invalid in C99 [-Wimplicit-function-declaration]

(this has been observed with FreeBSD's kernel build environment)

---
 xen/include/public/arch-arm.h | 2 +-
 xen/include/public/hvm/save.h | 4 ++--
 xen/include/public/io/ring.h  | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
xen/include/public/arch-arm.h +1 -1
index c365b1b39e..713fd65317 100644
@@ -191,7 +191,7 @@
 #define XEN_GUEST_HANDLE_PARAM(name)    __guest_handle_ ## name
 #define set_xen_guest_handle_raw(hnd, val)                  \
     do {                                                    \
-        typeof(&(hnd)) _sxghr_tmp = &(hnd);                 \
+        __typeof__(&(hnd)) _sxghr_tmp = &(hnd);             \
         _sxghr_tmp->q = 0;                                  \
         _sxghr_tmp->p = val;                                \
     } while ( 0 )
xen/include/public/hvm/save.h +2 -2
index f72e3a9bc4..bea5e9f50f 100644
@@ -82,12 +82,12 @@ struct hvm_save_descriptor {
     struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}
 #endif
 
-#define HVM_SAVE_TYPE(_x) typeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->t)
+#define HVM_SAVE_TYPE(_x) __typeof__ (((struct __HVM_SAVE_TYPE_##_x *)(0))->t)
 #define HVM_SAVE_LENGTH(_x) (sizeof (HVM_SAVE_TYPE(_x)))
 #define HVM_SAVE_CODE(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->c))
 
 #ifdef __XEN__
-# define HVM_SAVE_TYPE_COMPAT(_x) typeof (((struct __HVM_SAVE_TYPE_COMPAT_##_x *)(0))->t)
+# define HVM_SAVE_TYPE_COMPAT(_x) __typeof__ (((struct __HVM_SAVE_TYPE_COMPAT_##_x *)(0))->t)
 # define HVM_SAVE_LENGTH_COMPAT(_x) (sizeof (HVM_SAVE_TYPE_COMPAT(_x)))
 
 # define HVM_SAVE_HAS_COMPAT(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->cpt)-1)
xen/include/public/io/ring.h +1 -1
index d68615ae2f..6a94a9fe4b 100644
@@ -242,7 +242,7 @@ typedef struct __name##_back_ring __name##_back_ring_t
  */
 #define RING_COPY_REQUEST(_r, _idx, _req) do {				\
 	/* Use volatile to force the copy into _req. */			\
-	*(_req) = *(volatile typeof(_req))RING_GET_REQUEST(_r, _idx);	\
+	*(_req) = *(volatile __typeof__(_req))RING_GET_REQUEST(_r, _idx);	\
 } while (0)
 
 #define RING_GET_RESPONSE(_r, _idx)                                     \
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Elliott Mitchell

typeof() is available in Xen's build environment, which uses Xen's compiler. As these headers are public, they need strict standards conformance. Only __typeof__() is officially standardized.

A compiler in standards conformance mode should report:

Quoted 7 lines

warning: implicit declaration of function 'typeof' is invalid in C99 [-Wimplicit-function-declaration]

(this has been observed with FreeBSD's kernel build environment)

s!arm!xen/public! in the subject seeing as two thirds of the modifications are in non-ARM headers.

This wants backporting as a build fix, so should be considered for 4.15 at this point.

I wonder why our header checks don't pick this up.  Do we need to throw a -pedantic around?

Reviewed-by
#2 lore raw
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Elliott Mitchell

typeof() is available in Xen's build environment, which uses Xen's compiler. As these headers are public, they need strict standards conformance. Only __typeof__() is officially standardized.

A compiler in standards conformance mode should report:

warning: implicit declaration of function 'typeof' is invalid in C99 [-Wimplicit-function-declaration]

(this has been observed with FreeBSD's kernel build environment)

Quoted 7 lines
Quoted 2 lines

s!arm!xen/public! in the subject seeing as two thirds of the modifications are in non-ARM headers.

Quoted 2 lines

This wants backporting as a build fix, so should be considered for 4.15 at this point.

+1

#3 lore raw
In reply to Andrew Cooper
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Elliott Mitchell

typeof() is available in Xen's build environment, which uses Xen's compiler. As these headers are public, they need strict standards conformance. Only __typeof__() is officially standardized.

A compiler in standards conformance mode should report:

warning: implicit declaration of function 'typeof' is invalid in C99 [-Wimplicit-function-declaration]

Quoted 7 lines
Quoted 4 lines

(this has been observed with FreeBSD's kernel build environment)

s!arm!xen/public! in the subject seeing as two thirds of the modifications are in non-ARM headers.

Gah! Crucial little detail missing when rewriting the subject line. Julien Grall's original patch/commit only did ARM, but when I checked I found the other two and I did them too.

Quoted 7 lines

This wants backporting as a build fix, so should be considered for 4.15 at this point.

I wonder why our header checks don't pick this up.?? Do we need to throw a -pedantic around?

This came up since FreeBSD's kernel build uses Clang with -std=iso9899:1999. When I found FreeBSD was simply copying Xen's headers it was clear this needed to be *here*.

Signature · 4 lines
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         [email protected]  PGP 87145445         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
#4 lore raw
Quoted 29 lines · Elliott Mitchell
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Elliott Mitchell

typeof() is available in Xen's build environment, which uses Xen's compiler. As these headers are public, they need strict standards conformance. Only __typeof__() is officially standardized.

A compiler in standards conformance mode should report:

warning: implicit declaration of function 'typeof' is invalid in C99 [-Wimplicit-function-declaration]

Quoted 7 lines
Quoted 4 lines

(this has been observed with FreeBSD's kernel build environment)

s!arm!xen/public! in the subject seeing as two thirds of the modifications are in non-ARM headers.

Gah! Crucial little detail missing when rewriting the subject line. Julien Grall's original patch/commit only did ARM, but when I checked I found the other two and I did them too.

Quoted 5 lines

This wants backporting as a build fix, so should be considered for 4.15 at this point.

Quoted 6 lines
Quoted 2 lines

I wonder why our header checks don't pick this up.?? Do we need to throw a -pedantic around?

This came up since FreeBSD's kernel build uses Clang with -std=iso9899:1999. When I found FreeBSD was simply copying Xen's headers it was clear this needed to be *here*.

FTR this was never spotted on x86 because we don't make use of any of the macros that use typeof in the kernel. Arm OTOH has a typeof in set_xen_guest_handle_raw which is used by kernel code.

Thanks for fixing those.

Thanks, Roger.

#5 lore raw
In reply to Andrew Cooper
Quoted 18 lines · Andrew Cooper
Quoted 6 lines · Elliott Mitchell

typeof() is available in Xen's build environment, which uses Xen's compiler. As these headers are public, they need strict standards conformance. Only __typeof__() is officially standardized.

A compiler in standards conformance mode should report:

Quoted 7 lines

warning: implicit declaration of function 'typeof' is invalid in C99 [-Wimplicit-function-declaration]

(this has been observed with FreeBSD's kernel build environment)

s!arm!xen/public! in the subject seeing as two thirds of the modifications are in non-ARM headers.

Quoted 7 lines

This wants backporting as a build fix, so should be considered for 4.15 at this point.

I wonder why our header checks don't pick this up.  Do we need to throw a -pedantic around?

That's a long-standing issue with the checking: For issues to be found in macros, the macros would actually need to be used.

Jan

#6 lore raw

Jan Beulich writes ("Re: [PATCH for-4.15] arm: replace typeof() with __typeof__()"):

Quoted 3 lines · Andrew Cooper
Quoted 2 lines

This wants backporting as a build fix, so should be considered for 4.15 at this point.

Ian.

#7 lore raw

Hi,

Quoted 6 lines · Ian Jackson

Jan Beulich writes ("Re: [PATCH for-4.15] arm: replace typeof() with __typeof__()"):

Quoted 3 lines · Andrew Cooper
Quoted 2 lines

This wants backporting as a build fix, so should be considered for 4.15 at this point.

Thanks! I have committed the patch now.

Cheers,

Signature · 1 line
Julien Grall
#8 lore raw
In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper

I wonder why our header checks don't pick this up.?? Do we need to throw a -pedantic around?

That's a long-standing issue with the checking: For issues to be found in macros, the macros would actually need to be used.

This is key since only the hunk for xen/include/public/arch-arm.h was found during a build. The other two hunks were found while preparing to submit this to the Xen Project since I checked for other occurrences of typeof(). Had I not spent the time to look, the other three uses might have generated 2-3 additional patches in the future.

Also notable the ARM portion was originally found more than 5 years ago (between 4.2 and 4.6), so this had been lurking for a long time.

Signature · 4 lines
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         [email protected]  PGP 87145445         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
Reviewed-by on v1 1/1
#9 lore raw
In reply to Elliott Mitchell
Quoted 6 lines · Elliott Mitchell

typeof() is available in Xen's build environment, which uses Xen's compiler. As these headers are public, they need strict standards conformance. Only __typeof__() is officially standardized.

A compiler in standards conformance mode should report:

Quoted 7 lines

warning: implicit declaration of function 'typeof' is invalid in C99 [-Wimplicit-function-declaration]

(this has been observed with FreeBSD's kernel build environment)

Juergen