public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/97398] New: Enhancement request: Warning when multiply assigning to same struct field
@ 2020-10-13 7:30 Ulrich.Windl at rz dot uni-regensburg.de
2020-10-13 9:00 ` [Bug c/97398] " rguenth at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Ulrich.Windl at rz dot uni-regensburg.de @ 2020-10-13 7:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97398
Bug ID: 97398
Summary: Enhancement request: Warning when multiply assigning
to same struct field
Product: gcc
Version: 4.8.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: Ulrich.Windl at rz dot uni-regensburg.de
Target Milestone: ---
Created attachment 49360
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49360&action=edit
Simple test case that doesn't trigger any warning with gcc 7.5.0 and "-O -Wall"
After having found some minor mistake in my C code for "gcc -O2 -Wall" (gcc
4.8.5), I verified that gcc 7.5.0 reacts similar in a test case.
I had (re-)initialized several fields of a structure in a function that got the
pointer to the struct.
The code looks like this (S is the pointer to the struct, and the real code is
way more complex):
s->a = s->b = s->c;
s->d = s->e = s->c;
...
s->f = s->e = s->c
...
So s->e is set to s->c multiple times, and gcc does not warn about that. In
this case s->c is even set to the same value.
To help avoiding this type of mistake, I suggest that gcc should warn when a
structure field is set more then once without reading the value before
re-setting it.
Note: In the simple test program gcc optimizes away everything, but I still
think that it could warn about the mistake. At least you should get the idea.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/97398] Enhancement request: Warning when multiply assigning to same struct field
2020-10-13 7:30 [Bug c/97398] New: Enhancement request: Warning when multiply assigning to same struct field Ulrich.Windl at rz dot uni-regensburg.de
@ 2020-10-13 9:00 ` rguenth at gcc dot gnu.org
2020-10-15 20:06 ` egallager at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-10-13 9:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97398
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2020-10-13
Keywords| |diagnostic
Severity|normal |enhancement
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm, possibly doable for
s->e = s->e = s->c;
but not sure if reasonable for separate stmts (also thinking of false
positives here).
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/97398] Enhancement request: Warning when multiply assigning to same struct field
2020-10-13 7:30 [Bug c/97398] New: Enhancement request: Warning when multiply assigning to same struct field Ulrich.Windl at rz dot uni-regensburg.de
2020-10-13 9:00 ` [Bug c/97398] " rguenth at gcc dot gnu.org
@ 2020-10-15 20:06 ` egallager at gcc dot gnu.org
2020-10-16 6:53 ` Ulrich.Windl at rz dot uni-regensburg.de
2022-12-30 2:57 ` egallager at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: egallager at gcc dot gnu.org @ 2020-10-15 20:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97398
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
would this go under one of the existing -Wunused flags, or a new one?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/97398] Enhancement request: Warning when multiply assigning to same struct field
2020-10-13 7:30 [Bug c/97398] New: Enhancement request: Warning when multiply assigning to same struct field Ulrich.Windl at rz dot uni-regensburg.de
2020-10-13 9:00 ` [Bug c/97398] " rguenth at gcc dot gnu.org
2020-10-15 20:06 ` egallager at gcc dot gnu.org
@ 2020-10-16 6:53 ` Ulrich.Windl at rz dot uni-regensburg.de
2022-12-30 2:57 ` egallager at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: Ulrich.Windl at rz dot uni-regensburg.de @ 2020-10-16 6:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97398
--- Comment #3 from Ulrich Windl <Ulrich.Windl at rz dot uni-regensburg.de> ---
(In reply to Eric Gallager from comment #2)
> would this go under one of the existing -Wunused flags, or a new one?
I think it's a case of being an unused value set to a variable in general, but
more specifically it's setting a value more than once before possibly being
used (which is the case in my code). SO IMHO the question is whether setting a
variable more than once without being read in between is a special case of
setting a variable value without using it.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/97398] Enhancement request: Warning when multiply assigning to same struct field
2020-10-13 7:30 [Bug c/97398] New: Enhancement request: Warning when multiply assigning to same struct field Ulrich.Windl at rz dot uni-regensburg.de
` (2 preceding siblings ...)
2020-10-16 6:53 ` Ulrich.Windl at rz dot uni-regensburg.de
@ 2022-12-30 2:57 ` egallager at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: egallager at gcc dot gnu.org @ 2022-12-30 2:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97398
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Blocks| |89180, 87403
--- Comment #4 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Ulrich Windl from comment #3)
> (In reply to Eric Gallager from comment #2)
> > would this go under one of the existing -Wunused flags, or a new one?
>
> I think it's a case of being an unused value set to a variable in general,
> but more specifically it's setting a value more than once before possibly
> being used (which is the case in my code). SO IMHO the question is whether
> setting a variable more than once without being read in between is a special
> case of setting a variable value without using it.
Hm... guess I'll put this under both the "Wunused" and "new-warning" meta-bugs,
and then let whoever implements it decide where it fits better...
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89180
[Bug 89180] [meta-bug] bogus/missing -Wunused warnings
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-12-30 2:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-13 7:30 [Bug c/97398] New: Enhancement request: Warning when multiply assigning to same struct field Ulrich.Windl at rz dot uni-regensburg.de
2020-10-13 9:00 ` [Bug c/97398] " rguenth at gcc dot gnu.org
2020-10-15 20:06 ` egallager at gcc dot gnu.org
2020-10-16 6:53 ` Ulrich.Windl at rz dot uni-regensburg.de
2022-12-30 2:57 ` egallager at gcc dot gnu.org
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).