Bug 15209 - [3.4/4.0 Regression]Runs out of memory with packed structs
Summary: [3.4/4.0 Regression]Runs out of memory with packed structs
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.4.1
Assignee: Mark Mitchell
URL:
Keywords: ice-on-valid-code, memory-hog
: 15573 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-04-29 19:40 UTC by Wolfgang Bangerth
Modified: 2004-10-30 21:11 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.3.3
Known to fail: 3.4.0 4.0.0
Last reconfirmed: 2004-04-29 20:04:38


Attachments
preprocessed sources (108.20 KB, text/plain)
2004-04-29 19:41 UTC, Wolfgang Bangerth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Bangerth 2004-04-29 19:40:12 UTC
Taken from  http://gcc.gnu.org/ml/gcc-bugs/2004-04/msg02848.html :  
  
This is somewhat ironic: we run out of memory when using packed structs 
the wrong way ;-) 
 
I took the files from the package in above mail and tried to compile. Indeed, 
we get 
into a memory eating loop with the preprocessed source files I attach 
(it quickly runs into the 500-600 MB range and then eventually crashes 
for me). Removing the cause of the warning messages  
  x.ii:34314: warning: ignoring packed attribute on unpacked non-POD field 
    `MD5Hash PACKET_HEADER::hash' 
  x.ii:34315: warning: ignoring packed attribute on unpacked non-POD field 
   `MD5Hash PACKET_HEADER::setid' 
makes the problem to go away, though. Compile line is simply 
  c++ x.ii 
 
With 3.3.4, I get an ICE somewhere in the libstdc++ parts of 3.4, so I can't 
say from the preprocessed sources (all that I have left on my harddisk right 
now) whether this is a regression. 
 
I don't have the time to reduce memory hogs at present, so if someone else 
is interested in picking this up, feel free to. 
 
Wolfgang
Comment 1 Wolfgang Bangerth 2004-04-29 19:41:36 UTC
Created attachment 6189 [details]
preprocessed sources
Comment 2 Andrew Pinski 2004-04-29 20:04:35 UTC
Confirmed, reduced to at least (note this can most likely be reduced down further):
typedef unsigned int size_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;

typedef unsigned int uint32_t;
__extension__ typedef unsigned long long int uint64_t;

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;

struct MAGIC {u8 magic[8];} __attribute__ ((packed));
struct PACKETTYPE {u8 type[16];} __attribute__ ((packed));


typedef u16 leu16;
typedef u32 leu32;
typedef u64 leu64;

class MD5Hash
{
public:

  MD5Hash(void) {};

  void *print(void) const;
  MD5Hash(const MD5Hash &other);
  MD5Hash& operator=(const MD5Hash &other);

public:
  u8 hash[16];
};

struct PACKET_HEADER
{

  MAGIC magic;
  leu64 length;
  MD5Hash hash;
  MD5Hash setid;
  PACKETTYPE type;
} __attribute__ ((packed));


struct MAINPACKET
{
  PACKET_HEADER header;

  leu64 blocksize;
  leu32 recoverablefilecount;
  MD5Hash fileid[0];


} __attribute__ ((packed));

struct CriticalPacket
{
  u8 *packetdata;
  size_t packetlength;
};

class MainPacket : public CriticalPacket
{
  const MD5Hash& SetId(void) const;

  u64 blocksize;
  u32 totalfilecount;
  u32 recoverablefilecount;
};

inline const MD5Hash& MainPacket::SetId(void) const
{
  return ((const MAINPACKET*)packetdata)->header.setid;
}
Comment 3 Andrew Pinski 2004-05-21 19:29:36 UTC
*** Bug 15573 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2004-05-21 19:44:12 UTC
And here is the most reduced source:
struct MD5Hash
{
  MD5Hash(void) {};
  void *print(void) const;
  MD5Hash (const MD5Hash&);
};
struct PACKET_HEADER
{
  MD5Hash setid;
} __attribute__ ((packed));
const MD5Hash& SetId(unsigned char *packetdata)
{
  return ((const PACKET_HEADER*)packetdata)->setid;
}
Comment 5 Mark Mitchell 2004-05-28 21:03:57 UTC
I cannot reproduce this with the reduced case in Comment #4 using current 3.4.1
sources.  Is this still a problem?
Comment 6 Andrew Pinski 2004-05-28 21:22:49 UTC
Hmm, I think I reduced comment #2 too much.  I can still reproduce the one in comment #2 but not the 
one in comment #4.
Comment 7 Mark Mitchell 2004-05-31 17:58:46 UTC
Working on a fix.
Comment 8 CVS Commits 2004-05-31 21:04:26 UTC
Subject: Bug 15209

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-05-31 21:04:15

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog call.c cp-tree.h cvt.c name-lookup.c 
	                 pt.c tree.c typeck.c 
	gcc/testsuite/g++.dg/ext: packed3.C packed4.C 
	gcc/testsuite/g++.dg/template: friend.C 
