diff options
author | David Green <david.green@arm.com> | 2025-06-02 16:42:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-02 16:42:43 +0100 |
commit | 847e403ed7197988d4c8b95800b7e9b178d058a7 (patch) | |
tree | b93204025403d1d569a5590038d5ecdac103348b /clang/lib/Serialization | |
parent | 01d4b16406f53b0ccb80fa80aa15218f59fb7d7c (diff) | |
download | llvm-847e403ed7197988d4c8b95800b7e9b178d058a7.zip llvm-847e403ed7197988d4c8b95800b7e9b178d058a7.tar.gz llvm-847e403ed7197988d4c8b95800b7e9b178d058a7.tar.bz2 |
[ASTWriter] Do not write ObjCCategories if empty. (#141841)
This is a fix for a completely unrelated patch, that started to cause
failures in 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 become the
same size, and the error 'module file has a different size than
expected' will not be emitted as the pcms only track module size, not
content, for whether they are valid.
This prevents that issue by not saving the ObjCCategories if it is
empty. The change in clang/lib/Serialization/ASTReaderDecl.cpp is just
formatting, but shows that the only use of ObjCCategoriesMap loaded from
the file will be OK with null (never loaded) data. It is a bit of a weird
fix, but should help decrease the size of the modules for objects that
are not used.
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 9 | ||||
-rw-r--r-- | 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 fb31613..8dafefb 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 46bfdb2..ab1b5b3 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; |