public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/67386] missing diagnostic on a use of an undeclared function
Date: Fri, 28 Aug 2015 23:04:00 -0000	[thread overview]
Message-ID: <bug-67386-4-iQaxISPgrd@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-67386-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thanks.  I think I may have misinterpreted the C90 rules that describe implicit
function declarations.  The C90 text says:

If the expression that precedes the parenthesized argument list in a function
call consists solely of an identifier, and if no declaration is visible for
this identifier, the identifier is implicitly declared exactly as if, in the
innermost block containing the function call, the declaration

extern int identifier();

appeared.

My reading was that the implicit declaration is intended to be in effect only
for the call to the otherwise undeclared function, but GCC and the other
compilers I've tried let it persist (at least) until the end of the scope and
use it for references to the undeclared function that aren't calls (such as
assigning its address to a pointer).

While trying to better understand both the rule and the implementation (since
it affects the fix for pr66516), I created the following test case and tried it
with GCC and the other compilers.  GCC's output for the test case is below (the
errors are the same with c98, gnu98, c99, gnu99, c11, and gnu11 as arguments to
-std=, and with or without -pedantic).  Clang, however, doesn't issue any
errors, and neither does IBM xlc.  The EDG front end behaves the same as GCC.

I think Clang and IBM xlc are both wrong since the reference to abs on line 8
should clearly be diagnosed.  The C90 words aren't completely clear about where
in the innermost block the extern int identifier(); declaration is supposed to
appear but it stands to reason that it should appear where all other
declarations must appear in C90: before any executable code.  So diagnosing the
reference to abs on line 11 is incorrect because the call to abs(0) on the
following line should introduce an implicit declaration of the function just
before line 11 where its address is taken.

Unless you disagree, I'll close this as NOTABUG and open a new bug for the
incorrect diagnostic on line 11.

$ cat -n t.c && ~/bin/gcc-5.1.0/bin/gcc -c t.c
     1  int (*p)(int);
     2  int i;
     3  
     4  void f0 (void) {
     5      i = abs (0);   // okay, abs implicitly declared in this scope
     6  }
     7  void f1 (void) {
     8      p = abs;       // error, no implicitly declaration in scope
     9  }
    10  void f2 (void) {
    11      p = abs;       // GCC bug?
    12      i = abs (0);   // injects an implicit declaration into the
enclosing block
    13  }
    14  void f3 (void) {
    15      i = abs (0);   // introduces an implicit declaration into scope
    16      p = abs;       // okay, abs implicitly declared above
    17  }
    18  
t.c: In function ‘f0’:
t.c:5:9: warning: implicit declaration of function ‘abs’
[-Wimplicit-function-declaration]
     i = abs (0);
         ^
t.c: In function ‘f1’:
t.c:8:9: error: ‘abs’ undeclared (first use in this function)
     p = abs;
         ^
t.c:8:9: note: each undeclared identifier is reported only once for each
function it appears in
t.c: In function ‘f2’:
t.c:11:9: error: ‘abs’ undeclared (first use in this function)
     p = abs;
         ^
>From gcc-bugs-return-495833-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Aug 28 23:07:58 2015
Return-Path: <gcc-bugs-return-495833-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 29190 invoked by alias); 28 Aug 2015 23:07:57 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 29140 invoked by uid 48); 28 Aug 2015 23:07:54 -0000
From: "schwab@linux-m68k.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/67390] New: [6 regression] FAIL: g++.dg/torture/pr64312.C   -O1  (test for excess errors)
Date: Fri, 28 Aug 2015 23:07:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords: memory-hog
X-Bugzilla-Severity: normal
X-Bugzilla-Who: schwab@linux-m68k.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter cc blocked target_milestone cf_gcctarget
Message-ID: <bug-67390-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-08/txt/msg01975.txt.bz2
Content-length: 952

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg390

            Bug ID: 67390
           Summary: [6 regression] FAIL: g++.dg/torture/pr64312.C   -O1
                    (test for excess errors)
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Keywords: memory-hog
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: schwab@linux-m68k.org
                CC: alalaw01 at gcc dot gnu.org
            Blocks: 67283
  Target Milestone: ---
            Target: m68k-*-*

After r227265:

$ (ulimit -v $((1024*1024)); gcc/xg++ -Bgcc/
../gcc/testsuite/g++.dg/torture/pr64312.C -O1 -S -o pr64312.s)
cc1plus: out of memory allocating 2056 bytes after a total of 530935808 bytes


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg283
[Bug 67283] GCC regression over inlining of returned structures


  parent reply	other threads:[~2015-08-28 23:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-28 16:21 [Bug c/67386] New: " msebor at gcc dot gnu.org
2015-08-28 17:55 ` [Bug c/67386] " joseph at codesourcery dot com
2015-08-28 23:04 ` msebor at gcc dot gnu.org [this message]
2015-08-30 16:50 ` msebor at gcc dot gnu.org
2015-08-31 10:59 ` joseph at codesourcery dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-67386-4-iQaxISPgrd@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).