r327464 - Check that a field is not annotated with attribute "unavailable" before

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 13 16:37:51 PDT 2018


Author: ahatanak
Date: Tue Mar 13 16:37:51 2018
New Revision: 327464

URL: http://llvm.org/viewvc/llvm-project?rev=327464&view=rev
Log:
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

Added:
    cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=327464&r1=327463&r2=327464&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Mar 13 16:37:51 2018
@@ -15442,7 +15442,7 @@ void Sema::ActOnFields(Scope *S, SourceL
       }
     }
 
-    if (Record && !getLangOpts().CPlusPlus) {
+    if (Record && !getLangOpts().CPlusPlus && !FD->hasAttr<UnavailableAttr>()) {
       QualType FT = FD->getType();
       if (FT.isNonTrivialToPrimitiveDefaultInitialize())
         Record->setNonTrivialToPrimitiveDefaultInitialize(true);

Added: cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h?rev=327464&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h (added)
+++ cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h Tue Mar 13 16:37:51 2018
@@ -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

Modified: cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m?rev=327464&r1=327463&r2=327464&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m (original)
+++ cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m Tue Mar 13 16:37:51 2018
@@ -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(Bit
   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 */




More information about the cfe-commits mailing list