Bug 46583 - [4.6 Regression] -fcompare-debug failure with -O -fno-inline -fipa-cp -fipa-cp-clone
Summary: [4.6 Regression] -fcompare-debug failure with -O -fno-inline -fipa-cp -fipa-c...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Alexandre Oliva
URL:
Keywords: compare-debug-failure
Depends on:
Blocks:
 
Reported: 2010-11-20 22:47 UTC by Zdenek Sojka
Modified: 2022-01-18 23:30 UTC (History)
4 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build:
Known to work:
Known to fail: 4.6.0
Last reconfirmed: 2010-11-21 00:22:11


Attachments
reduced testcase (237 bytes, text/plain)
2010-11-20 22:47 UTC, Zdenek Sojka
Details
Patch that fixes the problem (1007 bytes, patch)
2010-11-21 08:06 UTC, Alexandre Oliva
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2010-11-20 22:47:45 UTC
Created attachment 22472 [details]
reduced testcase

Compiler output:
$ gcc -O -fno-inline -fipa-cp -fipa-cp-clone -fcompare-debug testcase.C
gcc: error: testcase.C: -fcompare-debug failure
$ diff testcase.*gkd
46d45
< 0:   const unsigned int D.xxxx;
47a47
> 0:   const unsigned int D.xxxx;

Tested revisions:
r166976 - fail
r165699 - fail
r163636 - fail
r161659 - OK
4.5 r166509 - OK
Comment 1 H.J. Lu 2010-11-21 00:22:11 UTC
It is caused by revision 162156:

http://gcc.gnu.org/ml/gcc-cvs/2010-07/msg00510.html
Comment 2 Jorn Wolfgang Rennecke 2010-11-21 01:35:49 UTC
(In reply to comment #1)
> It is caused by revision 162156:
> 
> http://gcc.gnu.org/ml/gcc-cvs/2010-07/msg00510.html

This patch gives a diagnosis for an internal compiler inconsistency.
Having different orders of identifiers can lead to different compilation
output, although if it actually does is down to a complex interaction of
compiler internals that to all effects and purposes can be considered
to be pseudo-random.
See PR44832 for an example.

The real question to be asked here is why the identifier order has changed.
Comment 3 Alexandre Oliva 2010-11-21 07:51:45 UTC
Mine.  The order changed because we discarded the typedef decl from the block scope in the original function.  When the time came to clone it, we'd remap the typedef type after variable a3 of that type, and a3 would not be nonlocalized, whereas with debug info we retained the typedef, cloned the type first, and a3 would be nonlocalized.  The patch I'm going to attach momentarily fixes this by keeping the typedef around.
Comment 4 Alexandre Oliva 2010-11-21 08:06:28 UTC
Created attachment 22474 [details]
Patch that fixes the problem

This is the patch I'm testing.
Comment 5 Richard Biener 2010-11-21 20:46:37 UTC
Looks like a sledgehammer.  Why does nonlocalize state depends on debug info?
Comment 6 Alexandre Oliva 2010-11-22 15:05:33 UTC
It checks whether the var type was already remapped.

tree-inline.c:
can_be_nonlocal(...):
  /* We must use global type.  We call remapped_type instead of
     remap_type since we don't want to remap this type here if it
     hasn't been remapped before.  */
  if (TREE_TYPE (decl) != remapped_type (TREE_TYPE (decl), id))
    return false;
Comment 7 Jakub Jelinek 2010-11-22 15:24:04 UTC
Yeah.  FYI, I've tried to limit this to VLAs only in
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43942#c14
unfortunately it degraded debug info quality, so for now we really need all types.
Comment 8 Alexandre Oliva 2011-01-20 16:56:30 UTC
Author: aoliva
Date: Thu Jan 20 16:56:25 2011
New Revision: 169058

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169058
Log:
gcc/ChangeLog:
PR debug/46583
* tree-ssa-live.c (remove_unused_scope_block_p): Keep type decls.
gcc/testsuite/ChangeLog:
PR debug/46583
* g++.dg/debug/pr46583.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/debug/pr46583.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-live.c
Comment 9 Alexandre Oliva 2011-01-20 17:09:11 UTC
Fixed