https://github.com/davemgreen updated https://github.com/llvm/llvm-project/pull/141841
>From 2ed4ce494dbabd94f5b60ae13ee1631fe40a0a4e Mon Sep 17 00:00:00 2001 From: David Green <david.gr...@arm.com> Date: Wed, 28 May 2025 20:39:53 +0100 Subject: [PATCH 1/2] [ASTWriter] Do not write ObjCCategories if empty. This is a fix for a completely unrelated patch, that started to fail the explicit-build.cpp test because the size of the b.pcm and b-not-a.pcm files became the same. The alignment added by empty ObjCCategory blobs being written to the file causes them to be the same size, and the error 'module file has a different size than expected' will not be emitted. This prevents that issue by not saving the ObjCCategories if it is empty. The change in clang/lib/Serialization/ASTReaderDecl.cpp is just a format, but shows that the only use of ObjCCategoriesMap loaded from the file will be OK with null (never loaded) data. --- clang/lib/Serialization/ASTReaderDecl.cpp | 9 ++++----- clang/lib/Serialization/ASTWriter.cpp | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index fb31613ded655..8dafefb9696bf 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -4631,11 +4631,10 @@ namespace { // Perform a binary search to find the local redeclarations for this // declaration (if any). - const ObjCCategoriesInfo Compare = { LocalID, 0 }; - const ObjCCategoriesInfo *Result - = std::lower_bound(M.ObjCCategoriesMap, - M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, - Compare); + const ObjCCategoriesInfo Compare = {LocalID, 0}; + const ObjCCategoriesInfo *Result = std::lower_bound( + M.ObjCCategoriesMap, + M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, Compare); if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap || LocalID != Result->getDefinitionID()) { // We didn't find anything. If the class definition is in this module diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 46bfdb2a92d1d..ab1b5b333e06a 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -4972,6 +4972,9 @@ void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) { } void ASTWriter::WriteObjCCategories() { + if (ObjCClassesWithCategories.empty()) + return; + SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; RecordData Categories; >From 696c8b3133e8e690b6900c4c8b1ec4e1a4d3309a Mon Sep 17 00:00:00 2001 From: David Green <david.gr...@arm.com> Date: Mon, 2 Jun 2025 10:24:38 +0100 Subject: [PATCH 2/2] Add a test --- clang/test/Modules/objc-categories.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 clang/test/Modules/objc-categories.cpp diff --git a/clang/test/Modules/objc-categories.cpp b/clang/test/Modules/objc-categories.cpp new file mode 100644 index 0000000000000..2c004c4fd19c6 --- /dev/null +++ b/clang/test/Modules/objc-categories.cpp @@ -0,0 +1,14 @@ +// RUN: rm -rf %t.pcm + +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -x c++ -std=c++11 -emit-module -fmodules -fmodule-name=cxx_library %S/Inputs/module.modulemap -o %t.pcm +// RUN: llvm-bcanalyzer %t.pcm | FileCheck %s --check-prefix=CXX_LIBRARY +// CXX_LIBRARY: AST_BLOCK +// CXX_LIBRARY-NOT: OBJC_CATEGORIES +// CXX_LIBRARY-NOT: OBJC_CATEGORIES_MAP + +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -x objective-c -emit-module -fmodules -fmodule-name=category_top %S/Inputs/module.modulemap -o %t.pcm +// RUN: llvm-bcanalyzer %t.pcm | FileCheck %s --check-prefix=CATEGORY_TOP +// CATEGORY_TOP: AST_BLOCK +// CATEGORY_TOP: OBJC_CATEGORIES +// CATEGORY_TOP: OBJC_CATEGORIES_MAP + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits