r240989 - [CodeGen] Remove atomic sugar from record types in isSafeToConvert
David Majnemer
david.majnemer at gmail.com
Mon Jun 29 13:13:23 PDT 2015
Author: majnemer
Date: Mon Jun 29 15:13:23 2015
New Revision: 240989
URL: http://llvm.org/viewvc/llvm-project?rev=240989&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/test/CodeGen/c11atomics.c
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=240989&r1=240988&r2=240989&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Mon Jun 29 15:13:23 2015
@@ -154,14 +154,16 @@ isSafeToConvert(const RecordDecl *RD, Co
static bool
isSafeToConvert(QualType T, CodeGenTypes &CGT,
llvm::SmallPtrSet<const RecordDecl*, 16> &AlreadyChecked) {
- T = T.getCanonicalType();
-
+ // Strip off atomic type sugar.
+ if (const auto *AT = T->getAs<AtomicType>())
+ T = AT->getValueType();
+
// If this is a record, check it.
- if (const RecordType *RT = dyn_cast<RecordType>(T))
+ if (const auto *RT = T->getAs<RecordType>())
return isSafeToConvert(RT->getDecl(), CGT, AlreadyChecked);
-
+
// If this is an array, check the elements, which are embedded inline.
- if (const ArrayType *AT = dyn_cast<ArrayType>(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
Modified: cfe/trunk/test/CodeGen/c11atomics.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/c11atomics.c?rev=240989&r1=240988&r2=240989&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/c11atomics.c (original)
+++ cfe/trunk/test/CodeGen/c11atomics.c Mon Jun 29 15:13:23 2015
@@ -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;
More information about the cfe-commits
mailing list