-
Notifications
You must be signed in to change notification settings - Fork 2k
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
llvm: Fix unused function warning #18870
Conversation
union __attribute__((packed)) { | ||
uint32_t u8_pad; | ||
le_uint16_t conf_fcnt; | ||
}; |
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.
union __attribute__((packed)) { | |
uint32_t u8_pad; | |
le_uint16_t conf_fcnt; | |
}; | |
uint16_t u8_pad; | |
le_uint16_t conf_fcnt; |
i am not sure why that pad is named u8_pad maybe you are able to tell?
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.
Shouldn't that be
le_uint16_t conf_fcnt;
uint16_t u8_pad;
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.
you are right
union __attribute__((packed)) { | |
uint32_t u8_pad; | |
le_uint16_t conf_fcnt; | |
}; | |
le_uint16_t conf_fcnt; | |
uint16_t u16_pad; |
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.
diff --git a/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan_crypto.c b/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan_crypto.c
index 18fc6e29b9..6bcddfde2d 100644
--- a/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan_crypto.c
+++ b/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan_crypto.c
@@ -235,11 +235,8 @@ void gnrc_lorawan_encrypt_payload(iolist_t *iolist, const le_uint32_t *dev_addr,
uint32_t fcnt, uint8_t dir,
const uint8_t *appskey)
{
- uint8_t s_block[16];
- uint8_t a_block[16];
-
- memset(s_block, 0, sizeof(s_block));
- memset(a_block, 0, sizeof(a_block));
+ uint8_t s_block[16]={0};
+ uint8_t a_block[16]={0};
lorawan_block0_t *block = (lorawan_block0_t *)a_block;
@@ -247,14 +244,11 @@ void gnrc_lorawan_encrypt_payload(iolist_t *iolist, const le_uint32_t *dev_addr,
block->fb = CRYPT_B0_START;
- block->u8_pad = 0;
block->dir = dir & DIR_MASK;
block->dev_addr = *dev_addr;
block->fcnt = byteorder_htoll(fcnt);
- block->u32_pad = 0;
-
int c = 0;
for (iolist_t *io = iolist; io != NULL; io = io->iol_next) {
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.
cpu/stm32/cpu_init.c
Outdated
@@ -160,6 +160,7 @@ static void _gpio_init_ain(void) | |||
* This very teniously avoids optimization, even optimized it's better than | |||
* nothing but periodic review should establish that it doesn't get optimized. | |||
*/ | |||
#if defined(STM32_OPTION_BYTES) |
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.
either use attribute unused or move the #ifdef up from line 244 (not do the same #ifdef twice)
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.
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 added a fixup that moves the #ifdef. I think attribute(unused) is wrong here. This is not three steps into linking or hidden behind 100 layers of dependency modelling. That function is exactly used three times and only when that option is enabled. An attribute does not convey that meaning/context but the ifdef does.
this may better be two PR since the changes are in very different parts of RIOT and not connected but by this PR and the issue |
cpu/stm32/cpu_init.c
Outdated
@@ -396,13 +398,15 @@ void backup_ram_init(void) | |||
#define BACKUP_RAM_MAGIC {'R', 'I', 'O', 'T'} | |||
#endif | |||
|
|||
#if IS_ACTIVE(CPU_HAS_BACKUP_RAM) |
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.
#if IS_ACTIVE(CPU_HAS_BACKUP_RAM) | |
__attribute__((unused)) |
is IMO much better than using the preprocessor, as we get better LSP suggestions, better static analysis results and wide compile test coverage when not hiding functions from the compiler.
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.
Hehe, you did it yourself in f4c5cf1
Those are both very minor changes, I don't think we need two PRs for that. |
2e4ef0d
to
ccafa5a
Compare
cpu/stm32/cpu_init.c
Outdated
@@ -161,6 +161,7 @@ static void _gpio_init_ain(void) | |||
* This very teniously avoids optimization, even optimized it's better than | |||
* nothing but periodic review should establish that it doesn't get optimized. | |||
*/ | |||
#if defined(STM32_OPTION_BYTES) |
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.
#if defined(STM32_OPTION_BYTES) | |
MAYBE_UNUSED |
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.
Saw this comment too late, see #18870 (comment)
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.
Please squash
dd83c9e
to
7b38e56
Compare
|
7b38e56
to
d19182c
Compare
Switched to using |
Related to #18851
When building example/gnrc_lorawan using LLVM two unused function error are raised. Those are fixed by only include said functions when they are needed.
Additionally, LLVM complains about lorawan struct being not packed correctly. I believe this is because GCC applies the given attribute(packed) to all elements of a given struct including the anonymous struct and unions if present. Clang on the other does not seem to do that. The fix works by adding the packed attribute to the anonymous union as well.