Bug 7046 - #pragma pack(1) context evaluated at point of instantiation rather than declaration
Summary: #pragma pack(1) context evaluated at point of instantiation rather than decla...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 2.95.3
: P3 normal
Target Milestone: 4.5.0
Assignee: Jason Merrill
URL:
Keywords: wrong-code
: 10332 16044 21560 34614 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-06-16 02:56 UTC by wuerkner
Modified: 2014-02-16 13:13 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-10-04 01:50:24


Attachments
gcc_bug.tar.gz (671 bytes, application/x-gzip )
2003-05-21 15:16 UTC, wuerkner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description wuerkner 2002-06-16 02:56:01 UTC
templates that are instantiated within a #pragma pack(1) context, generate code as if they where defined with #pragma pack(1).
The result is, that one can create instantiations (in other compile units) that place class member variables on different memory locations for the SAME template arguments. Thus leeding to obvious data corruption when accessing them from different compile units.

Release:
gcc 2.95.3

Environment:
SuSE Linux 7.3 (Kernel 2.4.18)

How-To-Repeat:
Unpack Attachment.
cd gcc_bug
./run.sh (compiles and runs example)
Comment 1 wuerkner 2002-06-16 02:56:01 UTC
Fix:
template instantiations should respect the #pragma pack-state of their definition. The current state when beeing instantiated should be irrelevant.
Comment 2 Wolfgang Bangerth 2002-11-21 17:25:39 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed. Not sure what the right answer is, but it would
    certainly be beneficial if the pragma-pack thing would be
    considered at the point of declaration, not at the point of
    instantiation -- just like an attribute attached to the type.
Comment 3 Andrew Pinski 2003-08-02 17:59:28 UTC
Looks like we have a large number of these "top level" bugs where things apply at the 
top level when instantiating when they should not apply.
Comment 4 Andrew Pinski 2003-08-22 02:05:14 UTC
*** Bug 10332 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2004-06-18 02:06:29 UTC
*** Bug 16044 has been marked as a duplicate of this bug. ***
Comment 6 Jason Merrill 2007-10-04 01:50:08 UTC
*** Bug 21560 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2007-12-29 16:58:10 UTC
*** Bug 34614 has been marked as a duplicate of this bug. ***
Comment 8 Jason Merrill 2009-11-06 03:33:39 UTC
Subject: Bug 7046

Author: jason
Date: Fri Nov  6 03:33:17 2009
New Revision: 153959

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153959
Log:
	PR c++/7046
	* class.c (finish_struct): Store maximum_field_alignment in
	TYPE_PRECISION.
	* pt.c (instantiate_class_template): Set maximum_field_alignment.

Added:
    trunk/gcc/testsuite/g++.dg/abi/pragma-pack1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog

Comment 9 Jason Merrill 2009-11-06 04:08:19 UTC
Fixed for 4.5.
Comment 10 Jackie Rosen 2014-02-16 13:13:15 UTC Comment hidden (spam)