public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/27838]  New: Wrong code generated for for()-loop with enumerated type as index
@ 2006-05-31 12:51 oder at eleks dot lviv dot ua
  2006-05-31 13:05 ` [Bug c++/27838] " schwab at suse dot de
  0 siblings, 1 reply; 2+ messages in thread
From: oder at eleks dot lviv dot ua @ 2006-05-31 12:51 UTC (permalink / raw)
  To: gcc-bugs

I have enumerated type defined as follows

enum EQUEUEDWRITERFILEERROR
{
        QWFE__MIN,

        QWFE_REOPEN = QWFE__MIN,
        QWFE_WRITE,
        QWFE_OVERFLOW,

        QWFE__MAX,
};

For it I have prefix increment operator defined with macro
#define DEFINE_ENUM_INC_DEC(EnumType) \
        static inline EnumType &operator ++(EnumType &Value) { return (EnumType
&)(++((int &)Value)); }

For following for-loop operator
        for (EQUEUEDWRITERFILEERROR qwfeError = QWFE__MIN; qwfeError !=
QWFE__MAX; ++qwfeError)

compiler generated wrong code for condition check
0x8090981 mov    0xffffffd7(%ebp),%edx
0x8090984 mov    0xffffffd7(%ebp),%al
0x8090987 inc    %edx
0x8090988 cmp    $0x3,%al
0x809098a mov    %edx,0xffffffd7(%ebp)
0x809098d jne    0x8090940 

That is, variable is incremented in parallel with loop condition check and
result of increment has effect to loop condition only on the next pass. This
causes the loop to execute one time more than required.

Compilation options used
-malign-double -fshort-enums -freg-struct-return -fno-exceptions -g -O3
-march=pentium -fno-rtti -fconserve-space


-- 
           Summary: Wrong code generated for for()-loop with enumerated type
                    as index
           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=27838


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

* [Bug c++/27838] Wrong code generated for for()-loop with enumerated type as index
  2006-05-31 12:51 [Bug c++/27838] New: Wrong code generated for for()-loop with enumerated type as index oder at eleks dot lviv dot ua
@ 2006-05-31 13:05 ` schwab at suse dot de
  0 siblings, 0 replies; 2+ messages in thread
From: schwab at suse dot de @ 2006-05-31 13:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from schwab at suse dot de  2006-05-31 13:04 -------
You are violating the aliasing rules.

*** This bug has been marked as a duplicate of 21920 ***


-- 

schwab at suse dot de changed:

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


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


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

end of thread, other threads:[~2006-05-31 13:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-31 12:51 [Bug c++/27838] New: Wrong code generated for for()-loop with enumerated type as index oder at eleks dot lviv dot ua
2006-05-31 13:05 ` [Bug c++/27838] " schwab at suse dot de

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).