public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "yottui at yahoo dot co.jp" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/47357] New: volatile member function is not treated as volatile Date: Wed, 19 Jan 2011 09:56:00 -0000 [thread overview] Message-ID: <bug-47357-4@http.gcc.gnu.org/bugzilla/> (raw) 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 --
next reply other threads:[~2011-01-19 9:00 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-01-19 9:56 yottui at yahoo dot co.jp [this message] 2011-01-19 11:24 ` [Bug c++/47357] " rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-47357-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).