public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/98097] New: Missing warning about strcmp (char[4], "BARZ")
@ 2020-12-02 14:07 rguenth at gcc dot gnu.org
2020-12-02 14:07 ` [Bug tree-optimization/98097] " rguenth at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-12-02 14:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98097
Bug ID: 98097
Summary: Missing warning about strcmp (char[4], "BARZ")
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
#include <string.h>
struct info {
char type[4];
unsigned int status;
};
int foo (struct info *i)
{
return strcmp (i->type, "ECKD") == 0;
}
Does not warn with -Wstring-compare, the variant with i passed by value does.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98097] Missing warning about strcmp (char[4], "BARZ")
2020-12-02 14:07 [Bug tree-optimization/98097] New: Missing warning about strcmp (char[4], "BARZ") rguenth at gcc dot gnu.org
@ 2020-12-02 14:07 ` rguenth at gcc dot gnu.org
2020-12-02 15:48 ` msebor at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-12-02 14:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98097
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
CC| |msebor at gcc dot gnu.org
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Likely because &i->type is not a gimple invariant and thus in a separate stmt?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98097] Missing warning about strcmp (char[4], "BARZ")
2020-12-02 14:07 [Bug tree-optimization/98097] New: Missing warning about strcmp (char[4], "BARZ") rguenth at gcc dot gnu.org
2020-12-02 14:07 ` [Bug tree-optimization/98097] " rguenth at gcc dot gnu.org
@ 2020-12-02 15:48 ` msebor at gcc dot gnu.org
2020-12-02 16:06 ` jakub at gcc dot gnu.org
2021-01-08 0:54 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-12-02 15:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98097
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2020-12-02
Ever confirmed|0 |1
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
The failure to diagnose this is due to the warning using the same conservative
assumption as for the strcmp and strlen optimization. The optimization assumes
that strlen(i->type) is bounded by the size of the object i points to if it can
be determined, or by MAX_OBJECT_SIZE if not. (You'll recall the long,
contentious discussion about this.) This assumption is overly conservative
for warnings but because -Wstring-compare was an optimization first and the
warning only an afterthought (after testing showed the optimization didn't
trigger enough to matter), I didn't remember to decouple the two. Let me do
that.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98097] Missing warning about strcmp (char[4], "BARZ")
2020-12-02 14:07 [Bug tree-optimization/98097] New: Missing warning about strcmp (char[4], "BARZ") rguenth at gcc dot gnu.org
2020-12-02 14:07 ` [Bug tree-optimization/98097] " rguenth at gcc dot gnu.org
2020-12-02 15:48 ` msebor at gcc dot gnu.org
@ 2020-12-02 16:06 ` jakub at gcc dot gnu.org
2021-01-08 0:54 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-02 16:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98097
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
For optimizations indeed we shouldn't do any such assumptions, the fact that
the function is called with a particular pointer type doesn't necessarily mean
that is the dynamic type of the underlying object, and strcmp etc. functions
read or write the memory through char type which can alias anything.
But for warnings, we can indeed use the passed in type as a reasonable hint
what is ok and what is suspicious.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98097] Missing warning about strcmp (char[4], "BARZ")
2020-12-02 14:07 [Bug tree-optimization/98097] New: Missing warning about strcmp (char[4], "BARZ") rguenth at gcc dot gnu.org
` (2 preceding siblings ...)
2020-12-02 16:06 ` jakub at gcc dot gnu.org
@ 2021-01-08 0:54 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-01-08 0:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98097
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-January/563036.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-01-08 0:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 14:07 [Bug tree-optimization/98097] New: Missing warning about strcmp (char[4], "BARZ") rguenth at gcc dot gnu.org
2020-12-02 14:07 ` [Bug tree-optimization/98097] " rguenth at gcc dot gnu.org
2020-12-02 15:48 ` msebor at gcc dot gnu.org
2020-12-02 16:06 ` jakub at gcc dot gnu.org
2021-01-08 0:54 ` msebor 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).