ARM-software / CMSIS_6

CMSIS version 6 (successor of CMSIS_5)
https://arm-software.github.io/CMSIS_6/
Apache License 2.0
193 stars 61 forks source link

__ARM_FEATURE_CMSE definition #63

Closed HTRamsey closed 11 months ago

HTRamsey commented 1 year ago

Where is this supposed to be defined? It pops a ton of -Wundef for me using gcc.

JonatanAntoni commented 1 year ago

This is expected to be pre-defined by the compiler once -mcmse compiler flag is used. Can you please be more specific about what version of GCC you are using and give at least examples where this gives you warnings?

HTRamsey commented 1 year ago

So in all of the core_cmx.h files it is used, it has #if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == X) however in all of the cmsis_x_m.h files in m-profile the usage isn't guarded with a #if defined.

ghost commented 1 year ago

It is ok to use a define in the following way #if (__ARM_FEATURE_CMSE == 3) without a #if defined guard because the compiler will use value 0 for the macro if it is not defined.

ReinhardKeil commented 1 year ago

Maybe it would be a good idea to use in the header file a construct that hints the usage of the -mcmse compiler flag. For example:

#if (!defined(__ARM_FEATURE_CMSE))
#warning "CMSE extensions are not enabled. Use compiler option: -mcmse"
#endif
JonatanAntoni commented 1 year ago

Maybe it would be a good idea to use in the header file a construct that hints the usage of the -mcmse compiler flag. For example:

This won't work. The flag -mcmse is only used when targeting secure mode but not for non-secure mode. The define __ARM_FEATURE_CMSE is used to detect which mode we compile for.

It is ok to use a define in the following way #if (__ARM_FEATURE_CMSE == 3) without a #if defined guard because the compiler will use value 0 for the macro if it is not defined.

While this is true, the GNU C Preprocessor docs has the following:

The -Wundef option causes GCC to warn whenever it encounters an identifier which is not a macro in an ‘#if’.

@holden-zenith, would you raise a contribution changing all the #if statements so that they don't cause you warnings for you?

ReinhardKeil commented 1 year ago

Change it a bit. Would this cause a warning?

#if (defined(__ARM_FEATURE_CMSE) &&  (__ARM_FEATURE_CMSE == 3))
JonatanAntoni commented 1 year ago

Preprocessor statements like #if <MACRO> are causing -Wundef warnings once the used <MACRO> is not defined. Hence, we need to use #if defined(<MACRO>) && <MACRO> instead.

JonatanAntoni commented 11 months ago

Relates to #79.

@holden-zenith, I think we can conclude that we should not rely on undefined macros implicitly expanding to 0 if used in an expression.

Can we close this one?

ReinhardKeil commented 11 months ago

Ich denke das habt ihr gemacht mit https://github.com/ARM-software/CMSIS_6/pull/79/commits

Ich wuerde es schliessen.

From: Jonatan Antoni @.> Sent: Monday, November 27, 2023 1:38 PM To: ARM-software/CMSIS_6 @.> Cc: Reinhard Keil @.>; Comment @.> Subject: Re: [ARM-software/CMSIS_6] __ARM_FEATURE_CMSE definition (Issue #63)

Relates to #79https://github.com/ARM-software/CMSIS_6/pull/79.

@holden-zenithhttps://github.com/holden-zenith, I think we can conclude that we should not rely on undefined macros implicitly expanding to 0 if used in an expression.

Can we close this one?

— Reply to this email directly, view it on GitHubhttps://github.com/ARM-software/CMSIS_6/issues/63#issuecomment-1827756697, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AB7CSGR2HFVP365S3CT4ETDYGSCTFAVCNFSM6AAAAAA6OEIBIWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRXG42TMNRZG4. You are receiving this because you commented.Message ID: @.**@.>>

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.