public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/22597] New: pure attribute produces incorrect results
@ 2005-07-21 19:54 eda-qa at disemia dot com
  2005-07-21 19:55 ` [Bug c++/22597] " eda-qa at disemia dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: eda-qa at disemia dot com @ 2005-07-21 19:54 UTC (permalink / raw)
  To: gcc-bugs

In the attached code the pure attribute is causing the result to be random/junk
on the final calculation in main.  According to the docs the function seems to
qualify for pure status -- it uses only the parameters given.   It does however
create a temporary (but as this exists on the stack I assumed it is okay, since
it still doesn't violate the notion of being pure).

Expected result (with -DNOATTRIB or -DNOCOPYCTOR flags):
5, 5
1, 1

Actual Result (compiled with g++ -o test point_err.cc):
5, 5
338848, 4.85849e-270

(NOTE: Worked on 3.3)

It is curious also that no declaring the copy constructor also allows this code
to work with the pure attribute.

So, either this is a bug in the 4.0 "pure" handling, or the documentation for
"pure" is omitting some vital point which my code violates.

-- 
           Summary: pure attribute produces incorrect results
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: eda-qa at disemia dot com
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/22597] pure attribute produces incorrect results
  2005-07-21 19:54 [Bug c++/22597] New: pure attribute produces incorrect results eda-qa at disemia dot com
@ 2005-07-21 19:55 ` eda-qa at disemia dot com
  2005-07-21 19:56 ` eda-qa at disemia dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: eda-qa at disemia dot com @ 2005-07-21 19:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From eda-qa at disemia dot com  2005-07-21 19:54 -------
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr--enable-shared
--with-system-zlib --libexecdir=/usr/lib --enable-nls --without-included-gettext
--enable-threads=posix --program-suffix=-4.0 --enable-__cxa_atexit
--enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug
--enable-java-gc=boehm --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.1 (Debian 4.0.1-2)


-- 


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


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

* [Bug c++/22597] pure attribute produces incorrect results
  2005-07-21 19:54 [Bug c++/22597] New: pure attribute produces incorrect results eda-qa at disemia dot com
  2005-07-21 19:55 ` [Bug c++/22597] " eda-qa at disemia dot com
@ 2005-07-21 19:56 ` eda-qa at disemia dot com
  2005-07-21 20:15 ` [Bug c++/22597] [4.1 Regression] " pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: eda-qa at disemia dot com @ 2005-07-21 19:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From eda-qa at disemia dot com  2005-07-21 19:55 -------
Created an attachment (id=9325)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9325&action=view)
demostration of the error


-- 


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


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

* [Bug c++/22597] [4.1 Regression] pure attribute produces incorrect results
  2005-07-21 19:54 [Bug c++/22597] New: pure attribute produces incorrect results eda-qa at disemia dot com
  2005-07-21 19:55 ` [Bug c++/22597] " eda-qa at disemia dot com
  2005-07-21 19:56 ` eda-qa at disemia dot com
@ 2005-07-21 20:15 ` pinskia at gcc dot gnu dot org
  2005-07-25 16:34 ` [Bug c++/22597] [3.4/4.0 " reichelt at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-21 20:15 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-21 20:14 -------
Confirmed, reduced testcase:
extern "C" void abort(void);
int t = 0;
struct point
{
        point( const point& o ) {}
        explicit point(){}
        point __attribute__((pure)) operator/(const double m ) const
        {
                t++;
        }
};
void f(const point&){}
 int main()
 {
        point a;
        f(a / 5.0);
  if (t!=1)
    abort();
        return 0;
 }

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.0.1
      Known to work|                            |3.4.0 4.1.0
   Last reconfirmed|0000-00-00 00:00:00         |2005-07-21 20:14:55
               date|                            |
            Summary|pure attribute produces     |[4.1 Regression] pure
                   |incorrect results           |attribute produces incorrect
                   |                            |results
   Target Milestone|---                         |4.0.2


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


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

* [Bug c++/22597] [3.4/4.0 Regression] pure attribute produces incorrect results
  2005-07-21 19:54 [Bug c++/22597] New: pure attribute produces incorrect results eda-qa at disemia dot com
                   ` (2 preceding siblings ...)
  2005-07-21 20:15 ` [Bug c++/22597] [4.1 Regression] " pinskia at gcc dot gnu dot org
@ 2005-07-25 16:34 ` reichelt at gcc dot gnu dot org
  2005-07-25 17:55 ` reichelt at gcc dot gnu dot org
  2005-09-27 16:15 ` mmitchel at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-07-25 16:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2005-07-25 16:02 -------
I don't think that Andrew's example is valid, since a pure function
modifies global data. Btw, shouldn't the compiler complain about that?

Here's an example that is valid IMHO:

==================================================
extern "C" void abort();

struct A
{
    int i;

    A()           : i(1) {}
    A(const A& a) : i(1) {}
};

A __attribute__((pure)) foo() { return A(); }

int main()
{
    if (foo().i != 1)
        abort();
    return 0;
}
==================================================

The abort is triggered on the 3.4 branch and the 4.0 branch.
GCC 3.3.6 and mainline work fine.

The same happens, if one uses __attribute__((const)).


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |reichelt at gcc dot gnu dot
                   |                            |org
           Keywords|                            |monitored
      Known to fail|4.0.1                       |3.4.0 4.0.1
      Known to work|3.4.0 4.1.0                 |3.3.6 4.1.0
            Summary|[4.0 Regression] pure       |[3.4/4.0 Regression] pure
                   |attribute produces incorrect|attribute produces incorrect
                   |results                     |results


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


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

* [Bug c++/22597] [3.4/4.0 Regression] pure attribute produces incorrect results
  2005-07-21 19:54 [Bug c++/22597] New: pure attribute produces incorrect results eda-qa at disemia dot com
                   ` (3 preceding siblings ...)
  2005-07-25 16:34 ` [Bug c++/22597] [3.4/4.0 " reichelt at gcc dot gnu dot org
@ 2005-07-25 17:55 ` reichelt at gcc dot gnu dot org
  2005-09-27 16:15 ` mmitchel at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-07-25 17:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2005-07-25 17:13 -------
Jason, this was fixed on mainline by your patch for PR 19317:
http://gcc.gnu.org/ml/gcc-cvs/2005-06/msg00858.html

Would you mind looking at this problem, too?


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu dot org


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


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

* [Bug c++/22597] [3.4/4.0 Regression] pure attribute produces incorrect results
  2005-07-21 19:54 [Bug c++/22597] New: pure attribute produces incorrect results eda-qa at disemia dot com
                   ` (4 preceding siblings ...)
  2005-07-25 17:55 ` reichelt at gcc dot gnu dot org
@ 2005-09-27 16:15 ` mmitchel at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-09-27 16:15 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.2                       |4.0.3


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


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

end of thread, other threads:[~2005-09-27 16:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-21 19:54 [Bug c++/22597] New: pure attribute produces incorrect results eda-qa at disemia dot com
2005-07-21 19:55 ` [Bug c++/22597] " eda-qa at disemia dot com
2005-07-21 19:56 ` eda-qa at disemia dot com
2005-07-21 20:15 ` [Bug c++/22597] [4.1 Regression] " pinskia at gcc dot gnu dot org
2005-07-25 16:34 ` [Bug c++/22597] [3.4/4.0 " reichelt at gcc dot gnu dot org
2005-07-25 17:55 ` reichelt at gcc dot gnu dot org
2005-09-27 16:15 ` mmitchel 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).