Bug 19061 - IA64 GCC pointer confusion results in optimization error
Summary: IA64 GCC pointer confusion results in optimization error
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.1.1
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2004-12-17 18:59 UTC by Steve Ellcey
Modified: 2006-03-03 17:33 UTC (History)
4 users (show)

See Also:
Host: ia64-hp-hpux11.23
Target: ia64-hp-hpux11.23
Build: ia64-hp-hpux11.23
Known to work:
Known to fail: 3.4.3 4.0.0 4.1.0
Last reconfirmed: 2005-11-11 18:03:16


Attachments
Testcase that fails at -O on every branch. (161 bytes, text/plain)
2005-11-11 18:01 UTC, Eric Botcazou
Details
Proposed fix. (376 bytes, patch)
2005-11-11 18:06 UTC, Eric Botcazou
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Ellcey 2004-12-17 18:59:47 UTC
The included program coredumps during execution when compiled with -O2 but not
when compiled with -O0.  The problem appears to be with combine and the use of
the ptr_extend_plus_2 instruction.  GCC is losing track of what is and isn't a
pointer.  I am not entirely sure if the program is legal given all the casts.

struct magic_state {
    void *mgs_sv;
};
typedef struct magic_state MGS;

MGS *PL_savestack;

void
restore_magic(void *p)
{
    MGS* mgs = ((MGS*) ((char*)PL_savestack + (long)(p)));

    if (!mgs->mgs_sv)
        return;
    mgs->mgs_sv = ((void *)0);
}

MGS s;

main()
{
        PL_savestack = &s;
        restore_magic((void *) 0);
}
Comment 1 Giovanni Bajo 2004-12-18 00:12:07 UTC
The program is correct, because you are still accessing a MGS object through a 
MGS pointer, so GCC should not segfault here.
Comment 2 Joseph S. Myers 2005-02-20 00:03:52 UTC
Confirmed with mainline and 3.4.3.
Comment 3 Eric Botcazou 2005-11-11 18:01:59 UTC
Created attachment 10216 [details]
Testcase that fails at -O on every branch.
Comment 4 Eric Botcazou 2005-11-11 18:03:16 UTC
That's a pretty serious issue (the testcase comes from Perl).
Comment 5 Eric Botcazou 2005-11-11 18:06:03 UTC
I think basereg_operand should not look inside SUBREGs.  Here's an excerpt from PA's deprecated basereg_operand:

  return (GET_CODE (op) == REG
          && REG_POINTER (op)
          && register_operand (op, mode));

I'm going to attach the proposed fix.

Comment 6 Eric Botcazou 2005-11-11 18:06:32 UTC
Created attachment 10217 [details]
Proposed fix.
Comment 7 Andrew Pinski 2006-02-18 04:55:55 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2006-02/msg01489.html
Comment 8 Steve Ellcey 2006-03-03 16:43:46 UTC
Subject: Bug 19061

Author: sje
Date: Fri Mar  3 16:43:43 2006
New Revision: 111678

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=111678
Log:
	PR rtl-optimization/26345
	PR target/19061
	* config/ia64/predicates.md (basereg_operand): Don't look in subregs.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/ia64/predicates.md

Comment 9 Steve Ellcey 2006-03-03 16:45:53 UTC
Subject: Bug 19061

Author: sje
Date: Fri Mar  3 16:45:47 2006
New Revision: 111679

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=111679
Log:
	PR rtl-optimization/26345
	PR target/19061
	* config/ia64/predicates.md (basereg_operand): Don't look in subregs.

Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/config/ia64/predicates.md

Comment 10 Andrew Pinski 2006-03-03 17:33:18 UTC
Fixed in 4.1.1.