Skip to content

Commit 8e7522b

Browse files
committed
[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.
1 parent 3d0f885 commit 8e7522b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4634,11 +4634,10 @@ namespace {
46344634

46354635
// Perform a binary search to find the local redeclarations for this
46364636
// declaration (if any).
4637-
const ObjCCategoriesInfo Compare = { LocalID, 0 };
4638-
const ObjCCategoriesInfo *Result
4639-
= std::lower_bound(M.ObjCCategoriesMap,
4640-
M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap,
4641-
Compare);
4637+
const ObjCCategoriesInfo Compare = {LocalID, 0};
4638+
const ObjCCategoriesInfo *Result = std::lower_bound(
4639+
M.ObjCCategoriesMap,
4640+
M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, Compare);
46424641
if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap ||
46434642
LocalID != Result->getDefinitionID()) {
46444643
// We didn't find anything. If the class definition is in this module

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4978,6 +4978,9 @@ void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) {
49784978
}
49794979

49804980
void ASTWriter::WriteObjCCategories() {
4981+
if (ObjCClassesWithCategories.empty())
4982+
return;
4983+
49814984
SmallVector<ObjCCategoriesInfo, 2> CategoriesMap;
49824985
RecordData Categories;
49834986

0 commit comments

Comments
 (0)