[clang] 8b529e3 - [ObjC] Fix AST serialization for pseudo-strong parameters

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 8 08:55:17 PDT 2020


Author: David Goldman
Date: 2020-06-08T11:54:01-04:00
New Revision: 8b529e311a9052ee7a0676a1b517728efa44a3ba

URL: https://github.com/llvm/llvm-project/commit/8b529e311a9052ee7a0676a1b517728efa44a3ba
DIFF: https://github.com/llvm/llvm-project/commit/8b529e311a9052ee7a0676a1b517728efa44a3ba.diff

LOG: [ObjC] Fix AST serialization for pseudo-strong parameters

This bit was assumed to be always false for ParmVarDecls, but attribute
objc_externally_retained now can produce it.

Differential revision: https://reviews.llvm.org/D74417

Added: 
    clang/test/PCH/externally-retained.m

Modified: 
    clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 8c5be6cacac0..a28a21b29339 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1100,8 +1100,6 @@ void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
     Record.AddStmt(D->getUninstantiatedDefaultArg());
   Code = serialization::DECL_PARM_VAR;
 
-  assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
-
   // If the assumptions about the DECL_PARM_VAR abbrev are true, use it.  Here
   // we dynamically check for the properties that we optimize for, but don't
   // know are true of all PARM_VAR_DECLs.
@@ -2121,7 +2119,7 @@ void ASTWriter::WriteDeclAbbrevs() {
   Abv->Add(BitCodeAbbrevOp(0));                       // SClass
   Abv->Add(BitCodeAbbrevOp(0));                       // TSCSpec
   Abv->Add(BitCodeAbbrevOp(0));                       // InitStyle
-  Abv->Add(BitCodeAbbrevOp(0));                       // ARCPseudoStrong
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
   Abv->Add(BitCodeAbbrevOp(0));                       // Linkage
   Abv->Add(BitCodeAbbrevOp(0));                       // HasInit
   Abv->Add(BitCodeAbbrevOp(0));                   // HasMemberSpecializationInfo

diff  --git a/clang/test/PCH/externally-retained.m b/clang/test/PCH/externally-retained.m
new file mode 100644
index 000000000000..6a1debf8f467
--- /dev/null
+++ b/clang/test/PCH/externally-retained.m
@@ -0,0 +1,30 @@
+// Test for assertion failure due to objc_externally_retained on a function.
+
+// Without PCH
+// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-arc -include %s %s
+
+// With PCH
+// RUN: %clang_cc1 %s -emit-pch -fobjc-arc -o %t
+// RUN: %clang_cc1 -emit-llvm-only -verify %s -fobjc-arc -include-pch %t -debug-info-kind=limited
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+//===----------------------------------------------------------------------===//
+// Header
+
+__attribute__((objc_externally_retained)) void doSomething(id someObject);
+
+id sharedObject = 0;
+
+//===----------------------------------------------------------------------===//
+#else
+//===----------------------------------------------------------------------===//
+
+void callDoSomething() {
+  doSomething(sharedObject);
+}
+
+//===----------------------------------------------------------------------===//
+#endif


        


More information about the cfe-commits mailing list