From 86326398b73b81f84831fb5fc4c12d9219bc0f57 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 1 Jun 2026 19:10:11 +0200 Subject: [PATCH] Merge commit 63c29df8eceb from llvm git (by Dmitry Polukhin): MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Serialization] Fix assertion on re-deserialized friend template spec… (#200566) …ialization in PCH (#198133) A friend function-template specialization declared inside a class template is serialized into a PCH. When the class template is later instantiated while loading the PCH, the friend specialization can be deserialized re-entrantly (VisitFriendDecl -> VisitFunctionDecl -> ... -> VisitFunctionDecl for the same specialization) at the same time as the canonical copy, producing two redeclarations of the same specialization in the template's specialization set. ASTDeclReader::VisitFunctionDecl asserted that this collision could only happen when merging declarations from different modules. Since 38b3d87bd384, friend functions defined inside dependent class templates are loaded eagerly, so the collision can now also occur within a single PCH/AST file (non-modules build), tripping the assertion: Assertion failed: (Reader.getContext().getLangOpts().Modules && "already deserialized this template specialization"), function VisitFunctionDecl The merge that follows (mergeRedeclarable) already links the two redeclarations correctly regardless of whether modules are enabled, so the fix is to drop the modules-only assumption and let the merge run. Fixes https://github.com/llvm/llvm-project/issues/198133 This fixes (well, simply removes :) an assertion when building the cad/OrcaSlicer port with precompiled headers turned on. PR: 295296 MFC after: 3 days --- contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp b/contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp index b918bfbd549c..87224fae5dbb 100644 --- a/contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp @@ -989,8 +989,6 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { if (InsertPos) CommonPtr->Specializations.InsertNode(FTInfo, InsertPos); else { - assert(Reader.getContext().getLangOpts().Modules && - "already deserialized this template specialization"); Existing = ExistingInfo->getFunction(); } }