Bug 29106 - [4.0 Regression] sizeof(*var) in expression drops entire line of code out of compile
Summary: [4.0 Regression] sizeof(*var) in expression drops entire line of code out of ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.3
: P1 normal
Target Milestone: 4.0.4
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 31049 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-09-16 14:17 UTC by David Baraff
Modified: 2007-04-09 13:00 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.2.0 4.1.2
Known to fail: 4.1.1
Last reconfirmed: 2006-09-17 19:27:47


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Baraff 2006-09-16 14:17:32 UTC
#include <stdio.h>

int main()
{
    int* const savepos = sizeof(*savepos) ? 0 : 0;

    // code for the next line is left out!
    printf("size of thingy is %d\n", sizeof(*savepos));
}

Any line of code containing sizeof(*savepos) gets stripped.   If you compile and run this, nothing is printed.
Comment 1 David Baraff 2006-09-16 14:18:35 UTC
/*
Using built-in specs.
Target: x86_64-redhat-linux-gnu
Configured with: ../gcc-4.0.3/configure x86_64-redhat-linux-gnu --prefix=/pixar/d2/sets/t\
ools-03 --exec-prefix=/pixar/d2/sets/tools-03 --bindir=/pixar/d2/sets/tools-03/bin --sbin\
dir=/pixar/d2/sets/tools-03/sbin --sysconfdir=/pixar/d2/sets/tools-03/etc --datadir=/pixa\
r/d2/sets/tools-03/share --includedir=/pixar/d2/sets/tools-03/include --libdir=/pixar/d2/\
sets/tools-03/lib --libexecdir=/pixar/d2/sets/tools-03/libexec --localstatedir=/pixar/d2/\
sets/tools-03/var --sharedstatedir=/pixar/d2/sets/tools-03/com --mandir=/pixar/d2/sets/to\
ols-03/man --infodir=/pixar/d2/sets/tools-03/info --enable-version-specific-runtime-libs \
--enable-languages=c++,objc,f95 --enable-threads=posix --enable-shared --enable-mudflap
Thread model: posix
gcc version 4.0.3

Compile as:
   g++ bug.cpp

Issue:
   Calll to printf left out.  (Indeed, any line of code that
   contains sizeof(*savepos) gets tossed on the floor.  I assume
   since sizeof() is a compile-time construct, something took this a bit
   too far?
*/
Comment 2 Andrew Pinski 2006-09-16 23:42:05 UTC
The front-end was produce an error_mark_node when no error had been produced.
This works on the today's mainline but failed with "4.1.2 20060814".
Comment 3 Andrew Pinski 2006-09-16 23:45:36 UTC
It also worked in "4.1.0 20051026".
Comment 4 Andrew Pinski 2006-09-17 19:27:47 UTC
Confirmed, still broken as of today "4.1.2 20060917".
Comment 5 Richard Biener 2006-10-27 09:46:52 UTC
Janis, can you hunt this?  The 4.1 branch doesn't print anything while 4.2 prints
"size of thingy is 4".

Thanks!
Comment 6 Janis Johnson 2006-10-27 23:16:03 UTC
A regression hunt on the gcc-4_1-branch identified the following patch where the failure starts:

    http://gcc.gnu.org/viewcvs?view=rev&rev=111231

    r111231 | mmitchel | 2006-02-18 08:37:34 +0000 (Sat, 18 Feb 2006)
Comment 7 Mark Mitchell 2006-11-01 18:28:20 UTC
Egads, that's awful.
Comment 8 Mark Mitchell 2006-11-14 05:11:43 UTC
Subject: Bug 29106

Author: mmitchel
Date: Tue Nov 14 05:11:32 2006
New Revision: 118803

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118803
Log:
	PR c++/29106
	* init.c (constant_value_1): Treat a DECL_INITIAL of
	error_mark_node as meaning that the variable is uninitialized,
	rather than erroneously initialized.
	PR c++/29106
	* g++.dg/init/self1.C: New test.
	* g++.dg/other/fold1.C: Adjust error markers.
	* g++.dg/init/member1.C: Likewise.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/init/self1.C
Modified:
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/init.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/init/member1.C
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/other/fold1.C

Comment 9 Mark Mitchell 2006-11-14 05:17:34 UTC
Fixed in 4.1.2.
Comment 10 Mark Mitchell 2006-11-14 17:14:11 UTC
Subject: Bug 29106

Author: mmitchel
Date: Tue Nov 14 17:13:57 2006
New Revision: 118818

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118818
Log:
	PR c++/29106
	* g++.dg/init/self1.C: New test.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/init/self1.C
Modified:
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 11 Mark Mitchell 2006-11-14 17:15:17 UTC
Subject: Bug 29106

Author: mmitchel
Date: Tue Nov 14 17:15:08 2006
New Revision: 118819

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118819
Log:
	PR c++/29106
	* g++.dg/init/self1.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/init/self1.C
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 12 Volker Reichelt 2006-11-18 11:55:16 UTC
Btw, the fix ported PR28284 back to the 4.1 branch.
Comment 13 patchapp@dberlin.org 2007-01-27 18:05:24 UTC
Subject: Bug number PR c++/29106

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-01/msg02248.html
Comment 14 Volker Reichelt 2007-01-27 19:58:54 UTC
Subject: Bug 29106

Author: reichelt
Date: Sat Jan 27 19:58:38 2007
New Revision: 121238

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121238
Log:
	Backport:
	2006-11-13  Mark Mitchell  <mark@codesourcery.com>

	PR c++/29106
	* init.c (constant_value_1): Treat a DECL_INITIAL of
	error_mark_node as meaning that the variable is uninitialized,
	rather than erroneously initialized.

	* g++.dg/init/self1.C: New test.
	* g++.dg/other/fold1.C: Adjust error markers.
	* g++.dg/init/member1.C: Likewise.

	2006-08-27  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/28284
	* pt.c (fold_non_dependent_expr): Make sure expr is not dereferenced if it
	is NULL.

	* g++.dg/template/pr28284.C: New test.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/init/self1.C
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/template/pr28284.C
Modified:
    branches/gcc-4_0-branch/gcc/cp/ChangeLog
    branches/gcc-4_0-branch/gcc/cp/init.c
    branches/gcc-4_0-branch/gcc/cp/pt.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/init/member1.C
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/other/fold1.C

Comment 15 Volker Reichelt 2007-01-31 23:03:44 UTC
Also fixed in GCC 4.0.4.
Comment 16 Volker Reichelt 2007-04-09 13:00:36 UTC
*** Bug 31049 has been marked as a duplicate of this bug. ***