Bug 31391 - [4.3 Regression] undefined label with -O -g due to cfglayout
Summary: [4.3 Regression] undefined label with -O -g due to cfglayout
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Steven Bosscher
URL:
Keywords: link-failure
Depends on:
Blocks:
 
Reported: 2007-03-29 13:53 UTC by Martin Michlmayr
Modified: 2007-04-02 06:41 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-03-30 20:39:16


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Michlmayr 2007-03-29 13:53:04 UTC
I get the following link error with 4.3 and -O -g:

$ gcc -c -g -O test.c -o test.o
$ gcc -o m m.c test.o
test.o:(.debug_info+0x539): undefined reference to `.L4'
collect2: ld returned 1 exit status

test.c:

#include <netdb.h>
#include <stdio.h>
#include <malloc.h>

typedef struct _hostEntry {
    struct _hostEntry   *next;
    int     type;
} HostEntry;

typedef struct _displayEntry {
    struct _displayEntry    *next;
    int                     type;
    int                     chooser;
    HostEntry               *hosts;
} DisplayEntry;

char* name;
char *ReadWord(FILE *file) {
    return name;
}

static HostEntry *
ReadHostEntry (FILE *file)
{
    char            *hostOrAlias;
    HostEntry       *h;
    struct hostent  *hostent;

tryagain:
    hostOrAlias = ReadWord (file);
    if (!hostOrAlias)
        return NULL;
    h = (HostEntry *) malloc (sizeof (DisplayEntry));
        if (!hostent)
        {
            free ((char *) h);
            goto tryagain;
        }
    return h;
}

static DisplayEntry *
ReadDisplayEntry (FILE *file)
{
    DisplayEntry    *d;
    HostEntry       *h, **prev;
    struct hostent  *hostent;

    switch (hostent->h_addrtype)
    {
    default:
        break;
    }
    prev = &d->hosts;
    while ((h = ReadHostEntry (file)))
    {
        if (h->type == 3)
        {
            d->chooser = 1;
        }
         else {
            *prev = h;
            prev = &h->next;
        }
    }
    return d;
}

int ScanAccessDatabase (FILE *file)
{
    ReadDisplayEntry (file);
}


m.c:

int main() {
}
Comment 1 Martin Michlmayr 2007-03-29 13:56:32 UTC
This problem was introduced between 20070303 and 20070326.
Comment 2 Steven Bosscher 2007-03-30 15:21:20 UTC
Looks like the kind of bug that cfglayout mode might introduce.

Will investigate...
Comment 3 Steven Bosscher 2007-03-30 15:21:40 UTC
Looks like the kind of bug that cfglayout mode might introduce.

Will investigate...
Comment 4 Steven Bosscher 2007-03-30 15:22:31 UTC
Which target is this, BTW?
Comment 5 Martin Michlmayr 2007-03-30 15:29:53 UTC
I've seen it on x86_64 and ia64.
Comment 6 Steven Bosscher 2007-03-30 21:16:19 UTC
At the end of loop2, the tryagain label is turned into a deleted label note.  This happens because the label has zero uses left in cfglayout. There are only unconditional jumps to it, unconditional jumps are removed when going into cfglayout mode (any edge can fall through to any block), and apparently we rebuild jump labels.  Which shouldn't happen, I think.

Anyway, definitely mine.
Comment 7 Steven Bosscher 2007-03-30 23:29:35 UTC
Index: cfgcleanup.c
===================================================================
--- cfgcleanup.c        (revision 123362)
+++ cfgcleanup.c        (working copy)
@@ -2034,6 +2034,8 @@ try_optimize_cfg (int mode)

                      reorder_insns_nobb (label, label, bb_note);
                      BB_HEAD (b) = bb_note;
+                     if (BB_END (b) == bb_note)
+                       BB_END (b) = label;
                    }
                  if (dump_file)
                    fprintf (dump_file, "Deleted label in block %i.\n",
Comment 8 Martin Michlmayr 2007-03-31 01:44:49 UTC
This patch works for me.
Comment 9 Steven Bosscher 2007-04-01 19:26:13 UTC
Subject: Bug 31391

Author: steven
Date: Sun Apr  1 19:26:00 2007
New Revision: 123406

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123406
Log:
	PR rtl-optimization/31391
	* cfgcleanup.c (try_optimize_cfg): If a removed label is turned
	into a DELETED_LABEL note, and the label is in an empty basic
	block, update BB_END as well as BB_HEAD.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cfgcleanup.c

Comment 10 Steven Bosscher 2007-04-02 06:41:39 UTC
.