From ceb66521ba155ad250e54f8142a2034af7ab3210 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Tue, 13 Mar 2018 23:37:51 +0000 Subject: [PATCH] Check that a field is not annotated with attribute "unavailable" before setting the NonTrivialToPrimitive* flags of a record. Union fields that have non-trivial Objective-C ownership qualifications are normally not legal, but if the union is declared in a system header, the fields are annotated with attribute "unavailable". rdar://problem/38431072 llvm-svn: 327464 --- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/test/CodeGenObjC/Inputs/strong_in_union.h | 10 ++++++++++ clang/test/CodeGenObjC/strong-in-c-struct.m | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 clang/test/CodeGenObjC/Inputs/strong_in_union.h diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 577724b..db598b0 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -15442,7 +15442,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, } } - if (Record && !getLangOpts().CPlusPlus) { + if (Record && !getLangOpts().CPlusPlus && !FD->hasAttr()) { QualType FT = FD->getType(); if (FT.isNonTrivialToPrimitiveDefaultInitialize()) Record->setNonTrivialToPrimitiveDefaultInitialize(true); diff --git a/clang/test/CodeGenObjC/Inputs/strong_in_union.h b/clang/test/CodeGenObjC/Inputs/strong_in_union.h new file mode 100644 index 0000000..abe4549 --- /dev/null +++ b/clang/test/CodeGenObjC/Inputs/strong_in_union.h @@ -0,0 +1,10 @@ +#ifndef STRONG_IN_UNION_H +#define STRONG_IN_UNION_H +#pragma clang system_header + +typedef union { + id f0; + int *f1; +} U; + +#endif // STRONG_IN_UNION_H diff --git a/clang/test/CodeGenObjC/strong-in-c-struct.m b/clang/test/CodeGenObjC/strong-in-c-struct.m index 11291f7..6310943 100644 --- a/clang/test/CodeGenObjC/strong-in-c-struct.m +++ b/clang/test/CodeGenObjC/strong-in-c-struct.m @@ -1,10 +1,11 @@ -// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-llvm -o - -DUSESTRUCT %s | FileCheck %s +// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-llvm -o - -DUSESTRUCT -I %S/Inputs %s | FileCheck %s -// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-pch -o %t %s -// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -include-pch %t -emit-llvm -o - -DUSESTRUCT %s | FileCheck %s +// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-pch -I %S/Inputs -o %t %s +// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -include-pch %t -emit-llvm -o - -DUSESTRUCT -I %S/Inputs %s | FileCheck %s #ifndef HEADER #define HEADER +#include "strong_in_union.h" typedef void (^BlockTy)(void); @@ -531,4 +532,12 @@ void test_copy_constructor_Bitfield1(Bitfield1 *a) { Bitfield1 t = *a; } +// CHECK: define void @test_strong_in_union() +// CHECK: alloca %{{.*}} +// CHECK-NEXT: ret void + +void test_strong_in_union() { + U t; +} + #endif /* USESTRUCT */ -- 2.7.4