From: David Majnemer Date: Mon, 29 Jun 2015 20:13:23 +0000 (+0000) Subject: [CodeGen] Remove atomic sugar from record types in isSafeToConvert X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=029eb4a6d97d4e3e21b4a7d42c403857f1724572;p=clang [CodeGen] Remove atomic sugar from record types in isSafeToConvert We failed to see that we should have deferred the creation of a type which references a type currently under construction because of atomic sugar. This fixes PR23985. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240989 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index e0f926cabd..a4a8654eb3 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -154,14 +154,16 @@ isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT, static bool isSafeToConvert(QualType T, CodeGenTypes &CGT, llvm::SmallPtrSet &AlreadyChecked) { - T = T.getCanonicalType(); - + // Strip off atomic type sugar. + if (const auto *AT = T->getAs()) + T = AT->getValueType(); + // If this is a record, check it. - if (const RecordType *RT = dyn_cast(T)) + if (const auto *RT = T->getAs()) return isSafeToConvert(RT->getDecl(), CGT, AlreadyChecked); - + // If this is an array, check the elements, which are embedded inline. - if (const ArrayType *AT = dyn_cast(T)) + if (const auto *AT = CGT.getContext().getAsArrayType(T)) return isSafeToConvert(AT->getElementType(), CGT, AlreadyChecked); // Otherwise, there is no concern about transforming this. We only care about diff --git a/test/CodeGen/c11atomics.c b/test/CodeGen/c11atomics.c index a35eef9426..d1e4478d7e 100644 --- a/test/CodeGen/c11atomics.c +++ b/test/CodeGen/c11atomics.c @@ -12,8 +12,24 @@ // they're sufficiently rare that it's not worth making sure that the semantics // are correct. -// CHECK: @testStructGlobal = global {{.*}} { i16 1, i16 2, i16 3, i16 4 } -// CHECK: @testPromotedStructGlobal = global {{.*}} { %{{.*}} { i16 1, i16 2, i16 3 }, [2 x i8] zeroinitializer } +struct elem; + +struct ptr { + struct elem *ptr; +}; +// CHECK-DAG: %struct.ptr = type { %struct.elem* } + +struct elem { + _Atomic(struct ptr) link; +}; +// CHECK-DAG: %struct.elem = type { %struct.ptr } + +struct ptr object; +// CHECK-DAG: @object = common global %struct.ptr zeroinitializer + +// CHECK-DAG: @testStructGlobal = global {{.*}} { i16 1, i16 2, i16 3, i16 4 } +// CHECK-DAG: @testPromotedStructGlobal = global {{.*}} { %{{.*}} { i16 1, i16 2, i16 3 }, [2 x i8] zeroinitializer } + typedef int __attribute__((vector_size(16))) vector;