[clang] [llvm] Disentangle DISubprogram ODR type method uniquing from metadata uniquing (PR #217042)
Vladislav Dzhidzhoev via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 22 17:21:42 PST 2026
================
@@ -0,0 +1,80 @@
+//===- llvm/IR/DebugInfoODRUniquer.cpp - Debug Information Builder --------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines a class used to merge debug info for ODR types.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/DebugInfoODRUniquer.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+
+using namespace llvm;
+
+DISubprogram *DebugInfoODRUniquer::getODRSubprogramDecl(DIScope *Scope,
+ StringRef LinkageName) {
+ // Only methods, which have a type scope, are eligable for ODR uniquing.
+ auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
+ if (!CT || !CT->getRawIdentifier())
+ return nullptr;
+
+ auto R =
+ FnDecls.find_as(DISubprogramODRKey(CT->getIdentifier(), LinkageName));
+ if (R == FnDecls.end())
+ return nullptr;
+
+ assert(!(*R)->isDefinition() && "definition unexpectedly ODR-uniqued");
+ return *R;
+}
+
+void DebugInfoODRUniquer::addSubprogramDecl(DISubprogram *SP) {
+ assert(!SP->isDefinition() &&
+ "only expect declarations DISubprogram ODR uniquing");
+ assert(!SP->isDistinct() && "expect declarations to be uniqued");
+
+ if (SP->getLinkageName().empty())
+ return;
+ // Only methods, which have a type scope, are eligable for ODR uniquing.
+ auto *CT = dyn_cast_or_null<DICompositeType>(SP->getScope());
----------------
dzhidzhoev wrote:
Since mailformed IR can reach here, I would replace `SP->getScope()` with `SP->getRawScope()`. `dyn_cast_or_null` should still filter out non-DICompositeType scopes.
https://github.com/llvm/llvm-project/pull/217042
More information about the cfe-commits
mailing list