15209 – [3.4/4.0 Regression]Runs out of memory with packed structs (original) (raw)
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 2 Drea 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 Drea Pinski 2004-05-21 19:29:36 UTC
*** Bug 15573 has been marked as a duplicate of this bug. ***
Comment 4 Drea 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 7 Mark Mitchell 2004-05-31 17:58:46 UTC
Working on a fix.
Comment 10 Mark Mitchell 2004-05-31 21:29:20 UTC
Fixed in GCC 3.4.1.