-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Set compilers to C++14 and C11 #10427
Conversation
@kjbracey-arm, thank you for your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very very exciting!!!
Do you know what this does to code size?
@@ -183,7 +183,7 @@ def format_flags(self): | |||
flags['c_flags'] + flags['cxx_flags'] + flags['common_flags'] | |||
) | |||
in_template = set( | |||
["--no_vla", "--cpp", "--c99", "-MMD"] + config_option | |||
["--no_vla", "--cpp", "--cpp11", "--c99", "-MMD"] + config_option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the --cpp
and --cpp11
flags exclusive in this case?
["--no_vla", "--cpp", "--cpp11", "--c99", "-MMD"] + config_option | |
["--no_vla", "--cpp11", "--c99", "-MMD"] + config_option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reading of that was that that was just a list of options that would be eligible for passthrough in the code below. Can you check?
In which case both --cpp
and --cpp11
want this behaviour, in case anyone wants to switch profile back to old version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was that that was
PS Don't report me to tech authors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh gosh you're totally right, good eye! In my defense, I have not finished my first cup of coffee this morning 😄
Nothing on its own, hopefully. Possibly might end up activating a few more Once it's on and we start writing C++14-requiring code there will be language constructs like |
Understood, though I think it'd be worth it to do a basic comparison with blinky or something as a sanity check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work!
Note to self: when this goes in and we make a corresponding tools release, we'll need to update the online compiler. |
@@ -6,7 +6,7 @@ | |||
<Compile> | |||
<Option name="OptimizationLevel" value="4"/> | |||
<Option name="UseFPU" value="0"/> | |||
<Option name="UserEditCompiler" value="-fno-common; -fmessage-length=0; -Wall; -fno-strict-aliasing; -fno-rtti; -fno-exceptions; -ffunction-sections; -fdata-sections; -std=gnu++98"/> | |||
<Option name="UserEditCompiler" value="-fno-common; -fmessage-length=0; -Wall; -fno-strict-aliasing; -fno-rtti; -fno-exceptions; -ffunction-sections; -fdata-sections; -std=gnu++14"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: How do we differentiate Armc5 / Armc6 profiles in exporters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, but not sure I understand the question. This template must be for GCC or ARMC6, as -std
is an option only for them.
There may be further exporter changes required for toolchains where the standard is specified via an XML option, which may not be visible on my search.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I thought this was default template for uVision didn;t see coide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deepika's right though, we'll need to update the uvision template a bit more to play nicely with the C++ and C version. The language versions are selected by the IDE GUI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, if it doesn't inflate the size (please check couple of examples manually, as I can't see the code size checks run in the PR). Also that should go for 5.13 not a patch release.
These two lines control the language versions for uvision: https://github.com/ARMmbed/mbed-os/blob/master/tools/export/uvision/uvision.tmpl#L372-L373 The corresponding diff to go from gnu99 and gnu++98 to gnu11 and gnu++14 is as follows: - <v6Lang>4</v6Lang>
- <v6LangP>2</v6LangP>
+ <v6Lang>6</v6Lang>
+ <v6LangP>6</v6LangP> We'd need to make this conditional based on the |
ARMC6 blinky showed ROM -4, RAM +8 - not sure whether there was anything real there or just padding shifting. GCC blinky shows ROM +8. ROM increase in GCC is coming from passing object sizes to delete operator in destructors, eg:
Instead of:
New |
Does it need to be conditional? How much do we want to support retro-version language profiles? To the extent of "they'll probably work if you mess with the settings manually" or "we'll support old versions by making sure exporters and online compiler let you select old versions smoothly"? Old language versions will be working for basically one release (5.13?) - the one where we haven't had time to start using the new language features, so not sure it's worth having too much polish. |
Conditional or not does not really matter, (fine with any approach duplicate template file or python script updating the correct values) we just need to make sure the correct flags are set for uVision5 and uVision6 exporters |
So you mean conditional on "ARMC5 or ARMC6", got it. I was reading that as conditional on "what language standard the JSON profile said", which seemed overkill. Well, in that uVision case, that But then where does the setting for ARMC5 C++11 go? Does it have an XML tag, or does it have to go in as a misc option? |
@team-embeddedPlanet |
uVision exporter may be an issue - it doesn't have an ARMC5 option for C++11, and doesn't have an ARMC6 option for "gnu++14". Can't just put them into the misc options, as the misc options go to both C and C++, and it gets narked. Exporter may have to lag behind until IDEs catch up. |
tools/export/uvision/uvision.tmpl
Outdated
<v6Lang>4</v6Lang> | ||
<v6LangP>2</v6LangP> | ||
<v6Lang>6</v6Lang> | ||
<v6LangP>4</v6LangP> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The uvision template change has to be conditional because the online compiler needs to be able to export older projects that cannot use the newer language standards. The online compiler will use the latest copy of the tools but switch the profiles accordingly so the correct language version is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworked to parse the -std
option. And I realised that we can actually work around uVision not knowing about gnu++14
- it's armclang's default and we can ask for <default>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except that workaround doesn't seem to work. Contrary to uVision documentation, if you put <default>
in, it explicitly selects -std=gnu11
for C and -std=gnu++89
for C++.
(Those were the defaults for Compiler 6.9, I guess, but the documentation clearly says that it will use the compiler default by not passing an option).
f08ddae
to
5538e73
Compare
What's the situation with other exporters, w.r.t. being adaptive for old Mbed OS profiles? |
@bridadan Could you please re-review ? |
The earlier commit takes the approach of extracting the This new commit redoes that and actually passes the Does this seem reasonable? If it works, it does avoid the GUI/IDE limitations. |
@kjbracey-arm Interesting strategy. However, what does that mean for the GUI option? Is it ignored/overridden? In general, I've been under the impression that people export to uVision specifically because they want to use the GUI options vs modifying command line flags. |
@kjbracey-arm if we don't have an immediate path forward on the uvision exporter it could always be revisited in a follow up PR |
* ARMC6 and GCC are set to C++14 and C11. * ARMC5 is set to C++11 and C99, as it's the highest it can offer.
This is limited to ARMC6 because as of µVision V5.27 you can't set C++11 for ARMC5. Also current µVision does not support gnu++14. We should be able to get is as `<default>`, as it is the default for ARM Compiler 6.10-6.12, but this option does not work as documented and actually requests gnu++89 explicitly. So gnu++14 is mapped to gnu++11.
Clang warns about reserved user-defined literals by default. This warning is not terribly helpful; compilers aren't normally in the habit of warning about use of reserved identifiers. It can interfere with, for example, deliberate emulation of a future standard language feature. The warning was promoted to an error in an mbed client build, due to a non-C++11 "%s"name occurring in a macro. But the macro itself was never invoked, so the misinterpretation as C++11 caused no problems other than this warning. Killing the warning will let that code build on ARMC6. The code already built on GCC and IAR. If that macro ever was used, then a separate error about operator "" name not being defined would be generated, on all 3 toolchains.
CI restarted |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Tests passed, needs finalizing reviews! |
This should be now ready for integration |
@kjbracey-arm [DEBUG] Output: ./targets/TARGET_STM/TARGET_STM32L4/device\stm32l4xx_ll_usart.h:1959:3: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register] How shall we cope with this ? |
You can ignore it for now, as we're not actually compiling C++17. But the The fix is just to remove the The only case it does do something I'm aware of is the "named register" construct in the ARM Compiler (5 and 6): I guess we could add |
Thanks @kjbracey-arm for adding migration section 👍 |
Description
Pull request type
Release Notes
Migration notes
As the default profiles now select C++14 and C11 for GCC and ARM toolchains, some applications may fail to compile because they use constructs that were valid in C++98, but not in C++14.
IAR 8 has always operated in C++14/C11 mode, so there are no new changes for IAR users who switched to IAR 8 for Mbed OS 5.12, but these notes apply for users migrating from older Mbed OS versions that used IAR 7.
Common compatibility issues
printf
formatsWithout the space, C++11 interprets it as being a request for a user-defined "PRIu32-type" string literal.
These changes should be easy to make to existing codebases. A guide to other possible breakages in C++11 can be found at https://stackoverflow.com/questions/6399615/what-breaking-changes-are-introduced-in-c11. C++14 and C11 cause few extra issues.
Future compatibility issues
register
keyword is deprecated in C++14, and is removed in C++17. Some compilers issue warnings forregister
use in C++14, but this has been temporarily suppressed due to the prevalence of the keyword in target code. C++ code should be updated to remove the keyword as soon as possible - the warning will be reactivated once Mbed OS itself no longer triggers it.Fallback
Mbed OS 5.13 releases should still work if compiled as C++98/C99, although this is not tested - if you have serious application compatibility issues, you should be able to switch the build profile back to the earlier language version as a temporary measure. This is likely to no longer be the case for Mbed OS 5.14.
ARM Compiler 5
Note also that ARM Compiler 5 has limited C++11 support and no C++14 or C11 support, and ARM Compiler 5 is no longer tested or officially supported. Nevertheless, ARMC5 builds have not been deliberately broken; ARMC5 build profiles select its C++11 mode in an attempt to match the other toolchains as much as possible, but the limited support may itself cause issues - attempts to check
__cplusplus >= 201103
may activate code that ARMC5 cannot actually compile. Like the other toolchains, the profile can be switched back to C++98 if necessary for now.Continued ARM C 5 support will limit the adoption of C++11 and C++14 features in the Mbed OS codebase, so it is quite possible that ARM Compiler 5 builds may stop working altogether in an upcoming release.