Author: Dave Bartolomeo
Date: 2026-03-01T16:25:23Z
New Revision: ae7916539918544655bd92b7f9a05b48563483b4

URL: 
https://github.com/llvm/llvm-project/commit/ae7916539918544655bd92b7f9a05b48563483b4
DIFF: 
https://github.com/llvm/llvm-project/commit/ae7916539918544655bd92b7f9a05b48563483b4.diff

LOG: [clang][NFC][diagnostics] Remove several uses of `getCustomDiagID()` 
(#172532)

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.

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticASTKinds.td
    clang/lib/AST/ASTContext.cpp
    clang/lib/AST/ItaniumMangle.cpp
    clang/lib/AST/MicrosoftCXXABI.cpp
    clang/lib/AST/MicrosoftMangle.cpp
    clang/lib/AST/VTableBuilder.cpp
    clang/test/CodeGenObjC/aarch64-sve-types.m

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 1afae9b1fc1a2..bde418695f647 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -595,6 +595,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">;
@@ -1032,6 +1034,36 @@ 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_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_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 d650555d10f11..5fbdff280073f 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"
@@ -9223,9 +9224,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)
+            << QualType(BT, 0);
         return ' ';
       }
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 04201fc11c4ac..1faf7f1466e39 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"
@@ -38,6 +39,8 @@
 #include <optional>
 
 using namespace clang;
+namespace UnsupportedItaniumManglingKind =
+    clang::diag::UnsupportedItaniumManglingKind;
 
 namespace {
 
@@ -1272,9 +1275,8 @@ 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_unsupported_itanium_mangling)
+      << UnsupportedItaniumManglingKind::FixedPointLiteral;
 }
 
 void CXXNameMangler::mangleNullPointer(QualType T) {
@@ -3997,10 +3999,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_unsupported_itanium_mangling)
+      << UnsupportedItaniumManglingKind::DependentNeonVector;
 }
 
 static StringRef mangleAArch64VectorBase(const BuiltinType *EltType) {
@@ -4076,10 +4076,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_unsupported_itanium_mangling)
+      << UnsupportedItaniumManglingKind::DependentNeonVector;
 }
 
 // The AArch64 ACLE specifies that fixed-length SVE vector and predicate types
@@ -4174,10 +4172,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_unsupported_itanium_mangling)
+      << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
 }
 
 void CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) {
@@ -4282,10 +4278,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_unsupported_itanium_mangling)
+      << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
 }
 
 // GNU extension: vector types
@@ -4825,10 +4819,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_unsupported_itanium_mangling)
+            << UnsupportedItaniumManglingKind::
+                   RequiresExprWithSubstitutionFailure;
         Out << 'F';
       };
 
@@ -5036,10 +5029,8 @@ 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_unsupported_itanium_expr_mangling)
+          << E->getStmtClassName() << E->getSourceRange();
       return;
     }
     break;
@@ -5075,11 +5066,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_unsupported_itanium_mangling)
+        << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
+        << E->getSourceRange();
     return;
   }
 
@@ -5450,9 +5439,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_unsupported_itanium_expr_mangling)
+          << getTraitSpelling(SAE->getKind());
       return;
     }
     }
@@ -5963,10 +5951,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();
-    unsigned DiagID = Diags.getCustomDiagID(
-        DiagnosticsEngine::Error,
-        "cannot yet mangle OpenACC Asterisk Size expression");
-    Diags.Report(DiagID);
+    Diags.Report(diag::err_unsupported_itanium_mangling)
+        << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
     return;
   }
   }
@@ -6584,9 +6570,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.
-  unsigned DiagID = Diags.getCustomDiagID(
-      DiagnosticsEngine::Error, "cannot mangle this unnamed union NTTP yet");
-  Diags.Report(UnionLoc, DiagID);
+  Diags.Report(UnionLoc, diag::err_unsupported_itanium_mangling)
+      << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
 
   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 dda39cff10baf..1f28d281be9fe 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..d053feeaf111b 100644
