[clang] [clang] Do not serialize function definitions without a body (PR #121550)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 5 17:58:09 PST 2025


================
@@ -6227,8 +6227,10 @@ void ASTWriter::WriteDeclUpdatesBlocks(ASTContext &Context,
     // Add a trailing update record, if any. These must go last because we
     // lazily load their attached statement.
     if (!GeneratingReducedBMI || !CanElideDeclDef(D)) {
-      if (HasUpdatedBody) {
-        const auto *Def = cast<FunctionDecl>(D);
+      assert(!(HasUpdatedBody && HasAddedVarDefinition) &&
+             "Declaration can not be both a FunctionDecl and a VarDecl");
+      if (const auto *Def = dyn_cast<FunctionDecl>(D);
+          HasUpdatedBody && Def->doesThisDeclarationHaveABody()) {
----------------
ChuanqiXu9 wrote:

Logically, it looks better to not set `HasUpdatedBody` if the declaration doesn't have a body.

https://github.com/llvm/llvm-project/pull/121550


More information about the cfe-commits mailing list