[clang] [clang][NFC][diagnostics] Remove several uses of `getCustomDiagID()` (PR #172532)
Dave Bartolomeo via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 23 06:14:03 PST 2025
https://github.com/dbartol updated https://github.com/llvm/llvm-project/pull/172532
>From ae2cf1fb4d015aa8ee2efd5f9503fe41081820d4 Mon Sep 17 00:00:00 2001
From: Dave Bartolomeo <dave_bartolomeo at apple.com>
Date: Tue, 16 Dec 2025 13:33:42 -0500
Subject: [PATCH 1/3] [clang][NFC][diagnostics] Remove several uses of
`getCustomDiagID()`
This change converts all existing uses of `getCustomDiagID()` within the `clang/AST` library into regular diagnostics defined in `DiagnosticASTKinds.td`.
This is mostly just cleanup, but it will also help with future changes to the diagnostic system by letting us focus on the custom diagnostic scenarios that _don't_ fit into the usual pre-declared diagnostic scenario.
---
.../include/clang/Basic/DiagnosticASTKinds.td | 34 ++++++++++
clang/lib/AST/ASTContext.cpp | 6 +-
clang/lib/AST/ItaniumMangle.cpp | 65 +++++++------------
clang/lib/AST/MicrosoftCXXABI.cpp | 5 +-
clang/lib/AST/MicrosoftMangle.cpp | 14 ++--
clang/lib/AST/VTableBuilder.cpp | 6 +-
6 files changed, 69 insertions(+), 61 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td b/clang/include/clang/Basic/DiagnosticASTKinds.td
index e90ee9d376e07..11f1f1e56bf72 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -606,6 +606,8 @@ def warn_odr_objc_synthesize_ivar_inconsistent : Warning<
InGroup<ODR>;
def note_odr_objc_synthesize_ivar_here : Note<
"property is synthesized to ivar %0 here">;
+def err_unsupported_objc_primitive_encoding
+ : Error<"cannot yet @encode type %0">;
// Importing C++ ASTs
def note_odr_friend : Note<"friend declared here">;
@@ -1043,6 +1045,38 @@ def warn_npot_ms_struct : Warning<
def err_itanium_layout_unimplemented : Error<
"Itanium-compatible layout for the Microsoft C++ ABI is not yet supported">;
+// Unsupported features in name mangling
+def err_itanium_mangle_fixed_point_literal
+ : Error<"cannot mangle fixed point literals yet">;
+def err_itanium_mangle_dependent_neon_vector
+ : Error<"cannot mangle this dependent neon vector type yet">;
+def err_itanium_mangle_dependent_fixed_length_sve_vector
+ : Error<"cannot mangle this dependent fixed-length SVE vector type yet">;
+def err_itanium_mangle_dependent_fixed_length_rvv_vector
+ : Error<"cannot mangle this dependent fixed-length RVV vector type yet">;
+def err_itanium_mangle_requires_expr_with_substitution_failure
+ : Error<"cannot mangle this requires-expression containing a substitution "
+ "failure">;
+def err_itanium_mangle_unsupported_expr_type
+ : Error<"cannot yet mangle expression type %0">;
+def err_itanium_mangle_ternary_omitted_operand
+ : Error<"?: operator with omitted middle operand cannot be mangled">;
+def err_itanium_mangle_unsupported_expr
+ : Error<"cannot yet mangle %0 expression">;
+def err_itanium_mangle_openacc_asterisk_size_expr
+ : Error<"cannot yet mangle OpenACC Asterisk Size expression">;
+def err_itanium_mangle_unnamed_union_nttp
+ : Error<"cannot mangle this unnamed union NTTP yet">;
+
+def err_ms_mangle_number_overflow
+ : Error<"mangling number exceeds limit (65535)">;
+def err_ms_mangle_unsupported_with_detail
+ : Error<"cannot mangle this %0 %1 yet">;
+def err_ms_mangle_unsupported : Error<"cannot mangle this %0 yet">;
+
+def err_unexpected_vftable_component
+ : Error<"unexpected vftable component type %0 for component number %1">;
+
// -Wpadded-bitfield
def warn_padded_struct_bitfield : Warning<
"padding %select{struct|interface|class}0 %1 with %2 "
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index f52470a4d7458..85f8b02b92f70 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -50,6 +50,7 @@
#include "clang/Basic/AddressSpaces.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/CommentOptions.h"
+#include "clang/Basic/DiagnosticAST.h"
#include "clang/Basic/ExceptionSpecificationType.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
@@ -9107,9 +9108,8 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
#include "clang/Basic/AMDGPUTypes.def"
{
DiagnosticsEngine &Diags = C->getDiagnostics();
- unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
- "cannot yet @encode type %0");
- Diags.Report(DiagID) << BT->getName(C->getPrintingPolicy());
+ Diags.Report(diag::err_unsupported_objc_primitive_encoding)
+ << BT->getName(C->getPrintingPolicy());
return ' ';
}
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index fe12a506643c9..f8be6ce786a7d 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -28,6 +28,7 @@
#include "clang/AST/Mangle.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/ABI.h"
+#include "clang/Basic/DiagnosticAST.h"
#include "clang/Basic/Module.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Thunk.h"
@@ -1249,9 +1250,7 @@ void CXXNameMangler::mangleFloatLiteral(QualType T, const llvm::APFloat &V) {
void CXXNameMangler::mangleFixedPointLiteral() {
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error, "cannot mangle fixed point literals yet");
- Diags.Report(DiagID);
+ Diags.Report(diag::err_itanium_mangle_fixed_point_literal);
}
void CXXNameMangler::mangleNullPointer(QualType T) {
@@ -3969,10 +3968,8 @@ void CXXNameMangler::mangleNeonVectorType(const VectorType *T) {
void CXXNameMangler::mangleNeonVectorType(const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error,
- "cannot mangle this dependent neon vector type yet");
- Diags.Report(T->getAttributeLoc(), DiagID);
+ Diags.Report(T->getAttributeLoc(),
+ diag::err_itanium_mangle_dependent_neon_vector);
}
static StringRef mangleAArch64VectorBase(const BuiltinType *EltType) {
@@ -4048,10 +4045,8 @@ void CXXNameMangler::mangleAArch64NeonVectorType(const VectorType *T) {
}
void CXXNameMangler::mangleAArch64NeonVectorType(const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error,
- "cannot mangle this dependent neon vector type yet");
- Diags.Report(T->getAttributeLoc(), DiagID);
+ Diags.Report(T->getAttributeLoc(),
+ diag::err_itanium_mangle_dependent_neon_vector);
}
// The AArch64 ACLE specifies that fixed-length SVE vector and predicate types
@@ -4146,10 +4141,8 @@ void CXXNameMangler::mangleAArch64FixedSveVectorType(const VectorType *T) {
void CXXNameMangler::mangleAArch64FixedSveVectorType(
const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error,
- "cannot mangle this dependent fixed-length SVE vector type yet");
- Diags.Report(T->getAttributeLoc(), DiagID);
+ Diags.Report(T->getAttributeLoc(),
+ diag::err_itanium_mangle_dependent_fixed_length_sve_vector);
}
void CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) {
@@ -4252,10 +4245,8 @@ void CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) {
void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error,
- "cannot mangle this dependent fixed-length RVV vector type yet");
- Diags.Report(T->getAttributeLoc(), DiagID);
+ Diags.Report(T->getAttributeLoc(),
+ diag::err_itanium_mangle_dependent_fixed_length_rvv_vector);
}
// GNU extension: vector types
@@ -4784,10 +4775,9 @@ void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
auto HandleSubstitutionFailure =
[&](SourceLocation Loc) {
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error, "cannot mangle this requires-expression "
- "containing a substitution failure");
- Diags.Report(Loc, DiagID);
+ Diags.Report(
+ Loc,
+ diag::err_itanium_mangle_requires_expr_with_substitution_failure);
Out << 'F';
};
@@ -4988,10 +4978,9 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
if (!NullOut) {
// As bad as this diagnostic is, it's better than crashing.
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
- "cannot yet mangle expression type %0");
- Diags.Report(E->getExprLoc(), DiagID)
- << E->getStmtClassName() << E->getSourceRange();
+ Diags.Report(E->getExprLoc(),
+ diag::err_itanium_mangle_unsupported_expr_type)
+ << E->getStmtClassName() << E->getSourceRange();
return;
}
break;
@@ -5027,11 +5016,9 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case Expr::BinaryConditionalOperatorClass: {
NotPrimaryExpr();
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID =
- Diags.getCustomDiagID(DiagnosticsEngine::Error,
- "?: operator with omitted middle operand cannot be mangled");
- Diags.Report(E->getExprLoc(), DiagID)
- << E->getStmtClassName() << E->getSourceRange();
+ Diags.Report(E->getExprLoc(),
+ diag::err_itanium_mangle_ternary_omitted_operand)
+ << E->getStmtClassName() << E->getSourceRange();
return;
}
@@ -5402,9 +5389,8 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case UETT_PtrAuthTypeDiscriminator:
case UETT_DataSizeOf: {
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error, "cannot yet mangle %0 expression");
- Diags.Report(E->getExprLoc(), DiagID) << getTraitSpelling(SAE->getKind());
+ Diags.Report(E->getExprLoc(), diag::err_itanium_mangle_unsupported_expr)
+ << getTraitSpelling(SAE->getKind());
return;
}
}
@@ -5906,10 +5892,7 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case Expr::OpenACCAsteriskSizeExprClass: {
// We shouldn't ever be able to get here, but diagnose anyway.
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error,
- "cannot yet mangle OpenACC Asterisk Size expression");
- Diags.Report(DiagID);
+ Diags.Report(diag::err_itanium_mangle_openacc_asterisk_size_expr);
return;
}
}
@@ -6527,9 +6510,7 @@ static IdentifierInfo *getUnionInitName(SourceLocation UnionLoc,
// of the data members in the union are unnamed), then there is no way for a
// program to refer to the anonymous union, and there is therefore no need to
// mangle its name. However, we should diagnose this anyway.
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error, "cannot mangle this unnamed union NTTP yet");
- Diags.Report(UnionLoc, DiagID);
+ Diags.Report(UnionLoc, diag::err_itanium_mangle_unnamed_union_nttp);
return nullptr;
}
diff --git a/clang/lib/AST/MicrosoftCXXABI.cpp b/clang/lib/AST/MicrosoftCXXABI.cpp
index 1c020c3ad4ad5..438feac9ca9b2 100644
--- a/clang/lib/AST/MicrosoftCXXABI.cpp
+++ b/clang/lib/AST/MicrosoftCXXABI.cpp
@@ -20,6 +20,7 @@
#include "clang/AST/MangleNumberingContext.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/Type.h"
+#include "clang/Basic/DiagnosticAST.h"
#include "clang/Basic/TargetInfo.h"
using namespace clang;
@@ -83,9 +84,7 @@ class MSHIPNumberingContext : public MicrosoftNumberingContext {
MicrosoftNumberingContext::getManglingNumber(TD, MSLocalManglingNumber);
if (DeviceN > 0xFFFF || HostN > 0xFFFF) {
DiagnosticsEngine &Diags = TD->getASTContext().getDiagnostics();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error, "Mangling number exceeds limit (65535)");
- Diags.Report(TD->getLocation(), DiagID);
+ Diags.Report(TD->getLocation(), diag::err_ms_mangle_number_overflow);
}
return (DeviceN << 16) | HostN;
}
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 551aa7bf3321c..388094096d294 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -25,6 +25,7 @@
#include "clang/AST/Mangle.h"
#include "clang/AST/VTableBuilder.h"
#include "clang/Basic/ABI.h"
+#include "clang/Basic/DiagnosticAST.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
@@ -578,25 +579,20 @@ DiagnosticBuilder MicrosoftCXXNameMangler::Error(SourceLocation loc,
StringRef thing1,
StringRef thing2) {
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
- "cannot mangle this %0 %1 yet");
- return Diags.Report(loc, DiagID) << thing1 << thing2;
+ return Diags.Report(loc, diag::err_ms_mangle_unsupported_with_detail)
+ << thing1 << thing2;
}
DiagnosticBuilder MicrosoftCXXNameMangler::Error(SourceLocation loc,
StringRef thingy) {
DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
- "cannot mangle this %0 yet");
- return Diags.Report(loc, DiagID) << thingy;
+ return Diags.Report(loc, diag::err_ms_mangle_unsupported) << thingy;
}
DiagnosticBuilder MicrosoftCXXNameMangler::Error(StringRef thingy) {
DiagnosticsEngine &Diags = Context.getDiags();
// extra placeholders are ignored quietly when not used
- unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
- "cannot mangle this %0 yet");
- return Diags.Report(DiagID) << thingy;
+ return Diags.Report(diag::err_ms_mangle_unsupported) << thingy;
}
void MicrosoftCXXNameMangler::mangle(GlobalDecl GD, StringRef Prefix) {
diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp
index d97f10cb9d1a1..5987b18e6cd6c 100644
--- a/clang/lib/AST/VTableBuilder.cpp
+++ b/clang/lib/AST/VTableBuilder.cpp
@@ -3315,10 +3315,8 @@ void VFTableBuilder::dumpLayout(raw_ostream &Out) {
default:
DiagnosticsEngine &Diags = Context.getDiagnostics();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error,
- "Unexpected vftable component type %0 for component number %1");
- Diags.Report(MostDerivedClass->getLocation(), DiagID)
+ Diags.Report(MostDerivedClass->getLocation(),
+ diag::err_unexpected_vftable_component)
<< I << Component.getKind();
}
>From 81d0054c6855633f3a7b163eeddc79047f37db74 Mon Sep 17 00:00:00 2001
From: Dave Bartolomeo <dave_bartolomeo at apple.com>
Date: Fri, 19 Dec 2025 12:11:10 -0500
Subject: [PATCH 2/3] Merge some Itanium mangling diagnostics
Merges several separate diagnostics about unsupported Itanium name mangling features into a single diagnostic with an `enum_select`.
---
.../include/clang/Basic/DiagnosticASTKinds.td | 38 ++++++++---------
clang/lib/AST/ItaniumMangle.cpp | 41 ++++++++++---------
2 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 11f1f1e56bf72..42ff03f9224ac 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -1046,27 +1046,25 @@ def err_itanium_layout_unimplemented : Error<
"Itanium-compatible layout for the Microsoft C++ ABI is not yet supported">;
// Unsupported features in name mangling
-def err_itanium_mangle_fixed_point_literal
- : Error<"cannot mangle fixed point literals yet">;
-def err_itanium_mangle_dependent_neon_vector
- : Error<"cannot mangle this dependent neon vector type yet">;
-def err_itanium_mangle_dependent_fixed_length_sve_vector
- : Error<"cannot mangle this dependent fixed-length SVE vector type yet">;
-def err_itanium_mangle_dependent_fixed_length_rvv_vector
- : Error<"cannot mangle this dependent fixed-length RVV vector type yet">;
-def err_itanium_mangle_requires_expr_with_substitution_failure
- : Error<"cannot mangle this requires-expression containing a substitution "
- "failure">;
-def err_itanium_mangle_unsupported_expr_type
- : Error<"cannot yet mangle expression type %0">;
-def err_itanium_mangle_ternary_omitted_operand
- : Error<"?: operator with omitted middle operand cannot be mangled">;
-def err_itanium_mangle_unsupported_expr
+def err_unsupported_itanium_mangling
+ : Error<"cannot yet mangle "
+ "%enum_select<UnsupportedItaniumManglingKind>"
+ "{%FixedPointLiteral{fixed point literal}"
+ "|%DependentNeonVector{dependent neon vector type}"
+ "|%DependentFixedLengthSVEVector{dependent fixed-length SVE vector "
+ "type}"
+ "|%DependentFixedLengthRVVVectorType{dependent fixed-length RVV "
+ "vector type}"
+ "|%TernaryWithOmittedMiddleOperand{?: operator with omitted middle "
+ "operand}"
+ "|%OpenACCAsteriskSizeExpr{OpenACC Asterisk Size expression}"
+ "|%UnnamedUnionNTTP{unnamed union non-type template parameter}"
+ "|%RequiresExprWithSubstitutionFailure{requires-expression "
+ "containing a substitution failure}"
+ "}0 yet">;
+
+def err_unsupported_itanium_expr_mangling
: Error<"cannot yet mangle %0 expression">;
-def err_itanium_mangle_openacc_asterisk_size_expr
- : Error<"cannot yet mangle OpenACC Asterisk Size expression">;
-def err_itanium_mangle_unnamed_union_nttp
- : Error<"cannot mangle this unnamed union NTTP yet">;
def err_ms_mangle_number_overflow
: Error<"mangling number exceeds limit (65535)">;
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index f8be6ce786a7d..32b44ace63d59 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -39,6 +39,7 @@
#include <optional>
using namespace clang;
+using namespace clang::diag;
namespace {
@@ -1250,7 +1251,8 @@ void CXXNameMangler::mangleFloatLiteral(QualType T, const llvm::APFloat &V) {
void CXXNameMangler::mangleFixedPointLiteral() {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(diag::err_itanium_mangle_fixed_point_literal);
+ Diags.Report(err_unsupported_itanium_mangling)
+ << UnsupportedItaniumManglingKind::FixedPointLiteral;
}
void CXXNameMangler::mangleNullPointer(QualType T) {
@@ -3968,8 +3970,8 @@ void CXXNameMangler::mangleNeonVectorType(const VectorType *T) {
void CXXNameMangler::mangleNeonVectorType(const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(T->getAttributeLoc(),
- diag::err_itanium_mangle_dependent_neon_vector);
+ Diags.Report(T->getAttributeLoc(), err_unsupported_itanium_mangling)
+ << UnsupportedItaniumManglingKind::DependentNeonVector;
}
static StringRef mangleAArch64VectorBase(const BuiltinType *EltType) {
@@ -4045,8 +4047,8 @@ void CXXNameMangler::mangleAArch64NeonVectorType(const VectorType *T) {
}
void CXXNameMangler::mangleAArch64NeonVectorType(const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(T->getAttributeLoc(),
- diag::err_itanium_mangle_dependent_neon_vector);
+ Diags.Report(T->getAttributeLoc(), err_unsupported_itanium_mangling)
+ << UnsupportedItaniumManglingKind::DependentNeonVector;
}
// The AArch64 ACLE specifies that fixed-length SVE vector and predicate types
@@ -4141,8 +4143,8 @@ void CXXNameMangler::mangleAArch64FixedSveVectorType(const VectorType *T) {
void CXXNameMangler::mangleAArch64FixedSveVectorType(
const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(T->getAttributeLoc(),
- diag::err_itanium_mangle_dependent_fixed_length_sve_vector);
+ Diags.Report(T->getAttributeLoc(), err_unsupported_itanium_mangling)
+ << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
}
void CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) {
@@ -4245,8 +4247,8 @@ void CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) {
void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(T->getAttributeLoc(),
- diag::err_itanium_mangle_dependent_fixed_length_rvv_vector);
+ Diags.Report(T->getAttributeLoc(), err_unsupported_itanium_mangling)
+ << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
}
// GNU extension: vector types
@@ -4775,9 +4777,9 @@ void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
auto HandleSubstitutionFailure =
[&](SourceLocation Loc) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(
- Loc,
- diag::err_itanium_mangle_requires_expr_with_substitution_failure);
+ Diags.Report(Loc, err_unsupported_itanium_mangling)
+ << UnsupportedItaniumManglingKind::
+ RequiresExprWithSubstitutionFailure;
Out << 'F';
};
@@ -4978,8 +4980,7 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
if (!NullOut) {
// As bad as this diagnostic is, it's better than crashing.
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(E->getExprLoc(),
- diag::err_itanium_mangle_unsupported_expr_type)
+ Diags.Report(E->getExprLoc(), err_unsupported_itanium_expr_mangling)
<< E->getStmtClassName() << E->getSourceRange();
return;
}
@@ -5016,8 +5017,8 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case Expr::BinaryConditionalOperatorClass: {
NotPrimaryExpr();
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(E->getExprLoc(),
- diag::err_itanium_mangle_ternary_omitted_operand)
+ Diags.Report(E->getExprLoc(), err_unsupported_itanium_mangling)
+ << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
<< E->getStmtClassName() << E->getSourceRange();
return;
}
@@ -5389,7 +5390,7 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case UETT_PtrAuthTypeDiscriminator:
case UETT_DataSizeOf: {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(E->getExprLoc(), diag::err_itanium_mangle_unsupported_expr)
+ Diags.Report(E->getExprLoc(), err_unsupported_itanium_expr_mangling)
<< getTraitSpelling(SAE->getKind());
return;
}
@@ -5892,7 +5893,8 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case Expr::OpenACCAsteriskSizeExprClass: {
// We shouldn't ever be able to get here, but diagnose anyway.
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(diag::err_itanium_mangle_openacc_asterisk_size_expr);
+ Diags.Report(err_unsupported_itanium_mangling)
+ << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
return;
}
}
@@ -6510,7 +6512,8 @@ static IdentifierInfo *getUnionInitName(SourceLocation UnionLoc,
// of the data members in the union are unnamed), then there is no way for a
// program to refer to the anonymous union, and there is therefore no need to
// mangle its name. However, we should diagnose this anyway.
- Diags.Report(UnionLoc, diag::err_itanium_mangle_unnamed_union_nttp);
+ Diags.Report(UnionLoc, err_unsupported_itanium_mangling)
+ << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
return nullptr;
}
>From 74f2d7b418bda187bc9f62fb38222c50886f19ac Mon Sep 17 00:00:00 2001
From: Dave Bartolomeo <dave_bartolomeo at apple.com>
Date: Tue, 23 Dec 2025 09:13:46 -0500
Subject: [PATCH 3/3] Fix PR feedback
---
.../include/clang/Basic/DiagnosticASTKinds.td | 48 +++++++++----------
clang/lib/AST/ItaniumMangle.cpp | 27 ++++++-----
2 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 42ff03f9224ac..6217f421f103d 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -1046,34 +1046,34 @@ def err_itanium_layout_unimplemented : Error<
"Itanium-compatible layout for the Microsoft C++ ABI is not yet supported">;
// Unsupported features in name mangling
-def err_unsupported_itanium_mangling
- : Error<"cannot yet mangle "
- "%enum_select<UnsupportedItaniumManglingKind>"
- "{%FixedPointLiteral{fixed point literal}"
- "|%DependentNeonVector{dependent neon vector type}"
- "|%DependentFixedLengthSVEVector{dependent fixed-length SVE vector "
- "type}"
- "|%DependentFixedLengthRVVVectorType{dependent fixed-length RVV "
- "vector type}"
- "|%TernaryWithOmittedMiddleOperand{?: operator with omitted middle "
- "operand}"
- "|%OpenACCAsteriskSizeExpr{OpenACC Asterisk Size expression}"
- "|%UnnamedUnionNTTP{unnamed union non-type template parameter}"
- "|%RequiresExprWithSubstitutionFailure{requires-expression "
- "containing a substitution failure}"
- "}0 yet">;
+def err_unsupported_itanium_mangling : Error<
+ "cannot yet mangle "
+ "%enum_select<UnsupportedItaniumManglingKind>"
+ "{%FixedPointLiteral{fixed point literal}"
+ "|%DependentNeonVector{dependent neon vector type}"
+ "|%DependentFixedLengthSVEVector{dependent fixed-length SVE vector "
+ "type}"
+ "|%DependentFixedLengthRVVVectorType{dependent fixed-length RVV "
+ "vector type}"
+ "|%TernaryWithOmittedMiddleOperand{?: operator with omitted middle "
+ "operand}"
+ "|%OpenACCAsteriskSizeExpr{OpenACC Asterisk Size expression}"
+ "|%UnnamedUnionNTTP{unnamed union non-type template parameter}"
+ "|%RequiresExprWithSubstitutionFailure{requires-expression "
+ "containing a substitution failure}"
+ "}0">;
-def err_unsupported_itanium_expr_mangling
- : Error<"cannot yet mangle %0 expression">;
+def err_unsupported_itanium_expr_mangling : Error<
+ "cannot yet mangle %0 expression">;
-def err_ms_mangle_number_overflow
- : Error<"mangling number exceeds limit (65535)">;
-def err_ms_mangle_unsupported_with_detail
- : Error<"cannot mangle this %0 %1 yet">;
+def err_ms_mangle_number_overflow : Error<
+ "mangling number exceeds limit (65535)">;
+def err_ms_mangle_unsupported_with_detail : Error<
+ "cannot mangle this %0 %1 yet">;
def err_ms_mangle_unsupported : Error<"cannot mangle this %0 yet">;
-def err_unexpected_vftable_component
- : Error<"unexpected vftable component type %0 for component number %1">;
+def err_unexpected_vftable_component : Error<
+ "unexpected vftable component type %0 for component number %1">;
// -Wpadded-bitfield
def warn_padded_struct_bitfield : Warning<
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 32b44ace63d59..60498209d6bdb 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -39,7 +39,8 @@
#include <optional>
using namespace clang;
-using namespace clang::diag;
+namespace UnsupportedItaniumManglingKind =
+ clang::diag::UnsupportedItaniumManglingKind;
namespace {
@@ -1251,7 +1252,7 @@ void CXXNameMangler::mangleFloatLiteral(QualType T, const llvm::APFloat &V) {
void CXXNameMangler::mangleFixedPointLiteral() {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(err_unsupported_itanium_mangling)
+ Diags.Report(diag::err_unsupported_itanium_mangling)
<< UnsupportedItaniumManglingKind::FixedPointLiteral;
}
@@ -3970,7 +3971,7 @@ void CXXNameMangler::mangleNeonVectorType(const VectorType *T) {
void CXXNameMangler::mangleNeonVectorType(const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(T->getAttributeLoc(), err_unsupported_itanium_mangling)
+ Diags.Report(T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
<< UnsupportedItaniumManglingKind::DependentNeonVector;
}
@@ -4047,7 +4048,7 @@ void CXXNameMangler::mangleAArch64NeonVectorType(const VectorType *T) {
}
void CXXNameMangler::mangleAArch64NeonVectorType(const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(T->getAttributeLoc(), err_unsupported_itanium_mangling)
+ Diags.Report(T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
<< UnsupportedItaniumManglingKind::DependentNeonVector;
}
@@ -4143,7 +4144,7 @@ void CXXNameMangler::mangleAArch64FixedSveVectorType(const VectorType *T) {
void CXXNameMangler::mangleAArch64FixedSveVectorType(
const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(T->getAttributeLoc(), err_unsupported_itanium_mangling)
+ Diags.Report(T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
<< UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
}
@@ -4247,7 +4248,7 @@ void CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) {
void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const DependentVectorType *T) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(T->getAttributeLoc(), err_unsupported_itanium_mangling)
+ Diags.Report(T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
<< UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
}
@@ -4777,7 +4778,7 @@ void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
auto HandleSubstitutionFailure =
[&](SourceLocation Loc) {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(Loc, err_unsupported_itanium_mangling)
+ Diags.Report(Loc, diag::err_unsupported_itanium_mangling)
<< UnsupportedItaniumManglingKind::
RequiresExprWithSubstitutionFailure;
Out << 'F';
@@ -4980,7 +4981,7 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
if (!NullOut) {
// As bad as this diagnostic is, it's better than crashing.
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(E->getExprLoc(), err_unsupported_itanium_expr_mangling)
+ Diags.Report(E->getExprLoc(), diag::err_unsupported_itanium_expr_mangling)
<< E->getStmtClassName() << E->getSourceRange();
return;
}
@@ -5017,9 +5018,9 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case Expr::BinaryConditionalOperatorClass: {
NotPrimaryExpr();
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(E->getExprLoc(), err_unsupported_itanium_mangling)
+ Diags.Report(E->getExprLoc(), diag::err_unsupported_itanium_mangling)
<< UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
- << E->getStmtClassName() << E->getSourceRange();
+ << E->getSourceRange();
return;
}
@@ -5390,7 +5391,7 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case UETT_PtrAuthTypeDiscriminator:
case UETT_DataSizeOf: {
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(E->getExprLoc(), err_unsupported_itanium_expr_mangling)
+ Diags.Report(E->getExprLoc(), diag::err_unsupported_itanium_expr_mangling)
<< getTraitSpelling(SAE->getKind());
return;
}
@@ -5893,7 +5894,7 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case Expr::OpenACCAsteriskSizeExprClass: {
// We shouldn't ever be able to get here, but diagnose anyway.
DiagnosticsEngine &Diags = Context.getDiags();
- Diags.Report(err_unsupported_itanium_mangling)
+ Diags.Report(diag::err_unsupported_itanium_mangling)
<< UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
return;
}
@@ -6512,7 +6513,7 @@ static IdentifierInfo *getUnionInitName(SourceLocation UnionLoc,
// of the data members in the union are unnamed), then there is no way for a
// program to refer to the anonymous union, and there is therefore no need to
// mangle its name. However, we should diagnose this anyway.
- Diags.Report(UnionLoc, err_unsupported_itanium_mangling)
+ Diags.Report(UnionLoc, diag::err_unsupported_itanium_mangling)
<< UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
return nullptr;
More information about the cfe-commits
mailing list