[clang] [Clang] Remove redundant DeclContext workaround for local extern decls (PR #186665)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 15 05:54:00 PDT 2026
https://github.com/eiytoq created https://github.com/llvm/llvm-project/pull/186665
This patch removes an out-of-date FIXME.
The underlying issue was already fixed by `Sema::adjustContextForLocalExternDecl` in `clang/lib/Sema/SemaDecl.cpp`.
>From 21d8bebf422151823648ff028dfed0d5b4d14a8f Mon Sep 17 00:00:00 2001
From: eiytoq <eiytoq at outlook.com>
Date: Sun, 15 Mar 2026 20:51:09 +0800
Subject: [PATCH] [Clang] Remove redundant DeclContext workaround for local
extern decls
---
clang/lib/AST/ItaniumMangle.cpp | 15 ++-------------
clang/lib/AST/MicrosoftMangle.cpp | 9 ---------
2 files changed, 2 insertions(+), 22 deletions(-)
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index eea04b14eaf09..391485bea05b3 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -800,10 +800,6 @@ bool ItaniumMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) {
// Variables at global scope are not mangled unless they have internal
// linkage or are specializations or are attached to a named module.
const DeclContext *DC = getEffectiveDeclContext(D);
- // Check for extern variable declared locally.
- if (DC->isFunctionOrMethod() && D->hasLinkage())
- while (!DC->isFileContext())
- DC = getEffectiveParentContext(DC);
if (DC->isTranslationUnit() && D->getFormalLinkage() != Linkage::Internal &&
!CXXNameMangler::shouldHaveAbiTags(*this, VD) &&
!isa<VarTemplateSpecializationDecl>(VD) &&
@@ -1077,15 +1073,8 @@ void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
const DeclContext *DC = Context.getEffectiveDeclContext(ND);
bool IsLambda = isLambda(ND);
- // If this is an extern variable declared locally, the relevant DeclContext
- // is that of the containing namespace, or the translation unit.
- // FIXME: This is a hack; extern variables declared locally should have
- // a proper semantic declaration context!
- if (isLocalContainerContext(DC) && ND->hasLinkage() && !IsLambda)
- while (!DC->isNamespace() && !DC->isTranslationUnit())
- DC = Context.getEffectiveParentContext(DC);
- else if (GetLocalClassDecl(ND) &&
- (!IsLambda || isCompatibleWith(LangOptions::ClangABI::Ver18))) {
+ if (GetLocalClassDecl(ND) &&
+ (!IsLambda || isCompatibleWith(LangOptions::ClangABI::Ver18))) {
mangleLocalName(GD, AdditionalAbiTags);
return;
}
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 1bf92d4209f9f..196f2009d84cf 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -122,10 +122,6 @@ static const DeclContext *getEffectiveDeclContext(const Decl *D) {
return DC->getRedeclContext();
}
-static const DeclContext *getEffectiveParentContext(const DeclContext *DC) {
- return getEffectiveDeclContext(cast<Decl>(DC));
-}
-
static const FunctionDecl *getStructor(const NamedDecl *ND) {
if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(ND))
return FTD->getTemplatedDecl()->getCanonicalDecl();
@@ -557,11 +553,6 @@ bool MicrosoftMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) {
// Variables at global scope with internal linkage are not mangled.
const DeclContext *DC = getEffectiveDeclContext(D);
- // Check for extern variable declared locally.
- if (DC->isFunctionOrMethod() && D->hasLinkage())
- while (!DC->isNamespace() && !DC->isTranslationUnit())
- DC = getEffectiveParentContext(DC);
-
if (DC->isTranslationUnit() && D->getFormalLinkage() == Linkage::Internal &&
!isa<VarTemplateSpecializationDecl>(D) && D->getIdentifier() != nullptr)
return false;
More information about the cfe-commits
mailing list