[cfe-commits] [PATCH] Add _Atomic specifier for atomic types

Jeffrey Yasskin jyasskin at google.com
Tue Oct 4 19:45:39 PDT 2011


On Tue, Oct 4, 2011 at 6:12 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Tue, Oct 4, 2011 at 12:23 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>>> Also, C1x says that the _Atomic specifier can't be applied to "an
>>> array type, a function type, an atomic type, or a qualified type.",
>>> while the _Atomic qualifier can't be applied to "an array type or a
>>> function type." Are those covered by the trivially-copyable
>>> restriction? This probably deserves a comment.
>>
>> Function types and atomic types are not trivially-copyable; arrays and
>> qualified types are.  I'll make the necessary adjustments (although
>> I'm not entirely comfortable banning arrays in C when they are legal
>> in C++; I might mark it an extension for the moment).
>
> I subsequently realized that despite what the C++ standard says, it
> would actually be impossible to instantiate std::atomic<int[10]>, and
> std::atomic<volatile int> wouldn't make any sense even though it could
> in theory be instantiated.

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#496 says
atomic<const/volatile> shouldn't be allowed. I don't seen an issue for
arrays in C++, but Lawrence Crowl agreed that they probably shouldn't
be allowed.

>>>> +    return QualType();
>>>> +  }
>>>> +
>>>> +  // FIXME: Do we need any handling for ARC here?
>>>> +
>>>> +  // Build the pointer type.
>>>> +  return Context.getAtomicType(T);
>>>> +}
>>>> Index: lib/Sema/SemaExpr.cpp
>>>> ===================================================================
>>>> --- lib/Sema/SemaExpr.cpp     (revision 141016)
>>>> +++ lib/Sema/SemaExpr.cpp     (working copy)
>>>> @@ -342,6 +342,10 @@
>>>>    QualType T = E->getType();
>>>>    assert(!T.isNull() && "r-value conversion on typeless expression?");
>>>>
>>>> +  // We can't do lvalue-to-rvalue on atomics yet.
>>>
>>> According to the C1x draft I have, it's not "yet". The only way to get
>>> an rvalue from an atomic lvalue is to call atomic_load().
>>
>> Okay, cool. :)
>
> Hmm... I just looked, and 6.3.2.1p2 seems to say that you can get an
> rvalue from an atomic lvalue.

Whoops. I must have stopped early in my search for 'atomic'. All sorts
of uses of _Atomic variables are allowed. Notable references are
6.2.6.1p9, 6.5.2.4, and 6.5.16.2. The draft Lawrence was looking at
had a special warning about implementing these for floating types,
which isn't provided by C++, but I can't see that in my copy from Dec
2010. Sorry for the misdirection.

>>>> Index: lib/AST/ItaniumMangle.cpp
>>>> ===================================================================
>>>> --- lib/AST/ItaniumMangle.cpp (revision 141016)
>>>> +++ lib/AST/ItaniumMangle.cpp (working copy)
>>>> @@ -2111,6 +2112,11 @@
>>>>      mangleType(D);
>>>>  }
>>>>
>>>> +void CXXNameMangler::mangleType(const AtomicType *T) {
>>>
>>> The other mangleType definitions have a grammar fragment in a comment.
>>>  It looks like the official ABI doesn't mention atomics yet, so can
>>> you describe where you got the v17 prefix?
>>
>> It's a vendor-specific prefix, since there isn't any standardized
>> mangling at the moment.  I'll put in a comment to that effect.
>> (Granted, it usually won't matter unless someone tries to use _Atomic
>> in C++ directly.)
>
> And... I used the wrong kind of prefix.  Now fixed.
>
> New version attached.

I'll look it over. All of your email responses have seemed correct, so
I don't expect to find anything.




More information about the cfe-commits mailing list