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

BIT_MASK(32) generate warning on 32 bits processor #42163

Closed
julien-massot opened this issue Jan 26, 2022 · 1 comment
Closed

BIT_MASK(32) generate warning on 32 bits processor #42163

julien-massot opened this issue Jan 26, 2022 · 1 comment
Assignees
Labels
area: API Changes to public APIs bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@julien-massot
Copy link
Collaborator

Describe the bug

On ARM 32 bits when using BIT_MASK(32) macro, it generates this warning

/home/julien/src/zephyr/zephyr/include/sys/util_macro.h:44:22: warning: left shift count >= width of type [-Wshift-count-overflow]
44 | #define BIT(n) (1UL << (n))
| ^~
/home/julien/src/zephyr/zephyr/include/sys/util_macro.h:68:22: note: in expansion of macro 'BIT'
68 | #define BIT_MASK(n) (BIT(n) - 1UL)
| ^~~
/home/julien/src/zephyr/zephyr/drivers/interrupt_controller/intc_gicv3.c:418:15: note: in expansion of macro 'BIT_MASK'
418 | sys_write32(BIT_MASK(GIC_NUM_INTR_PER_REG),

From what I understand to have a 32bits mask, we set the 33th bit and then do -1, which result in
0xFFFFFFFF as expected however it's not possible to the the 33th bits on a 32 bit type.

Should we modify BIT_MASK definition in
#define BIT_MASK(n) (BIT64(n) - 1UL) ?

@julien-massot julien-massot added the bug The issue is a bug, or the PR is fixing a bug label Jan 26, 2022
@carlescufi carlescufi self-assigned this Jan 26, 2022
@carlescufi carlescufi added the area: API Changes to public APIs label Jan 26, 2022
@dkalowsk dkalowsk added the priority: low Low impact/importance bug label Feb 1, 2022
@julien-massot
Copy link
Collaborator Author

Ok, after discussion on #42226 it sounds preferable to use (uint32_t)BIT64_mask(32) instead.

julien-massot pushed a commit to iotbzh/zephyr that referenced this issue Mar 10, 2022
On 32bit compiler the BIT_MASK(32) generate a warning,
after discussion on zephyrproject-rtos#42226 and zephyrproject-rtos#42163, advise was to use
BIT64_MASK instead.

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
carlescufi pushed a commit that referenced this issue Mar 11, 2022
On 32bit compiler the BIT_MASK(32) generate a warning,
after discussion on #42226 and #42163, advise was to use
BIT64_MASK instead.

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
RodinHaker pushed a commit to abelsensors/zephyr that referenced this issue Mar 19, 2022
On 32bit compiler the BIT_MASK(32) generate a warning,
after discussion on zephyrproject-rtos#42226 and zephyrproject-rtos#42163, advise was to use
BIT64_MASK instead.

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants