public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/29582]  New: Parameter pushed to stack too soon
@ 2006-10-24 15:56 oder at eleks dot lviv dot ua
  2006-10-24 16:03 ` [Bug c++/29582] " schwab at suse dot de
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: oder at eleks dot lviv dot ua @ 2006-10-24 15:56 UTC (permalink / raw)
  To: gcc-bugs

Given class COtherClass having methods
class COtherClass
{
...
        inline COtherClass(unsigned int uiParam1, const char *pszParam2, const
char *pszParam3, unsigned long ulParam4, const char *pszParam5)
        {...}
        ~COtherClass();
        COtherClass &Method1();
        COtherClass &Method2(unsigned long long &ullParam);
        COtherClass &operator ()(const char *pszParam1, const void *pvParam2);
        COtherClass &operator ()(const char *pszParam1, unsigned long long
ullParam2) { ... }
};

For code 
struct CHostClass
{
public:
        unsigned long long m_ullProblemField;
        const void      *m_pvPointerField;
        const char      *m_szSzField;

        ~CHostClass()
        {
                COtherClass(5, m_szSzField, NULL, 0,
"ImmString1").Method1().Method2(m_ullProblemField)("ImmString2",
m_pvPointerField)("ImmString3", m_ullProblemField);
        }
};

GCC generated the following assembler text (debug build)
mov    0x8(%ebp),%eax // CHostClass::this
pushl  0x4(%eax) // HI(CHostClass::m_ullProblemField)
pushl  (%eax) // LO(CHostClass::m_ullProblemField)
push   $0x81f10f9 // "ImmString3"
sub    $0x8,%esp
mov    0x8(%ebp),%eax // CHostClass::this
pushl  0x8(%eax) // CHostClass::m_pvPointerField
push   $0x81f0e3a // "ImmString2"
sub    $0xc,%esp
pushl  0x8(%ebp) // CHostClass::this <=> offset CHostClass::m_ullProblemField
sub    $0xc,%esp
push   $0x81f1104 // "ImmString1"
push   $0x0 // 0
push   $0x0 // NULL
mov    0x8(%ebp),%eax // CHostClass::this
pushl  0xc(%eax) // CHostClass::m_szSzField
push   $0x5 // 5
lea    0xfffff4e8(%ebp),%eax // storage for COtherClass instance
push   %eax
call   0x804e61c // COtherClass::COtherClass constructor
add    $0x24,%esp // 6*4 params + 12 reserve made with "sub $0xc,%esp"
lea    0xfffff4e8(%ebp),%eax // instance of COtherClass
push   %eax
call   0x818e68e // COtherClass::Method1
add    $0x4,%esp // 1 param
push   %eax // instance of COtherClass
call   0x8190384 // COtherClass::Method2
add    $0x14,%esp // 2*4 params + 12 reserve made with "sub $0xc,%esp"
push   %eax // instance of COtherClass
call   0x818e85c // COtherClass::operator()(const char *, const void *)
add    $0x14,%esp // 3*4 params + 8 reserve made with "sub $0x8,%esp"
push   %eax // instance of COtherClass
call   0x804f322 // COtherClass::operator()(const char *, unsigned long long)
add    $0x10,%esp // 2*4 + 1*8 params
sub    $0xc,%esp
lea    0xfffff4e8(%ebp),%eax // instance of COtherClass
push   %eax
call   0x818e610 // COtherClass::~COtherClass
add    $0x10,%esp // 1*4 params + 12 reserve made with "sub $0xc,%esp"

The problem is that the value of m_ullProblemField is pushed to stack at the
very beginning of code while it is modified later during invocation of
COtherClass::Method2. COtherClass::operator (const char *, unsigned long long)
should receive modified value of field but it receives initial one.


-- 
           Summary: Parameter pushed to stack too soon
           Product: gcc
           Version: 3.3.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: oder at eleks dot lviv dot ua
 GCC build triplet: x86
  GCC host triplet: x86
GCC target triplet: x86


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29582


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29582] Parameter pushed to stack too soon
  2006-10-24 15:56 [Bug c++/29582] New: Parameter pushed to stack too soon oder at eleks dot lviv dot ua
@ 2006-10-24 16:03 ` schwab at suse dot de
  2006-10-24 16:10 ` oder at eleks dot lviv dot ua
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: schwab at suse dot de @ 2006-10-24 16:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from schwab at suse dot de  2006-10-24 16:02 -------
The evaluation order of function arguments is not specified.  If you depend on
side effects to be carried out at a specific point you must make sure there is
a sequence point at the appropriate place.


-- 

schwab at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29582


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29582] Parameter pushed to stack too soon
  2006-10-24 15:56 [Bug c++/29582] New: Parameter pushed to stack too soon oder at eleks dot lviv dot ua
  2006-10-24 16:03 ` [Bug c++/29582] " schwab at suse dot de
@ 2006-10-24 16:10 ` oder at eleks dot lviv dot ua
  2006-10-29 20:40 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: oder at eleks dot lviv dot ua @ 2006-10-24 16:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from oder at eleks dot lviv dot ua  2006-10-24 16:09 -------
(In reply to comment #1)
> The evaluation order of function arguments is not specified.  If you depend on
> side effects to be carried out at a specific point you must make sure there is
> a sequence point at the appropriate place.

These are not the arguments of a single function. Given example is the sequence
of method invocations for a class instance. Modification of lvalue occurs in
2nd method invocation and it is supposed to be passed to 4th method invocation.


-- 

oder at eleks dot lviv dot ua changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29582


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29582] Parameter pushed to stack too soon
  2006-10-24 15:56 [Bug c++/29582] New: Parameter pushed to stack too soon oder at eleks dot lviv dot ua
  2006-10-24 16:03 ` [Bug c++/29582] " schwab at suse dot de
  2006-10-24 16:10 ` oder at eleks dot lviv dot ua
@ 2006-10-29 20:40 ` pinskia at gcc dot gnu dot org
  2006-10-30  8:33 ` oder at eleks dot lviv dot ua
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-29 20:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-10-29 20:40 -------
Do you have a testcase that actually compiles?


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29582


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29582] Parameter pushed to stack too soon
  2006-10-24 15:56 [Bug c++/29582] New: Parameter pushed to stack too soon oder at eleks dot lviv dot ua
                   ` (2 preceding siblings ...)
  2006-10-29 20:40 ` pinskia at gcc dot gnu dot org
@ 2006-10-30  8:33 ` oder at eleks dot lviv dot ua
  2006-10-30  8:41 ` oder at eleks dot lviv dot ua
  2006-10-31  0:01 ` bangerth at dealii dot org
  5 siblings, 0 replies; 7+ messages in thread
From: oder at eleks dot lviv dot ua @ 2006-10-30  8:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from oder at eleks dot lviv dot ua  2006-10-30 08:33 -------
Created an attachment (id=12509)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12509&action=view)
Compilable testcase


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29582


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29582] Parameter pushed to stack too soon
  2006-10-24 15:56 [Bug c++/29582] New: Parameter pushed to stack too soon oder at eleks dot lviv dot ua
                   ` (3 preceding siblings ...)
  2006-10-30  8:33 ` oder at eleks dot lviv dot ua
@ 2006-10-30  8:41 ` oder at eleks dot lviv dot ua
  2006-10-31  0:01 ` bangerth at dealii dot org
  5 siblings, 0 replies; 7+ messages in thread
From: oder at eleks dot lviv dot ua @ 2006-10-30  8:41 UTC (permalink / raw)
  To: gcc-bugs



-- 

oder at eleks dot lviv dot ua changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |UNCONFIRMED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29582


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29582] Parameter pushed to stack too soon
  2006-10-24 15:56 [Bug c++/29582] New: Parameter pushed to stack too soon oder at eleks dot lviv dot ua
                   ` (4 preceding siblings ...)
  2006-10-30  8:41 ` oder at eleks dot lviv dot ua
@ 2006-10-31  0:01 ` bangerth at dealii dot org
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2006-10-31  0:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bangerth at dealii dot org  2006-10-31 00:01 -------
(In reply to comment #0)
>                 COtherClass(5, m_szSzField, NULL, 0,
> "ImmString1").Method1().Method2(m_ullProblemField)("ImmString2",
> m_pvPointerField)("ImmString3", m_ullProblemField);
> [...]
> The problem is that the value of m_ullProblemField is pushed to stack at the
> very beginning of code while it is modified later during invocation of
> COtherClass::Method2. COtherClass::operator (const char *, unsigned long long)
> should receive modified value of field but it receives initial one.

No. The order of evaluation of your sequence of function calls is 
unspecified. There is no sequence point within your chain of calls, and
therefore the compiler is free to select whatever order for evaluating
the arguments of all these calls.

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29582


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-10-31  0:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-24 15:56 [Bug c++/29582] New: Parameter pushed to stack too soon oder at eleks dot lviv dot ua
2006-10-24 16:03 ` [Bug c++/29582] " schwab at suse dot de
2006-10-24 16:10 ` oder at eleks dot lviv dot ua
2006-10-29 20:40 ` pinskia at gcc dot gnu dot org
2006-10-30  8:33 ` oder at eleks dot lviv dot ua
2006-10-30  8:41 ` oder at eleks dot lviv dot ua
2006-10-31  0:01 ` bangerth at dealii dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).