public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54893] New: unable to access volatile variable within relaxed transaction
@ 2012-10-10 17:46 spear at cse dot lehigh.edu
  2012-10-11 10:41 ` [Bug c++/54893] " aldyh at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: spear at cse dot lehigh.edu @ 2012-10-10 17:46 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 54893
           Summary: unable to access volatile variable within relaxed
                    transaction
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: spear@cse.lehigh.edu


Attempts to access a volatile variable in gcc or g++ fails.

Sample code:
    #include <stdio.h>
    volatile int test_var = 0;
    int main()
    {
      __transaction_relaxed {
        test_var++;
      }
      printf("Changed variable value to %d\n", test_var);
    }

Compilation:
    g++ test.c -o test -fgnu-tm

Error:
    test.c:6:15: error: invalid volatile use of 'test_var' inside transaction

gcc version info:
    g++ (GCC) 4.7.1
    Copyright (C) 2012 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


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

* [Bug c++/54893] unable to access volatile variable within relaxed transaction
  2012-10-10 17:46 [Bug c++/54893] New: unable to access volatile variable within relaxed transaction spear at cse dot lehigh.edu
@ 2012-10-11 10:41 ` aldyh at gcc dot gnu.org
  2012-10-11 13:21 ` spear at cse dot lehigh.edu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: aldyh at gcc dot gnu.org @ 2012-10-11 10:41 UTC (permalink / raw)
  To: gcc-bugs


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

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pmarlier at gcc dot gnu.org

--- Comment #1 from Aldy Hernandez <aldyh at gcc dot gnu.org> 2012-10-11 10:40:53 UTC ---
Please see bug 46654.  This error was added on purpose.  Has the specification
changed and volatiles are now allowed inside transactions?


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

* [Bug c++/54893] unable to access volatile variable within relaxed transaction
  2012-10-10 17:46 [Bug c++/54893] New: unable to access volatile variable within relaxed transaction spear at cse dot lehigh.edu
  2012-10-11 10:41 ` [Bug c++/54893] " aldyh at gcc dot gnu.org
@ 2012-10-11 13:21 ` spear at cse dot lehigh.edu
  2012-10-11 19:54 ` torvald at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: spear at cse dot lehigh.edu @ 2012-10-11 13:21 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Mike Spear <spear at cse dot lehigh.edu> 2012-10-11 13:21:19 UTC ---
There is a key difference here.  The transaction in my example is /relaxed/. 
According to the specification, there are no restrictions on what a relaxed
transaction can do.  Relaxed transactions can call unsafe functions, do I/O,
acquire locks, execute inline asm, etc.  And access to C++11 atomics and C11
volatiles is definitely legal in relaxed transactions.

If I understand the GCC TM implementation correctly, immediately before the
attempt to access a volatile within the relaxed transaction, the transaction
will need to become serial irrevocable, after which point it can continue to
access and directly modify volatile variables.

Note that a workaround for the time being is to move the volatile access into a
function, to *not* mark the function [[transaction_callable]], and then to call
the function instead of accessing the volatile directly.  This will achieve the
exact same behavior as is expected, though with the overhead of a function call
on each volatile access within a relaxed transaction.  However, longer term
this is definitely a bug in the current implementation.


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

* [Bug c++/54893] unable to access volatile variable within relaxed transaction
  2012-10-10 17:46 [Bug c++/54893] New: unable to access volatile variable within relaxed transaction spear at cse dot lehigh.edu
  2012-10-11 10:41 ` [Bug c++/54893] " aldyh at gcc dot gnu.org
  2012-10-11 13:21 ` spear at cse dot lehigh.edu
@ 2012-10-11 19:54 ` torvald at gcc dot gnu.org
  2012-10-11 20:29 ` aldyh at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: torvald at gcc dot gnu.org @ 2012-10-11 19:54 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from torvald at gcc dot gnu.org 2012-10-11 19:54:11 UTC ---
I agree with Michael.  Accesses to volative vars are disallowed in safe code,
but relaxed transactions can run unsafe code (after going irrevocable).  The
test case in bug 46654 is an atomic transaction.


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

* [Bug c++/54893] unable to access volatile variable within relaxed transaction
  2012-10-10 17:46 [Bug c++/54893] New: unable to access volatile variable within relaxed transaction spear at cse dot lehigh.edu
                   ` (2 preceding siblings ...)
  2012-10-11 19:54 ` torvald at gcc dot gnu.org
@ 2012-10-11 20:29 ` aldyh at gcc dot gnu.org
  2012-10-17 21:18 ` [Bug middle-end/54893] " aldyh at gcc dot gnu.org
  2012-10-17 21:19 ` aldyh at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: aldyh at gcc dot gnu.org @ 2012-10-11 20:29 UTC (permalink / raw)
  To: gcc-bugs


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

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-10-11
         AssignedTo|unassigned at gcc dot       |aldyh at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #4 from Aldy Hernandez <aldyh at gcc dot gnu.org> 2012-10-11 20:29:13 UTC ---
Created attachment 28427
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28427
untested patch

Testing...


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

* [Bug middle-end/54893] unable to access volatile variable within relaxed transaction
  2012-10-10 17:46 [Bug c++/54893] New: unable to access volatile variable within relaxed transaction spear at cse dot lehigh.edu
                   ` (3 preceding siblings ...)
  2012-10-11 20:29 ` aldyh at gcc dot gnu.org
@ 2012-10-17 21:18 ` aldyh at gcc dot gnu.org
  2012-10-17 21:19 ` aldyh at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: aldyh at gcc dot gnu.org @ 2012-10-17 21:18 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Aldy Hernandez <aldyh at gcc dot gnu.org> 2012-10-17 21:18:21 UTC ---
Author: aldyh
Date: Wed Oct 17 21:18:16 2012
New Revision: 192549

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192549
Log:
    PR middle-end/54893
        * trans-mem.c (diagnose_tm_1_op): Allow volatiles inside relaxed
        transactions.

Added:
    trunk/gcc/testsuite/c-c++-common/tm/pr54893.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/trans-mem.c


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

* [Bug middle-end/54893] unable to access volatile variable within relaxed transaction
  2012-10-10 17:46 [Bug c++/54893] New: unable to access volatile variable within relaxed transaction spear at cse dot lehigh.edu
                   ` (4 preceding siblings ...)
  2012-10-17 21:18 ` [Bug middle-end/54893] " aldyh at gcc dot gnu.org
@ 2012-10-17 21:19 ` aldyh at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: aldyh at gcc dot gnu.org @ 2012-10-17 21:19 UTC (permalink / raw)
  To: gcc-bugs


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

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #6 from Aldy Hernandez <aldyh at gcc dot gnu.org> 2012-10-17 21:19:29 UTC ---
fixed on mainline


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

end of thread, other threads:[~2012-10-17 21:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-10 17:46 [Bug c++/54893] New: unable to access volatile variable within relaxed transaction spear at cse dot lehigh.edu
2012-10-11 10:41 ` [Bug c++/54893] " aldyh at gcc dot gnu.org
2012-10-11 13:21 ` spear at cse dot lehigh.edu
2012-10-11 19:54 ` torvald at gcc dot gnu.org
2012-10-11 20:29 ` aldyh at gcc dot gnu.org
2012-10-17 21:18 ` [Bug middle-end/54893] " aldyh at gcc dot gnu.org
2012-10-17 21:19 ` aldyh 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).