--- a/clang/lib/AST/VTableBuilder.cpp
+++ b/clang/lib/AST/VTableBuilder.cpp
@@ -3315,11 +3315,9 @@ 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)
-          << I << Component.getKind();
+      Diags.Report(MostDerivedClass->getLocation(),
+                   diag::err_unexpected_vftable_component)
+          << Component.getKind() << I;
     }
 
     Out << '\n';

diff  --git a/clang/test/CodeGenObjC/aarch64-sve-types.m 
b/clang/test/CodeGenObjC/aarch64-sve-types.m
index a97ce4b5bd39f..1771ca6722cab 100644
--- a/clang/test/CodeGenObjC/aarch64-sve-types.m
+++ b/clang/test/CodeGenObjC/aarch64-sve-types.m
@@ -3,36 +3,36 @@
 // RUN: not %clang_cc1 -triple aarch64-none-linux-gnu %s -emit-llvm -o - \
 // RUN:   -target-feature +sve,+bf16 2>&1 | FileCheck %s
 
-// CHECK: error: cannot yet @encode type __SVInt8_t
+// CHECK: error: cannot yet @encode type '__SVInt8_t'
 const char s8[] = @encode(__SVInt8_t);
-// CHECK: error: cannot yet @encode type __SVInt16_t
+// CHECK: error: cannot yet @encode type '__SVInt16_t'
 const char s16[] = @encode(__SVInt16_t);
-// CHECK: error: cannot yet @encode type __SVInt32_t
+// CHECK: error: cannot yet @encode type '__SVInt32_t'
 const char s32[] = @encode(__SVInt32_t);
-// CHECK: error: cannot yet @encode type __SVInt64_t
+// CHECK: error: cannot yet @encode type '__SVInt64_t'
 const char s64[] = @encode(__SVInt64_t);
 
-// CHECK: error: cannot yet @encode type __SVUint8_t
+// CHECK: error: cannot yet @encode type '__SVUint8_t'
 const char u8[] = @encode(__SVUint8_t);
-// CHECK: error: cannot yet @encode type __SVUint16_t
+// CHECK: error: cannot yet @encode type '__SVUint16_t'
 const char u16[] = @encode(__SVUint16_t);
-// CHECK: error: cannot yet @encode type __SVUint32_t
+// CHECK: error: cannot yet @encode type '__SVUint32_t'
 const char u32[] = @encode(__SVUint32_t);
-// CHECK: error: cannot yet @encode type __SVUint64_t
+// CHECK: error: cannot yet @encode type '__SVUint64_t'
 const char u64[] = @encode(__SVUint64_t);
 
-// CHECK: error: cannot yet @encode type __SVFloat16_t
+// CHECK: error: cannot yet @encode type '__SVFloat16_t'
 const char f16[] = @encode(__SVFloat16_t);
-// CHECK: error: cannot yet @encode type __SVFloat32_t
+// CHECK: error: cannot yet @encode type '__SVFloat32_t'
 const char f32[] = @encode(__SVFloat32_t);
-// CHECK: error: cannot yet @encode type __SVFloat64_t
+// CHECK: error: cannot yet @encode type '__SVFloat64_t'
 const char f64[] = @encode(__SVFloat64_t);
 
-// CHECK: error: cannot yet @encode type __SVBfloat16_t
+// CHECK: error: cannot yet @encode type '__SVBfloat16_t'
 const char bf16[] = @encode(__SVBfloat16_t);
 
-// CHECK: error: cannot yet @encode type __SVMfloat8_t
+// CHECK: error: cannot yet @encode type '__SVMfloat8_t'
 const char mf8[] = @encode(__SVMfloat8_t);
 
-// CHECK: error: cannot yet @encode type __SVBool_t
+// CHECK: error: cannot yet @encode type '__SVBool_t'
 const char b8[] = @encode(__SVBool_t);


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to