public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/101679] New: duplicate warning offset outside bounds of constant string
@ 2021-07-29 17:49 msebor at gcc dot gnu.org
  2021-07-29 21:22 ` [Bug middle-end/101679] triplicate " msebor at gcc dot gnu.org
  2021-07-29 21:30 ` msebor at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-29 17:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101679

            Bug ID: 101679
           Summary: duplicate warning offset outside bounds of constant
                    string
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Only one instance of -Warray-bounds should be reported the access below but GCC
issues two.  The warning is issued from c_strlen() with the first instance
during lowering and the second during (or just before) expansion.  The first
instance calls suppress_warning(arg, OPT_Warray_bounds) which is checked again
before issuing the second instance by calling warning_suppressed_p (arg,
OPT_Warray_bounds).  The problem is that the first time arg is an ADDR_EXPR but
VAR_DECL the second.  Stripping the ADDR_EXPR and disabling the warning for its
operand is not a solution because it would disable warnings for invalid uses of
the same operand in other statements, both in the same function or (for global
variables) in others.

$ cat a.c && gcc -S -Wall a.c 
const char s0[0] = { };

char* f (char *d)
{
  return __builtin_strcpy (d, s0);
}

a.c: In function ‘f’:
a.c:5:31: warning: offset ‘0’ outside bounds of constant string
[-Warray-bounds]
    5 |   return __builtin_strcpy (d, s0);
      |                               ^~
a.c:1:12: note: ‘s0’ declared here
    1 | const char s0[0] = { };
      |            ^~
a.c:5:10: warning: offset ‘0’ outside bounds of constant string
[-Warray-bounds]
    5 |   return __builtin_strcpy (d, s0);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
a.c:1:12: note: ‘s0’ declared here
    1 | const char s0[0] = { };
      |            ^~

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/101679] triplicate warning offset outside bounds of constant string
  2021-07-29 17:49 [Bug middle-end/101679] New: duplicate warning offset outside bounds of constant string msebor at gcc dot gnu.org
@ 2021-07-29 21:22 ` msebor at gcc dot gnu.org
  2021-07-29 21:30 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-29 21:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101679

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|duplicate warning offset    |triplicate warning offset
                   |outside bounds of constant  |outside bounds of constant
                   |string                      |string

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
An even better example of the same problem.  It also illustrates how the
warning location gets progressively worse:

$ cat a.c && gcc -S -Wall a.c 
const char s[0] = { };

int f (void)
{
  return __builtin_strlen (s);
}
a.c: In function ‘f’:
a.c:5:28: warning: offset ‘0’ outside bounds of constant string
[-Warray-bounds]
    5 |   return __builtin_strlen (s);
      |                            ^
a.c:1:12: note: ‘s’ declared here
    1 | const char s[0] = { };
      |            ^
a.c:5:10: warning: offset ‘0’ outside bounds of constant string
[-Warray-bounds]
    5 |   return __builtin_strlen (s);
      |          ^~~~~~~~~~~~~~~~~~~~
a.c:1:12: note: ‘s’ declared here
    1 | const char s[0] = { };
      |            ^
a.c:3:5: warning: offset ‘0’ outside bounds of constant string [-Warray-bounds]
    3 | int f (void)
      |     ^
a.c:1:12: note: ‘s’ declared here
    1 | const char s[0] = { };
      |            ^

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/101679] triplicate warning offset outside bounds of constant string
  2021-07-29 17:49 [Bug middle-end/101679] New: duplicate warning offset outside bounds of constant string msebor at gcc dot gnu.org
  2021-07-29 21:22 ` [Bug middle-end/101679] triplicate " msebor at gcc dot gnu.org
@ 2021-07-29 21:30 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-29 21:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101679

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
For the code in comment #1, the first warning is issued from the front end, the
second one from the Gimplifier, and the last one just before expansion.  The
first one still has the right location.  The second one has the location of the
call because that's what's being folded.  The third one has no location because
it's being issued for a STRING_CST so the code substitutes input_location.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-29 21:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 17:49 [Bug middle-end/101679] New: duplicate warning offset outside bounds of constant string msebor at gcc dot gnu.org
2021-07-29 21:22 ` [Bug middle-end/101679] triplicate " msebor at gcc dot gnu.org
2021-07-29 21:30 ` 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).