Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support removal of register storage class specifier in C++17 #345

Closed
pabigot opened this issue Apr 2, 2018 · 7 comments
Closed

support removal of register storage class specifier in C++17 #345

pabigot opened this issue Apr 2, 2018 · 7 comments
Assignees

Comments

@pabigot
Copy link

pabigot commented Apr 2, 2018

Prior to C++17 the register storage class specifier was deprecated; in C++17 it has been removed, making attempts to compile with CMSIS 5.3 with gcc --std=c++17 fail. Something like the following is needed in every header that uses that feature, along with the corresponding modifications at all use-points.

#if (__cplusplus - 0) >= 201703L
  #define __REGISTER
#else
  #define __REGISTER                             register
#endif

See: http://en.cppreference.com/w/cpp/language/storage_duration

@JonatanAntoni
Copy link
Member

May I ask you to be slightly more specific, please?
Where exactly do you have this issue?

Please be aware that CMSIS itself it intended to be ANSI-C (C99) and not C++. Simply removing the storage class register from the code is not guaranteed to work. Depending on the implementation it might be required that a value is kept as a register value only.

Using CMSIS from C++ should be possible when compiling all .c files in C-Mode. Inline functions defined in header files should be compiled as extern C. Please let me know if that does not work for you.

@pabigot
Copy link
Author

pabigot commented Apr 9, 2018

As of C++17 the existing solution does not work.

CMSIS Core headers like core_cm0.h can be included into C++ source files; this is enabled through the use of the __cplusplus macro to add the required extern "C" block around the declarations. This was sufficient to allow core inline functions like NVIC_SetEnableIRQ() and structures like SCB_Type to be available to and used in C++ applications through C++14.

The change to the register storage class specifier in C++17 means this isn't possible anymore because simply including core_cm0.h into a C++ application pulls in cmsis_compiler.h which pulls in cmsis_gcc.h which declares a local register uint32_t result; which is a syntax error. The modification I suggest is required if the existing capability is to be maintained beyond C++14.

The change can probably be conditional on using C++ at an affected version (as suggested) and isolated to compiler-specific headers like cmsis_gcc.h which should instead declare __REGISTER uint32 result;. For implementation files that use register declarations in C99-compiled code I agree it's not relevant and undesirable.

Some information on the reason for the change is here. As that material indicates gcc completely ignores the register keyword unless all optimizations are explicitly disabled (the __ASM statements in CMSIS include a constraint that ensures a register is used). In practice I've had no problems with gcc-arm-none-eabi-7-2017-q4-major and --std=c++17 with this modification.

@JonatanAntoni
Copy link
Member

JonatanAntoni commented Apr 9, 2018

Thanks for the details. I can know comprehend the issues you face. Its all about the inline functions using raw assembly instructions for special function register accesses like

__STATIC_FORCEINLINE uint32_t __get_PSP(void)
{
    register uint32_t result;
    __ASM volatile ("MRS %0, psp"  : "=r" (result) );
    return(result);
}

In other function we already skipped the register keyword. To be consistent we could remove the register keyword from cmsis_gcc.h completely. The same change should apply to cmsis_armclang.h.

Is it feasible for you to provide the changes in terms of a pull request?

Thanks again for your contribution.

@pabigot
Copy link
Author

pabigot commented Apr 9, 2018

Yes, I can do a PR sometime in the next week or so. Not sure whether I'll be able to test cmsis_armclang but if not will note that in the PR.

pabigot added a commit to pabigot/CMSIS_5 that referenced this issue Apr 10, 2018
Avoid using the register storage class specifier in core headers when
compiling for C++ versions from which it has been removed, starting with
C++17.  Retain it for C and earlier C++ releases.

See: http://en.cppreference.com/w/cpp/language/storage_duration

Closes issue ARM-software#345
@FreddieChopin
Copy link
Contributor

FreddieChopin commented May 11, 2018

Alternative pull request which removes the keyword wherever possible - #365

JonatanAntoni pushed a commit that referenced this issue May 14, 2018
In C++17 `register` keyword was removed. Current gcc 8.1.0 produces
following warning if `-std=c++17` flag is used:

warning: ISO C++17 does not allow 'register' storage class specifier
[-Wregister]

GCC almost completely ignores `register` keyword, with rare exception of
`-O0` when additional copy from/to stack may be generated.

For simplicity of the codebase it is better to just remove this
problematic keyword where it is not strictly required.

See: http://en.cppreference.com/w/cpp/language/storage_duration

Closes issue #345
@JonatanAntoni
Copy link
Member

Thanks @FreddieChopin for your contribution.
May I ask you all to double check the result, please?

@pabigot
Copy link
Author

pabigot commented May 22, 2018

@JonatanAntoni @FreddieChopin The merged changes work for my application. Thanks.

@pabigot pabigot closed this as completed May 22, 2018
QIANWC added a commit to QIANWC/rt-thread that referenced this issue Mar 13, 2021
ARMCLANG编译需要修改cmbacktrace源码:
大部分defined(__CC_ARM) => defined(__CC_ARM) || defined(__CLANG_ARM)
少数保留不变,使用GNUC分支的代码(因为AC6没有AC5的__asm)
c++11需要增加编译指令-Wno-deprecated-register
c++17需要去掉register修饰符(添加extern "C"未能解决),关于register修饰符的问题:ARM-software/CMSIS_5#345
SConscript去掉AC6不支持的--c99。
env工具不自带addr2line工具,需要从cmbacktrace官方仓库下载。
如果使用ULOG则一定要启用ULOG_USING_ISR_LOG,否则fault中断无法输出内容。
JiafeiPan pushed a commit to nxp-mcuxpresso/CMSIS_5 that referenced this issue Aug 8, 2023
In C++17 `register` keyword was removed. Current gcc 8.1.0 produces
following warning if `-std=c++17` flag is used:

warning: ISO C++17 does not allow 'register' storage class specifier
[-Wregister]

GCC almost completely ignores `register` keyword, with rare exception of
`-O0` when additional copy from/to stack may be generated.

For simplicity of the codebase it is better to just remove this
problematic keyword where it is not strictly required.

See: http://en.cppreference.com/w/cpp/language/storage_duration

Closes issue ARM-software#345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants