* [PATCH] [sim,rx] Silence warning that turns into a build error
@ 2021-04-08 19:51 Luis Machado
2021-04-08 20:16 ` Mike Frysinger
0 siblings, 1 reply; 6+ messages in thread
From: Luis Machado @ 2021-04-08 19:51 UTC (permalink / raw)
To: gdb-patches
On a 32-bit build, I ran into the following:
sim/rx/fpu.c:789:6: error: ‘*((void *)&a+8)’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
rv = fp_implode (&a);
To silence this, just initialize the struct with 0's.
sim/rx/ChangeLog:
YYYY-MM-DD Luis Machado <luis.machado@linaro.org>
* fpu.c (rxfp_itof): Initialize structure.
---
sim/rx/fpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sim/rx/fpu.c b/sim/rx/fpu.c
index f9e9007192a..9c789e8518c 100644
--- a/sim/rx/fpu.c
+++ b/sim/rx/fpu.c
@@ -732,7 +732,7 @@ rxfp_itof (long fa, int round_mode)
int sign = 0;
unsigned int frac_bits;
volatile unsigned int whole_bits;
- FP_Parts a;
+ FP_Parts a = {0, 0, 0, 0, 0};
if (fa == 0)
return PLUS_ZERO;
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [sim,rx] Silence warning that turns into a build error
2021-04-08 19:51 [PATCH] [sim,rx] Silence warning that turns into a build error Luis Machado
@ 2021-04-08 20:16 ` Mike Frysinger
2021-04-08 20:23 ` Luis Machado
0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2021-04-08 20:16 UTC (permalink / raw)
To: Luis Machado; +Cc: gdb-patches
On 08 Apr 2021 16:51, Luis Machado via Gdb-patches wrote:
> + FP_Parts a = {0, 0, 0, 0, 0};
wouldn't it be simpler & equiv:
FP_Parts a = {};
-mike
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [sim,rx] Silence warning that turns into a build error
2021-04-08 20:16 ` Mike Frysinger
@ 2021-04-08 20:23 ` Luis Machado
2021-04-08 20:25 ` Luis Machado
2021-04-08 20:57 ` Mike Frysinger
0 siblings, 2 replies; 6+ messages in thread
From: Luis Machado @ 2021-04-08 20:23 UTC (permalink / raw)
To: gdb-patches
On 4/8/21 5:16 PM, Mike Frysinger wrote:
> On 08 Apr 2021 16:51, Luis Machado via Gdb-patches wrote:
>> + FP_Parts a = {0, 0, 0, 0, 0};
>
> wouldn't it be simpler & equiv:
> FP_Parts a = {};
> -mike
>
I find that it works, but I'm unsure if it is a standard way of doing it.
The C reference says:
"When initializing an object of struct or union type, the initializer
must be a non-empty, brace-enclosed, comma-separated list of
initializers for the members."
So I went with the most obvious, as opposed to going shorter and more
opaque.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [sim,rx] Silence warning that turns into a build error
2021-04-08 20:23 ` Luis Machado
@ 2021-04-08 20:25 ` Luis Machado
2021-04-08 20:57 ` Mike Frysinger
1 sibling, 0 replies; 6+ messages in thread
From: Luis Machado @ 2021-04-08 20:25 UTC (permalink / raw)
To: gdb-patches
On 4/8/21 5:23 PM, Luis Machado wrote:
> On 4/8/21 5:16 PM, Mike Frysinger wrote:
>> On 08 Apr 2021 16:51, Luis Machado via Gdb-patches wrote:
>>> + FP_Parts a = {0, 0, 0, 0, 0};
>>
>> wouldn't it be simpler & equiv:
>> FP_Parts a = {};
>> -mike
>>
>
> I find that it works, but I'm unsure if it is a standard way of doing it.
>
> The C reference says:
>
> "When initializing an object of struct or union type, the initializer
> must be a non-empty, brace-enclosed, comma-separated list of
> initializers for the members."
>
> So I went with the most obvious, as opposed to going shorter and more
> opaque.
It may be the case that sim/ also builds with C++, like GDB. And {}
would work for that then.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [sim,rx] Silence warning that turns into a build error
2021-04-08 20:23 ` Luis Machado
2021-04-08 20:25 ` Luis Machado
@ 2021-04-08 20:57 ` Mike Frysinger
2021-04-09 12:17 ` Luis Machado
1 sibling, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2021-04-08 20:57 UTC (permalink / raw)
To: Luis Machado; +Cc: gdb-patches
On 08 Apr 2021 17:23, Luis Machado via Gdb-patches wrote:
> On 4/8/21 5:16 PM, Mike Frysinger wrote:
> > On 08 Apr 2021 16:51, Luis Machado via Gdb-patches wrote:
> >> + FP_Parts a = {0, 0, 0, 0, 0};
> >
> > wouldn't it be simpler & equiv:
> > FP_Parts a = {};
>
> I find that it works, but I'm unsure if it is a standard way of doing it.
>
> The C reference says:
>
> "When initializing an object of struct or union type, the initializer
> must be a non-empty, brace-enclosed, comma-separated list of
> initializers for the members."
>
> So I went with the most obvious, as opposed to going shorter and more
> opaque.
my concern is more about having to tweak this whenever fields are added
or removed.
i couldn't remember if the ={} syntax was a C++ extension, or in C11.
if it's a C++ extension, i *think* ={0} will work even in C11.
-mike
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [sim,rx] Silence warning that turns into a build error
2021-04-08 20:57 ` Mike Frysinger
@ 2021-04-09 12:17 ` Luis Machado
0 siblings, 0 replies; 6+ messages in thread
From: Luis Machado @ 2021-04-09 12:17 UTC (permalink / raw)
To: gdb-patches
On 4/8/21 5:57 PM, Mike Frysinger wrote:
> On 08 Apr 2021 17:23, Luis Machado via Gdb-patches wrote:
>> On 4/8/21 5:16 PM, Mike Frysinger wrote:
>>> On 08 Apr 2021 16:51, Luis Machado via Gdb-patches wrote:
>>>> + FP_Parts a = {0, 0, 0, 0, 0};
>>>
>>> wouldn't it be simpler & equiv:
>>> FP_Parts a = {};
>>
>> I find that it works, but I'm unsure if it is a standard way of doing it.
>>
>> The C reference says:
>>
>> "When initializing an object of struct or union type, the initializer
>> must be a non-empty, brace-enclosed, comma-separated list of
>> initializers for the members."
>>
>> So I went with the most obvious, as opposed to going shorter and more
>> opaque.
>
> my concern is more about having to tweak this whenever fields are added
> or removed.
>
> i couldn't remember if the ={} syntax was a C++ extension, or in C11.
> if it's a C++ extension, i *think* ={0} will work even in C11.
> -mike
>
I think it is a C++ thing. I pushed it with the {0} initializer now.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-04-09 12:17 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 19:51 [PATCH] [sim,rx] Silence warning that turns into a build error Luis Machado
2021-04-08 20:16 ` Mike Frysinger
2021-04-08 20:23 ` Luis Machado
2021-04-08 20:25 ` Luis Machado
2021-04-08 20:57 ` Mike Frysinger
2021-04-09 12:17 ` Luis Machado
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).