public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47357] New: volatile member function is not treated as volatile
@ 2011-01-19 9:56 yottui at yahoo dot co.jp
2011-01-19 11:24 ` [Bug c++/47357] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: yottui at yahoo dot co.jp @ 2011-01-19 9:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47357
Summary: volatile member function is not treated as volatile
Product: gcc
Version: 4.5.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: yottui@yahoo.co.jp
When I execute the following test code with '-O2 -msse2' compiler options, it
outputs the wrong value.
I'm expecting that pC[1] will be 2.
operator[](int) is defined as volatile. However v is not treated as volatile.
And I tried (volatile const u &) instead of (const u &) when the casting, but
it's not affected.
-- begin test case --
//g++ -O2 -msse2 test.cpp
#include <stdio.h>
#include <stdint.h>
#include <emmintrin.h>
#define NELEM 1
struct int4
{
__m128i v;
int4(__m128i a) : v(a) {}
int4(int a0, int a1, int a2, int a3)
: v(_mm_setr_epi32(a0, a1, a2, a3)) {}
operator __m128i() const { return v; }
int operator [](int i) volatile const
{
union u {
__m128i m128;
int i32[4];
};
return ((const u &)v).i32[i];
}
};
inline int4 operator <<(const int4 & a, const int4 & b)
{ return int4(a[0]<<b[0], a[1]<<b[1], a[2]<<b[2], a[3]<<b[3]); }
__attribute__((noinline)) void shift_left(
int n, const __m128i a[], const __m128i b[], __m128i c[])
{
for ( int j = 0; j < n; ++j )
{
c[j] = int4(a[j]) << int4(b[j]);
}
}
int main( int argc, char * argv[] )
{
__m128i * a = new __m128i[NELEM+1];
__m128i * b = new __m128i[NELEM+1];
__m128i * c = new __m128i[NELEM+1];
a = (__m128i *)(-sizeof(*a) & (intptr_t)&a[1]);
b = (__m128i *)(-sizeof(*b) & (intptr_t)&b[1]);
c = (__m128i *)(-sizeof(*c) & (intptr_t)&c[1]);
for ( int i = 0; i < NELEM*4; ++i )
{
((int *)a)[i] = i;
((int *)b)[i] = i & 31;
((int *)c)[i] = 0;
}
shift_left(NELEM, a, b, c);
const int * pA = (const int *)a;
const int * pB = (const int *)b;
const int * pC = (const int *)c;
for ( int i = 0; i < NELEM*4; ++i )
{
printf("%08x << %08x = %08x\n",
pA[i], pB[i], pC[i]);
}
}
-- end test case --
-- begin output --
00000000 << 00000000 = 58a00000
00000001 << 00000001 = e9000000
00000002 << 00000002 = b5f40000
00000003 << 00000003 = 00000000
-- end output --
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/47357] volatile member function is not treated as volatile
2011-01-19 9:56 [Bug c++/47357] New: volatile member function is not treated as volatile yottui at yahoo dot co.jp
@ 2011-01-19 11:24 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-01-19 11:24 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47357
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-01-19 10:44:54 UTC ---
I can't see anything in the program that would be affected by a 'volatile'
keyword. Instead I see a lot of bogus ways to try to circumvent type-based
aliasing rules (using volatile is one). Use -fno-strict-aliasing.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-01-19 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-19 9:56 [Bug c++/47357] New: volatile member function is not treated as volatile yottui at yahoo dot co.jp
2011-01-19 11:24 ` [Bug c++/47357] " rguenth at gcc dot gnu.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).