https://github.com/dzbarsky updated https://github.com/llvm/llvm-project/pull/202843
>From 85ffcd83da47e9b234f0c55a0b01a2aff2acca0d Mon Sep 17 00:00:00 2001 From: David Zbarsky <[email protected]> Date: Tue, 9 Jun 2026 23:50:19 -0400 Subject: [PATCH 1/4] [clang][Serialization] Outline LangOptions mismatch diagnostics Move language-option mismatch diagnostic construction into two noinline helpers. Generated comparisons remain direct and in their original order, so successful imports add no indirect calls and the serialized format is unchanged. ASTReader.cpp.o shrinks by 62,712 bytes, including 36,284 bytes of __text, and has 1,347 fewer relocations. Controlled links shrink clang by 35,264 bytes and clangd by 29,216 bytes; stripped sizes fall by 16,752 and 16,664 bytes, and linked fixups are unchanged. PCH, PCM, and BMI outputs are byte-identical and cross-import successfully. Mismatch diagnostics are byte-identical for boolean options, OpenMP, module features, Objective-C runtime, block command names, and AddressSanitizer. Focused module/PCH tests pass, and batched PCH and module imports show no significant performance change. --- clang/lib/Serialization/ASTReader.cpp | 43 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index f8a6a38bb9b5c..80feea0a0c795 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -276,6 +276,19 @@ void ChainedASTReaderListener::readModuleFileExtension( ASTReaderListener::~ASTReaderListener() = default; +static LLVM_ATTRIBUTE_NOINLINE void diagnoseLanguageOptionFlagMismatch( + DiagnosticsEngine &Diags, StringRef Description, bool SerializedValue, + bool CurrentValue, StringRef ModuleFilename) { + Diags.Report(diag::err_ast_file_langopt_mismatch) + << Description << SerializedValue << CurrentValue << ModuleFilename; +} + +static LLVM_ATTRIBUTE_NOINLINE void diagnoseLanguageOptionValueMismatch( + DiagnosticsEngine &Diags, StringRef Description, StringRef ModuleFilename) { + Diags.Report(diag::err_ast_file_langopt_value_mismatch) + << Description << ModuleFilename; +} + /// Compare the given set of language options against an existing set of /// language options. /// @@ -300,12 +313,12 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, if (ExistingLangOpts.Name != LangOpts.Name) { \ if (Diags) { \ if (Bits == 1) \ - Diags->Report(diag::err_ast_file_langopt_mismatch) \ - << Description << LangOpts.Name << ExistingLangOpts.Name \ - << ModuleFilename; \ + diagnoseLanguageOptionFlagMismatch( \ + *Diags, Description, LangOpts.Name, ExistingLangOpts.Name, \ + ModuleFilename); \ else \ - Diags->Report(diag::err_ast_file_langopt_value_mismatch) \ - << Description << ModuleFilename; \ + diagnoseLanguageOptionValueMismatch(*Diags, Description, \ + ModuleFilename); \ } \ return true; \ } \ @@ -319,8 +332,8 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, !AllowCompatibleDifferences)) { \ if (ExistingLangOpts.Name != LangOpts.Name) { \ if (Diags) \ - Diags->Report(diag::err_ast_file_langopt_value_mismatch) \ - << Description << ModuleFilename; \ + diagnoseLanguageOptionValueMismatch(*Diags, Description, \ + ModuleFilename); \ return true; \ } \ } \ @@ -333,8 +346,8 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, !AllowCompatibleDifferences)) { \ if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ if (Diags) \ - Diags->Report(diag::err_ast_file_langopt_value_mismatch) \ - << Description << ModuleFilename; \ + diagnoseLanguageOptionValueMismatch(*Diags, Description, \ + ModuleFilename); \ return true; \ } \ } \ @@ -344,23 +357,23 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) { if (Diags) - Diags->Report(diag::err_ast_file_langopt_value_mismatch) - << "module features" << ModuleFilename; + diagnoseLanguageOptionValueMismatch(*Diags, "module features", + ModuleFilename); return true; } if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { if (Diags) - Diags->Report(diag::err_ast_file_langopt_value_mismatch) - << "target Objective-C runtime" << ModuleFilename; + diagnoseLanguageOptionValueMismatch(*Diags, "target Objective-C runtime", + ModuleFilename); return true; } if (ExistingLangOpts.CommentOpts.BlockCommandNames != LangOpts.CommentOpts.BlockCommandNames) { if (Diags) - Diags->Report(diag::err_ast_file_langopt_value_mismatch) - << "block command names" << ModuleFilename; + diagnoseLanguageOptionValueMismatch(*Diags, "block command names", + ModuleFilename); return true; } >From 2f3711cd83bad9227cf246255ce6a17d6ccb27a4 Mon Sep 17 00:00:00 2001 From: David Zbarsky <[email protected]> Date: Tue, 7 Jul 2026 14:44:05 -0400 Subject: [PATCH 2/4] [clang][Serialization] Move LangOptions diagnostic guards into helpers Make diagnoseLanguageOptionFlagMismatch and diagnoseLanguageOptionValueMismatch accept DiagnosticsEngine pointers and handle null pointers. Remove the repeated DiagnosticsEngine checks from checkLanguageOptions. --- clang/lib/Serialization/ASTReader.cpp | 53 +++++++++++++-------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 80feea0a0c795..9e9dcc57976fa 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -277,15 +277,19 @@ void ChainedASTReaderListener::readModuleFileExtension( ASTReaderListener::~ASTReaderListener() = default; static LLVM_ATTRIBUTE_NOINLINE void diagnoseLanguageOptionFlagMismatch( - DiagnosticsEngine &Diags, StringRef Description, bool SerializedValue, + DiagnosticsEngine *Diags, StringRef Description, bool SerializedValue, bool CurrentValue, StringRef ModuleFilename) { - Diags.Report(diag::err_ast_file_langopt_mismatch) + if (!Diags) + return; + Diags->Report(diag::err_ast_file_langopt_mismatch) << Description << SerializedValue << CurrentValue << ModuleFilename; } static LLVM_ATTRIBUTE_NOINLINE void diagnoseLanguageOptionValueMismatch( - DiagnosticsEngine &Diags, StringRef Description, StringRef ModuleFilename) { - Diags.Report(diag::err_ast_file_langopt_value_mismatch) + DiagnosticsEngine *Diags, StringRef Description, StringRef ModuleFilename) { + if (!Diags) + return; + Diags->Report(diag::err_ast_file_langopt_value_mismatch) << Description << ModuleFilename; } @@ -311,15 +315,13 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, (CK::Compatibility == CK::Compatible && \ !AllowCompatibleDifferences)) { \ if (ExistingLangOpts.Name != LangOpts.Name) { \ - if (Diags) { \ - if (Bits == 1) \ - diagnoseLanguageOptionFlagMismatch( \ - *Diags, Description, LangOpts.Name, ExistingLangOpts.Name, \ - ModuleFilename); \ - else \ - diagnoseLanguageOptionValueMismatch(*Diags, Description, \ - ModuleFilename); \ - } \ + if (Bits == 1) \ + diagnoseLanguageOptionFlagMismatch( \ + Diags, Description, LangOpts.Name, ExistingLangOpts.Name, \ + ModuleFilename); \ + else \ + diagnoseLanguageOptionValueMismatch(Diags, Description, \ + ModuleFilename); \ return true; \ } \ } \ @@ -331,9 +333,8 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, (CK::Compatibility == CK::Compatible && \ !AllowCompatibleDifferences)) { \ if (ExistingLangOpts.Name != LangOpts.Name) { \ - if (Diags) \ - diagnoseLanguageOptionValueMismatch(*Diags, Description, \ - ModuleFilename); \ + diagnoseLanguageOptionValueMismatch(Diags, Description, \ + ModuleFilename); \ return true; \ } \ } \ @@ -345,9 +346,8 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, (CK::Compatibility == CK::Compatible && \ !AllowCompatibleDifferences)) { \ if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ - if (Diags) \ - diagnoseLanguageOptionValueMismatch(*Diags, Description, \ - ModuleFilename); \ + diagnoseLanguageOptionValueMismatch(Diags, Description, \ + ModuleFilename); \ return true; \ } \ } \ @@ -356,24 +356,21 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, #include "clang/Basic/LangOptions.def" if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) { - if (Diags) - diagnoseLanguageOptionValueMismatch(*Diags, "module features", - ModuleFilename); + diagnoseLanguageOptionValueMismatch(Diags, "module features", + ModuleFilename); return true; } if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { - if (Diags) - diagnoseLanguageOptionValueMismatch(*Diags, "target Objective-C runtime", - ModuleFilename); + diagnoseLanguageOptionValueMismatch(Diags, "target Objective-C runtime", + ModuleFilename); return true; } if (ExistingLangOpts.CommentOpts.BlockCommandNames != LangOpts.CommentOpts.BlockCommandNames) { - if (Diags) - diagnoseLanguageOptionValueMismatch(*Diags, "block command names", - ModuleFilename); + diagnoseLanguageOptionValueMismatch(Diags, "block command names", + ModuleFilename); return true; } >From 1a40754355c7980d8d93e594054eacb223a3ae89 Mon Sep 17 00:00:00 2001 From: David Zbarsky <[email protected]> Date: Tue, 7 Jul 2026 20:43:52 -0400 Subject: [PATCH 3/4] [clang][Serialization] Return LangOptions diagnostic helper results Return true when no DiagnosticsEngine is available and otherwise return the DiagnosticBuilder boolean conversion. Return the helper result directly from each checkLanguageOptions mismatch branch. --- clang/lib/Serialization/ASTReader.cpp | 49 ++++++++++++--------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 9e9dcc57976fa..740b8c6b0ade9 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -276,21 +276,21 @@ void ChainedASTReaderListener::readModuleFileExtension( ASTReaderListener::~ASTReaderListener() = default; -static LLVM_ATTRIBUTE_NOINLINE void diagnoseLanguageOptionFlagMismatch( +static LLVM_ATTRIBUTE_NOINLINE bool diagnoseLanguageOptionFlagMismatch( DiagnosticsEngine *Diags, StringRef Description, bool SerializedValue, bool CurrentValue, StringRef ModuleFilename) { if (!Diags) - return; - Diags->Report(diag::err_ast_file_langopt_mismatch) - << Description << SerializedValue << CurrentValue << ModuleFilename; + return true; + return Diags->Report(diag::err_ast_file_langopt_mismatch) + << Description << SerializedValue << CurrentValue << ModuleFilename; } -static LLVM_ATTRIBUTE_NOINLINE void diagnoseLanguageOptionValueMismatch( +static LLVM_ATTRIBUTE_NOINLINE bool diagnoseLanguageOptionValueMismatch( DiagnosticsEngine *Diags, StringRef Description, StringRef ModuleFilename) { if (!Diags) - return; - Diags->Report(diag::err_ast_file_langopt_value_mismatch) - << Description << ModuleFilename; + return true; + return Diags->Report(diag::err_ast_file_langopt_value_mismatch) + << Description << ModuleFilename; } /// Compare the given set of language options against an existing set of @@ -316,13 +316,11 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, !AllowCompatibleDifferences)) { \ if (ExistingLangOpts.Name != LangOpts.Name) { \ if (Bits == 1) \ - diagnoseLanguageOptionFlagMismatch( \ + return diagnoseLanguageOptionFlagMismatch( \ Diags, Description, LangOpts.Name, ExistingLangOpts.Name, \ ModuleFilename); \ - else \ - diagnoseLanguageOptionValueMismatch(Diags, Description, \ - ModuleFilename); \ - return true; \ + return diagnoseLanguageOptionValueMismatch(Diags, Description, \ + ModuleFilename); \ } \ } \ } @@ -333,9 +331,8 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, (CK::Compatibility == CK::Compatible && \ !AllowCompatibleDifferences)) { \ if (ExistingLangOpts.Name != LangOpts.Name) { \ - diagnoseLanguageOptionValueMismatch(Diags, Description, \ - ModuleFilename); \ - return true; \ + return diagnoseLanguageOptionValueMismatch(Diags, Description, \ + ModuleFilename); \ } \ } \ } @@ -346,9 +343,8 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, (CK::Compatibility == CK::Compatible && \ !AllowCompatibleDifferences)) { \ if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ - diagnoseLanguageOptionValueMismatch(Diags, Description, \ - ModuleFilename); \ - return true; \ + return diagnoseLanguageOptionValueMismatch(Diags, Description, \ + ModuleFilename); \ } \ } \ } @@ -356,22 +352,19 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, #include "clang/Basic/LangOptions.def" if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) { - diagnoseLanguageOptionValueMismatch(Diags, "module features", - ModuleFilename); - return true; + return diagnoseLanguageOptionValueMismatch(Diags, "module features", + ModuleFilename); } if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { - diagnoseLanguageOptionValueMismatch(Diags, "target Objective-C runtime", - ModuleFilename); - return true; + return diagnoseLanguageOptionValueMismatch( + Diags, "target Objective-C runtime", ModuleFilename); } if (ExistingLangOpts.CommentOpts.BlockCommandNames != LangOpts.CommentOpts.BlockCommandNames) { - diagnoseLanguageOptionValueMismatch(Diags, "block command names", - ModuleFilename); - return true; + return diagnoseLanguageOptionValueMismatch(Diags, "block command names", + ModuleFilename); } // Sanitizer feature mismatches are treated as compatible differences. If >From f40663a12aa3b499a070dde9be9211e882b3f358 Mon Sep 17 00:00:00 2001 From: David Zbarsky <[email protected]> Date: Tue, 7 Jul 2026 21:12:29 -0400 Subject: [PATCH 4/4] Trigger CI _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
