r224902 - Sema: Permit an atomic type to be initialized by the same atomic type

Richard Smith richard at metafoo.co.uk
Tue Jan 13 17:22:33 PST 2015


On Sun, Dec 28, 2014 at 1:47 PM, David Majnemer <david.majnemer at gmail.com>
wrote:

> Author: majnemer
> Date: Sun Dec 28 15:47:31 2014
> New Revision: 224902
>
> URL: http://llvm.org/viewvc/llvm-project?rev=224902&view=rev
> Log:
> Sema: Permit an atomic type to be initialized by the same atomic type
>
> We forgot a conversion step when initializing an atomic type with an
> rvalue of the same type.
>
> This fixes PR22043.
>
> Modified:
>     cfe/trunk/lib/Sema/SemaExprCXX.cpp
>     cfe/trunk/test/CodeGenCXX/atomicinit.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=224902&r1=224901&r2=224902&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Dec 28 15:47:31 2014
> @@ -2759,7 +2759,11 @@ Sema::PerformImplicitConversion(Expr *Fr
>    // Perform the first implicit conversion.
>    switch (SCS.First) {
>    case ICK_Identity:
> -    // Nothing to do.
> +    if (const AtomicType *FromAtomic = FromType->getAs<AtomicType>()) {
> +      FromType = FromAtomic->getValueType().getUnqualifiedType();
> +      From = ImplicitCastExpr::Create(Context, FromType,
> CK_AtomicToNonAtomic,
> +                                      From, /*BasePath=*/nullptr,
> VK_RValue);
> +    }
>      break;
>
>    case ICK_Lvalue_To_Rvalue: {
>
> Modified: cfe/trunk/test/CodeGenCXX/atomicinit.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/atomicinit.cpp?rev=224902&r1=224901&r2=224902&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/atomicinit.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/atomicinit.cpp Sun Dec 28 15:47:31 2014
> @@ -1,5 +1,9 @@
>  // RUN: %clang_cc1 %s -emit-llvm -O1 -o - -triple=i686-apple-darwin9
> -std=c++11 | FileCheck %s
>
> +// CHECK-DAG: @PR22043 = global i32 0, align 4
> +typedef _Atomic(int) AtomicInt;
> +AtomicInt PR22043 = AtomicInt();
>

As far as I can tell from the C standard, it should not be possible for an
rvalue to have an atomic-qualified type. That being the case, I think the
right fix here is for the type of 'AtomicInt()' to be merely 'int', just as
the type of 'ConstInt()' is 'int' in

  typedef const int ConstInt;
  ConstInt blah = ConstInt();

+
>  // CHECK-DAG: @_ZN7PR180978constant1aE = global { i16, i8 } { i16 1, i8 6
> }, align 4
>  // CHECK-DAG: @_ZN7PR180978constant1bE = global { i16, i8 } { i16 2, i8 6
> }, align 4
>  // CHECK-DAG: @_ZN7PR180978constant1cE = global { i16, i8 } { i16 3, i8 6
> }, align 4
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150113/96fae09e/attachment.html>


More information about the cfe-commits mailing list