summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-06-29 20:13:23 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-06-29 20:13:23 +0000
commit5682efd28c745d1eeef33c376cdcf5fca670d60e (patch)
tree8c4334cbf84aafab5d4aaab0d1a57a5fba452705
parent2e59d4fffeeb0aeaf2acfd9f79acec21690a7fee (diff)
downloadbcm5719-llvm-5682efd28c745d1eeef33c376cdcf5fca670d60e.tar.gz
bcm5719-llvm-5682efd28c745d1eeef33c376cdcf5fca670d60e.zip
[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. llvm-svn: 240989
-rw-r--r--clang/lib/CodeGen/CodeGenTypes.cpp12
-rw-r--r--clang/test/CodeGen/c11atomics.c20
2 files changed, 25 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp
index e0f926cabd7..a4a8654eb36 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -154,14 +154,16 @@ isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT,
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
diff --git a/clang/test/CodeGen/c11atomics.c b/clang/test/CodeGen/c11atomics.c
index a35eef94264..d1e4478d7ec 100644
--- a/clang/test/CodeGen/c11atomics.c
+++ b/clang/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;
OpenPOWER on IntegriCloud