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

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 6 00:32:29 PST 2025


Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/121550 at github.com>


================
@@ -6092,12 +6092,14 @@ void ASTWriter::WriteDeclUpdatesBlocks(ASTContext &Context,
 
       // An updated body is emitted last, so that the reader doesn't need
       // to skip over the lazy body to reach statements for other records.
-      if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION)
-        HasUpdatedBody = true;
-      else if (Kind == UPD_CXX_ADDED_VAR_DEFINITION)
+      if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION) {
+        assert(isa<FunctionDecl>(D) && "expected FunctionDecl");
+        HasUpdatedBody = cast<FunctionDecl>(D)->hasBody();
----------------
ChuanqiXu9 wrote:

Sorry to skip this on the last iteration. We should use `doesThisDeclarationHaveABody` instead of `hasBody`. Since `hasBody` may be more expensive. 

And also it is still slightly better to not set `UPD_CXX_ADDED_FUNCTION_DEFINITION` if the function doesn't have a body.  We can check this in CompletedImplicitDefinition and VariableDefinitionInstantiated.

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


More information about the cfe-commits mailing list