Added files:
	gcc/testsuite/g++.dg/expr: ptrmem5.C 
	gcc/testsuite/g++.dg/ext: packed6.C 
	gcc/testsuite/g++.dg/template: friend27.C friend28.C 
	gcc/testsuite/g++.dg/warn: Wreturn-1.C 

Log message:
	PR c++/15742
	* call.c (build_over_call): Set
	current_function_returns_abnormally even in template functions.
	
	PR c++/15696
	* cp-tree.h (invalid_nonstatic_memfn_p): New function.
	* cvt.c (convert_to_void): Use it.
	* typeck.c (invalid_nonstatic_memfn_p): New function.
	(decay_conversion): Use it.
	
	PR c++/15625
	* pt.c (tsubst_decl): Set DECL_FRIEND_CONTEXT for instantiated
	templates.
	
	PR c++/15629
	* name-lookup.c (arg_assoc_class): Do not find template
	specializations.
	
	PR c++/15209
	* tree.c (lvalue_p_1): Only consider the right-hand side of "."
	expressions when determining whether or not an express is packed.
	
	PR c++/15742
	* g++.dg/warn/Wreturn-1.C: New test.
	
	PR c++/15696
	* g++.dg/expr/ptrmem5.C: New test.
	
	PR c++/15625
	* g++.dg/template/friend27.C: New test.
	
	PR c++/15629
	* g++.dg/template/friend28.C: New test.
	* g++.dg/template/friend.C: Do not depend on <iostream>.  Add
	error message.
	
	PR c++/15209
	* g++.dg/ext/packed3.C: Remove bogus error.
	* g++.dg/ext/packed4.C: Remove bogus check.
	* g++.dg/ext/packed6.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.187&r2=1.3389.2.188
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.109&r2=1.3892.2.110
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.452.2.16&r2=1.452.2.17
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.946.4.12&r2=1.946.4.13
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.151.4.1&r2=1.151.4.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.34.2.13&r2=1.34.2.14
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.816.2.26&r2=1.816.2.27
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/tree.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.360.4.5&r2=1.360.4.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.18&r2=1.519.2.19
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/ptrmem5.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/packed6.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/packed3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1&r2=1.1.24.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/packed4.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1&r2=1.1.24.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend27.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend28.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.5&r2=1.5.56.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wreturn-1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 9 CVS Commits 2004-05-31 21:24:38 UTC
Subject: Bug 15209

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-05-31 21:24:31

Modified files:
	gcc/cp         : call.c cp-tree.h cvt.c name-lookup.c pt.c 
	                 tree.c typeck.c 
	gcc/testsuite/g++.dg/ext: packed3.C packed4.C 
	gcc/testsuite/g++.dg/template: friend.C 
Added files:
	gcc/testsuite/g++.dg/expr: ptrmem5.C 
	gcc/testsuite/g++.dg/ext: packed6.C 
	gcc/testsuite/g++.dg/template: friend27.C friend28.C 
	gcc/testsuite/g++.dg/warn: Wreturn-1.C 

Log message:
	PR c++/15742
	* call.c (build_over_call): Set
	current_function_returns_abnormally even in template functions.
	
	PR c++/15696
	* cp-tree.h (invalid_nonstatic_memfn_p): New function.
	* cvt.c (convert_to_void): Use it.
	* typeck.c (invalid_nonstatic_memfn_p): New function.
	(decay_conversion): Use it.
	
	PR c++/15625
	* pt.c (tsubst_decl): Set DECL_FRIEND_CONTEXT for instantiated
	templates.
	
	PR c++/15629
	* name-lookup.c (arg_assoc_class): Do not find template
	specializations.
	
	PR c++/15209
	* tree.c (lvalue_p_1): Only consider the right-hand side of "."
	expressions when determining whether or not an express is packed.
	
	PR c++/15742
	* g++.dg/warn/Wreturn-1.C: New test.
	
	PR c++/15696
	* g++.dg/expr/ptrmem5.C: New test.
	
	PR c++/15625
	* g++.dg/template/friend27.C: New test.
	
	PR c++/15629
	* g++.dg/template/friend28.C: New test.
	* g++.dg/template/friend.C: Do not depend on <iostream>.  Add
	error message.
	
	PR c++/15209
	* g++.dg/ext/packed3.C: Remove bogus error.
	* g++.dg/ext/packed4.C: Remove bogus check.
	* g++.dg/ext/packed6.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.476&r2=1.477
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.969&r2=1.970
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&r1=1.156&r2=1.157
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.56&r2=1.57
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.856&r2=1.857
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/tree.c.diff?cvsroot=gcc&r1=1.374&r2=1.375
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.547&r2=1.548
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/ptrmem5.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/packed6.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/packed3.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/packed4.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend27.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend28.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend.C.diff?cvsroot=gcc&r1=1.5&r2=1.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wreturn-1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 10 Mark Mitchell 2004-05-31 21:29:20 UTC
Fixed in GCC 3.4.1.