-
Notifications
You must be signed in to change notification settings - Fork 108
Be consistent checking c standard in assert.h (#527) #528
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
base: master
Are you sure you want to change the base?
Conversation
Assert header is split into two to handle the idempotency since commit b3260c2 "17491 assert(3c) prototype visibility". The macro is in one and the prototype for the internal function in the other. There are different variants for pre-c99 and c99 and the macro and prototype needs to match. The aforementioned commit changed the prototype to use "_STDC_C99" while the macro is using "__STDC_VERSION__". Normally _STDC_C99 and __STDC_VERSION__ would match and this wouldn't be a problem. As sys/feature_tests.h sets _STD_C99 based on __STDC_VERSION__ value. However the gcc10 compiler is patched to set _STD_C99 as a predefined macro for C++ code. TritonDataCenter/pkgsrc-extra@e295cdb This caused using assert from c++ code to fail because the macro expanded a function that there was no proto type for.
9730940 to
abec48f
Compare
|
This should be an illumos-gate bug. I'll build SmartOS with this, but I'm worried that while it fixes your case, it might regress something somewhere else. I'm sppinning builds for overnight (all four of {default,debug} x {gcc10,gcc14}). If they build, I'd recommend skipping here and getting this straight into illumos-gate, with more eyes, including the folks behind illumos#17491, looking at it. If you've never file a bug for -gate, it's not like here where you can PR. I'll help you with the process if we need to go that way. |
|
@wanders the way I read the pkgsrc patch is that it sets the corresponding _STDC_VERSION to something that is at least C99. So what value of |
|
@rmustacc it's the opposite, I remove I wasn't aware of any fallout from this (my bulk builds only showed positive improvements), so if this change is acceptable to illumos I'd like to also see the main illumos gccs also integrate this patch. |
I did a "make live" in smartos-live with this patch and it built. And then did make live inside a system running the produced image. Not sure that is a comprehensive test, or even valid.. I've never filed a bug there (I just started playing around with illumos/smartos last week), so I'd appreciate any help there. The process seems to me a bit more involved than just throwing up an PR like here, which is why I started here.
I might be missing something (reading diffs of patches always is confusing), but as I read it the commit TritonDataCenter/pkgsrc-extra@e295cdb removes Which matches the commit message "Switch to _STDC_C99/_STDC_C11" I had more details in the corresponding github issue: #527 The predefined macros there are:
Yes, I added that include because I'm used to making sure each header includes what that header needs, not assuming things are pulled in by other. Maybe that is not practise here? Maybe the proper fix is to not use |
I guess all pkgsrc builds all packages in "release mode", i.e with NDEBUG defined such that the To trigger the issue one must build without NDEBUG set. |
|
Thanks for the follow up here, @wanders and @jperkin. Apologies for misreading the patch and missing #527. I can definitely agree that what we have here is inconsistent and problematic. @wanders How did you pick C++11 as the defining point for the cutover. I'm having trouble determining when C++ nominally had support for the
Well, our other bulk build testing was with something without the patch, though it also doesn't set I'm pretty uncomfortable with defining the internal macros like this from the compiler as that's only going to create more flag days, but I definitely get the context and desire here. I can definitely see how it causes software problems to declare a
I think what I'm tempted to put together is something that says we should just always use the C99 version in all C++ code based on the per-processor support assuming my test is correct. That should be fairly low risk and then we come back and address the compiler inconsistencies and how we should be taking a C++ version and translating it into features. In an ideal world that might let us drop that portion of the patches entirely. |
As I understand it the c99 check is there for In pre-c99 the c++11 introduced
I can't really comment on whether the compiler should predefine the And I have not tried to investigate what the headers use But from my limited perspective it would seem like it would be better to set them from headers, rather than magically in compiler, like: The _STDC_C99 macro is documented as only for internal use in system headers, so doesn't seem clean that the compiler is messing with them. But nevertheless, the thing in assert doesn't seem quite right. Here is a variant changing the assert headers to only use standard defines for both C and C++ |
Ah, thanks. That makes sense then.
Yeah, I agree that I screwed that up and they should be a single condition. If you're okay with it, I'll take this as basis to fix it upstream in illumos, leave you as the author, and make a small style change to make sure the ending comments for the if blocks match the guards. Let me know if that's reasonable to you and I appreciate you pointing out the things I've been missing here. The broader discussion about what to do was more so for @jperkin and the question of taking the patch around the versions into illumos/gcc. |
Sounds good, feel free to take my patch! If it is possible it would be appreciated if you could add me to CC in upstream ticket/review. |
The upstream review will be on gerrit, so I can drop things here for you to track or shoot you an e-mail if you let me know how you'd like to be contacted. I'll try to have something up in the next few days, but there will be some variability due to some personal travel. |
The mail address used in author field in my commit should work fine. |
|
I am not travelling, but starting Tuesday night I'll be very high-latency&jitter due to the same reasons @rmustacc is travelling (US Thanksgiving holiday is Thursday, Friday's off too for many, and folks often travel for it), plus I'm testing out a biweekly SmartOS release a day later than normal because of that reason. That said I can help however I can as well. |
|
Note, I had to make a minor functional change to the latest patch as the static assert guard in <iso/assert.h> still requires <sys/feature_tests.h> and I'd rather not rewrite it. I also added a comment explaining a bit about what's going on. I've got a build kicked off and I'll drop links to the upstream review later today. I also was looking at the differences this might cause. It looks like C++98 and pkgsrc due to this will now end up getting the non-C99 assert though g++ and clang++ support this in C++98 and don't even generate a warning with |
|
Upstream issue: https://www.illumos.org/issues/17765 and review: https://code.illumos.org/c/illumos-gate/+/4470. |
Assert header is split into two to handle the idempotency since commit b3260c2 "17491 assert(3c) prototype visibility". The macro is in one and the prototype for the internal function in the other. There are different variants for pre-c99 and c99 and the macro and prototype needs to match. The aforementioned commit changed the prototype to use
_STDC_C99while the macro is using__STDC_VERSION__.Normally
_STDC_C99and__STDC_VERSION__would match and this wouldn't be a problem. As sys/feature_tests.h sets_STD_C99based on__STDC_VERSION__value.However the gcc10 compiler is patched to set _STD_C99 as a predefined macro for C++ code.
TritonDataCenter/pkgsrc-extra@e295cdb
This caused using assert from c++ code to fail because the macro expanded a function that there was no proto type for.