This patch fixes several issues in stdbit.h and makes the C23 bit utility helpers usable from the PIC16 library build.
Main fixes:
- repair malformed typed stdc_* macros and wrong helper references;
- fix incorrect inversions in stdc_first_leading_ / stdc_first_trailing_;
- add missing _BitInt entries in __typewidth() and fix the _BitInt(56) width typo;
- guard _BitInt-specific generic selections when the target does not support them;
- add __stdc_bit_floorull() to avoid the previous shift-by-width implementation;
- introduce __SDCC_ULLONG_WIDTH, using ULLONG_WIDTH where available and a C11-compatible fallback otherwise;
- add the existing __stdc_* helper sources to the PIC16 libc18f.a build.
Validation:
- all 8 __stdc_* helpers compile successfully for PIC16 with the normal --std-c11 library flags;
- the rebuilt libc18f.a contains all helper objects;
- an end-to-end PIC18F452 link using stdc_count_ones_ull() succeeds and produces a HEX file;
- stdbit_all.c parses successfully for PIC16 in C23 mode;
- __typewidth() was checked for missing and mismatched _BitInt(N) : N entries.
Apart from the copyright in __stdc_bit_floorull.c this looks good to me.
I doubt @spth Philipp sent you that file for you to attach it here.
Though I do understand the code was practically copied from stdbit.h.
Can the two of you please resolve this?
Thanks, Maarten. You're right. Philipp did not send me this file. I created __stdc_bit_floorull.c using one of the existing _stdc* helper files as a template and accidentally left its copyright line in the new file. I'll correct that. I have attached the corrected file.
Last edit: zeynelsagcan 5 days ago
I don't see the purpose of
__SDCC_ULLONG_WIDTH- what's wrong with usingULLONG_WIDTHin the.cfiles? After all, those.cfiles are part of our own library and compiled as C11 or later. Also, I don't think we should#include <limits.h>instdbit.h, since that would#definemacros that the C standard does not list as defined forstdbit.h.You mentioned some inversion being incorrect. Could you add regression test for them in sdcc/support/regression/tests? Ideally also including some tests that use the types that were affected by the
__typewidthissues, so the tests cover both.I've picked the
_BitIntentry fixes in [r17062], and also added an entry forsigned _BitInt(1).Related
Commit: [r17062]
ULLONG_WIDTHis only defined in limits.h for C23+, not for C11. But without including it this is no longer relevant. I have now added checks ifULLONG_WIDTHis defined and define it if it wasn't.signed _BitInt(1)again because it triggers warning 315. Either prevent the warning, make it pedantic or drop it.All in [r17065].
I have not yet added
__stdc_bit_floorull.c.Related
Commit: [r17065]
I also had noticed the warning, though unfortunately only after the commit. I'll make
signed _BitInt(1)conditional on the standard version - I think we need it for correct results of these functions forsigned _BitInt(1), which would be allowed in C2y.Done in [r17083].
Related
Commit: [r17083]
@spth & @janet-chien will you come to an agreement on what to do with
__stdc_bit_floorull.c, resolve it and close this one?