public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18468] New: bad code in template function called from template class method
@ 2004-11-13 20:31 james_avera at yahoo dot com
  2004-11-13 20:32 ` [Bug c++/18468] " james_avera at yahoo dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: james_avera at yahoo dot com @ 2004-11-13 20:31 UTC (permalink / raw)
  To: gcc-bugs

A template function (which swaps two values)
is called in a loop in an inlined method of a template class.  The number
of loop iterations is a constant, so the compiler might be trying to unroll
the loop.

The final assignment of the swap function is not executed after the
first iteration, causing incorrect results.

The problem occurs with -O2 or -O3, but not with -O.

I will attach a self-contained demo program.

-- 
           Summary: bad code in template function called from template class
                    method
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: james_avera at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i586-suse-linux-gnu
  GCC host triplet: i586-suse-linux-gnu
GCC target triplet: i586-suse-linux-gnu


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


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

* [Bug c++/18468] bad code in template function called from template class method
  2004-11-13 20:31 [Bug c++/18468] New: bad code in template function called from template class method james_avera at yahoo dot com
@ 2004-11-13 20:32 ` james_avera at yahoo dot com
  2004-11-13 20:37 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: james_avera at yahoo dot com @ 2004-11-13 20:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From james_avera at yahoo dot com  2004-11-13 20:32 -------
Created an attachment (id=7542)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7542&action=view)
test case

Please compile with -O2

-- 


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


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

* [Bug c++/18468] bad code in template function called from template class method
  2004-11-13 20:31 [Bug c++/18468] New: bad code in template function called from template class method james_avera at yahoo dot com
  2004-11-13 20:32 ` [Bug c++/18468] " james_avera at yahoo dot com
@ 2004-11-13 20:37 ` pinskia at gcc dot gnu dot org
  2004-11-16  2:47 ` james_avera at yahoo dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-13 20:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-13 20:37 -------
You are violating the C++ aliasing rules:

class GetPtrtokeyFunctor {
    public: 
    const PtrInt * operator()(const Objptr & objptr)
            { return reinterpret_cast<const PtrInt *>(&objptr); }
};



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


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


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

* [Bug c++/18468] bad code in template function called from template class method
  2004-11-13 20:31 [Bug c++/18468] New: bad code in template function called from template class method james_avera at yahoo dot com
  2004-11-13 20:32 ` [Bug c++/18468] " james_avera at yahoo dot com
  2004-11-13 20:37 ` pinskia at gcc dot gnu dot org
@ 2004-11-16  2:47 ` james_avera at yahoo dot com
  2004-11-16  2:52 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: james_avera at yahoo dot com @ 2004-11-16  2:47 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From james_avera at yahoo dot com  2004-11-16 02:47 -------
Subject: Re:  bad code in template function called from template class method

Hi,
Can you summarize what aliasing rule is violated?

Note that the argument is a ref, so the code is
not taking the adderess of a temporary.

Thanks,
-Jim

--- pinskia at gcc dot gnu dot org <gcc-bugzilla@gcc.gnu.org>
wrote:

> 
> ------- Additional Comments From pinskia at gcc dot gnu dot org 
> 2004-11-13 20:37 -------
> You are violating the C++ aliasing rules:
> 
> class GetPtrtokeyFunctor {
>     public: 
>     const PtrInt * operator()(const Objptr & objptr)
>             { return reinterpret_cast<const PtrInt *>(&objptr); }
> };
> 
> 
> 
> -- 
>            What    |Removed                     |Added
>
----------------------------------------------------------------------------
>              Status|UNCONFIRMED                 |RESOLVED
>          Resolution|                            |INVALID
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18468
> 
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
> 


=====
__________________________________________________
Please do not put me on a mailing list or give my 
address(es) to anyone else.


		
__________________________________ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 



-- 


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


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

* [Bug c++/18468] bad code in template function called from template class method
  2004-11-13 20:31 [Bug c++/18468] New: bad code in template function called from template class method james_avera at yahoo dot com
                   ` (2 preceding siblings ...)
  2004-11-16  2:47 ` james_avera at yahoo dot com
@ 2004-11-16  2:52 ` pinskia at gcc dot gnu dot org
  2005-06-05  9:04 ` pinskia at gcc dot gnu dot org
  2005-06-05  9:04 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-16  2:52 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-16 02:52 -------
Read http://gcc.gnu.org/bugs.html#nonbugs_general

Casting does not work as expected when optimization is turned on.

-- 


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


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

* [Bug c++/18468] bad code in template function called from template class method
  2004-11-13 20:31 [Bug c++/18468] New: bad code in template function called from template class method james_avera at yahoo dot com
                   ` (4 preceding siblings ...)
  2005-06-05  9:04 ` pinskia at gcc dot gnu dot org
@ 2005-06-05  9:04 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-05  9:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-05 09:04 -------
Reopening to ...

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


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


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

* [Bug c++/18468] bad code in template function called from template class method
  2004-11-13 20:31 [Bug c++/18468] New: bad code in template function called from template class method james_avera at yahoo dot com
                   ` (3 preceding siblings ...)
  2004-11-16  2:52 ` pinskia at gcc dot gnu dot org
@ 2005-06-05  9:04 ` pinskia at gcc dot gnu dot org
  2005-06-05  9:04 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-05  9:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-05 09:04 -------
Mark as a dup of bug 21920

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

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


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


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

end of thread, other threads:[~2005-06-05  9:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-13 20:31 [Bug c++/18468] New: bad code in template function called from template class method james_avera at yahoo dot com
2004-11-13 20:32 ` [Bug c++/18468] " james_avera at yahoo dot com
2004-11-13 20:37 ` pinskia at gcc dot gnu dot org
2004-11-16  2:47 ` james_avera at yahoo dot com
2004-11-16  2:52 ` pinskia at gcc dot gnu dot org
2005-06-05  9:04 ` pinskia at gcc dot gnu dot org
2005-06-05  9:04 ` pinskia at gcc dot gnu 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).