Bug 13382 - [3.3/3.4 Regression] Type information for const pointer disappears during optimisation.
Summary: [3.3/3.4 Regression] Type information for const pointer disappears during opt...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: 3.3.3
Assignee: Eric Botcazou
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2003-12-11 13:00 UTC by richard.hutchinson
Modified: 2004-01-17 04:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-12-11 15:24:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description richard.hutchinson 2003-12-11 13:00:13 UTC
Compiling the source code

static const struct
{
  int aMember;
} *const aPointer = 0;

int main()
{
  int anInt = (aPointer == 0) ? 0 : aPointer->aMember;
  return 0;
}

with the command line

gcc -o prog -O prog.c

generates the following error output:

testgcc.c: In function `main':
testgcc.c:15: error: request for member `aMember' in something not a structure
or union

This does not happen if the -O switch is omitted.

This behaviour does not occur with gcc 2.95.3 (the only other Solaris version I
have to hand).
Comment 1 Dara Hazeghi 2003-12-11 15:24:25 UTC
Confirmed with 3.3 branch and mainline. This is indeed a regression since 2.95.3. It does however 
fail with 3.0.4 and newer, so it's not a very new one.
Comment 2 Andrew Pinski 2003-12-11 18:28:53 UTC
Fold is folding something but not keeping the type around.
Comment 3 Eric Botcazou 2003-12-20 12:50:21 UTC
Fixing.
Comment 4 GCC Commits 2003-12-23 05:26:49 UTC
Subject: Bug 13382

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ebotcazou@gcc.gnu.org	2003-12-23 05:26:41

Modified files:
	gcc            : ChangeLog c-typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: null-pointer-1.c 

Log message:
	PR c/13382
	* c-typeck.c (convert_for_assignment): When converting from
	integral type to pointer type, always call convert.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2080&r2=2.2081
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.266&r2=1.267
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3302&r2=1.3303
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/null-pointer-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Eric Botcazou 2003-12-23 06:24:35 UTC
See http://gcc.gnu.org/ml/gcc-patches/2003-12/msg01851.html