https://github.com/ayokunle321 updated 
https://github.com/llvm/llvm-project/pull/130868

>From dfc517be06531af965dc51b09a0f1ae7965e3e20 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle...@users.noreply.github.com>
Date: Fri, 14 Mar 2025 15:13:05 -0600
Subject: [PATCH 1/4] revert changes in ASTKinds.td file

---
 clang/include/clang/Basic/DiagnosticASTKinds.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index ac53778339a20..9faa8eec56b40 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -1041,4 +1041,4 @@ def warn_unpacked_field
 def warn_unaligned_access : Warning<
   "field %1 within %0 is less aligned than %2 and is usually due to %0 being "
   "packed, which can lead to unaligned accesses">, InGroup<UnalignedAccess>, 
DefaultIgnore;
-}
+}
\ No newline at end of file

>From 9e08ddfb5931d06fa0e725ae7dea8de781489ab7 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle...@users.noreply.github.com>
Date: Wed, 19 Mar 2025 00:12:11 -0600
Subject: [PATCH 2/4] refactor select in note_constexpr_invalid_cast

---
 clang/include/clang/Basic/DiagnosticASTKinds.td |  5 +++--
 clang/lib/AST/ByteCode/Interp.h                 |  6 +++---
 clang/lib/AST/ExprConstant.cpp                  | 16 ++++++++--------
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 9faa8eec56b40..7167f95e88296 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -11,8 +11,9 @@ let Component = "AST" in {
 // Constant expression diagnostics. These (and their users) belong in Sema.
 def note_expr_divide_by_zero : Note<"division by zero">;
 def note_constexpr_invalid_cast : Note<
-  "%select{reinterpret_cast|dynamic_cast|%select{this conversion|cast that"
-  " performs the conversions of a reinterpret_cast}1|cast from %1}0"
+  
"%enum_select<CastKind>{%Reinterpret{reinterpret_cast}|%Dynamic{dynamic_cast}|"
+  "%ThisCastOrReinterpret{%select{this conversion|cast that performs the 
conversions "
+  "of a reinterpret_cast}1}|%CastFrom{cast from %1}}0"
   " is not allowed in a constant expression"
   "%select{| in C++ standards before C++20||}0">;
 def note_constexpr_invalid_void_star_cast : Note<
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index f2ddeac99cd7e..8956a69c7124c 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2366,12 +2366,12 @@ static inline bool PtrPtrCast(InterpState &S, CodePtr 
OpPC, bool SrcIsVoidPtr) {
     } else if (!S.getLangOpts().CPlusPlus26) {
       const SourceInfo &E = S.Current->getSource(OpPC);
       S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-          << 3 << "'void *'" << S.Current->getRange(OpPC);
+          << diag::CastKind::CastFrom << "'void *'" << 
S.Current->getRange(OpPC);
     }
   } else {
     const SourceInfo &E = S.Current->getSource(OpPC);
     S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
+        << diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus 
<< S.Current->getRange(OpPC);
   }
 
   return true;
@@ -2736,7 +2736,7 @@ inline bool GetIntPtr(InterpState &S, CodePtr OpPC, const 
Descriptor *Desc) {
 
   if (Desc)
     S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
-        << 2 << S.getLangOpts().CPlusPlus;
+        << diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus;
 
   S.Stk.push<Pointer>(static_cast<uint64_t>(IntVal), Desc);
   return true;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f8e8aaddbfdbd..9eb8c6717900b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8103,12 +8103,12 @@ class ExprEvaluatorBase
   }
 
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) {
-    CCEDiag(E, diag::note_constexpr_invalid_cast) << 0;
+    CCEDiag(E, diag::note_constexpr_invalid_cast) << 
diag::CastKind::Reinterpret;
     return static_cast<Derived*>(this)->VisitCastExpr(E);
   }
   bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) {
     if (!Info.Ctx.getLangOpts().CPlusPlus20)
-      CCEDiag(E, diag::note_constexpr_invalid_cast) << 1;
+      CCEDiag(E, diag::note_constexpr_invalid_cast) << diag::CastKind::Dynamic;
     return static_cast<Derived*>(this)->VisitCastExpr(E);
   }
   bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E) {
@@ -8833,7 +8833,7 @@ class LValueExprEvaluator
 
     case CK_LValueBitCast:
       this->CCEDiag(E, diag::note_constexpr_invalid_cast)
-          << 2 << Info.Ctx.getLangOpts().CPlusPlus;
+          << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus;
       if (!Visit(E->getSubExpr()))
         return false;
       Result.Designator.setInvalid();
@@ -9670,10 +9670,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
                 << E->getType()->getPointeeType();
           else
             CCEDiag(E, diag::note_constexpr_invalid_cast)
-                << 3 << SubExpr->getType();
+                << diag::CastKind::CastFrom << SubExpr->getType();
         } else
           CCEDiag(E, diag::note_constexpr_invalid_cast)
-              << 2 << Info.Ctx.getLangOpts().CPlusPlus;
+              << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus;
         Result.Designator.setInvalid();
       }
     }
@@ -9712,7 +9712,7 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
 
   case CK_IntegralToPointer: {
     CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << 2 << Info.Ctx.getLangOpts().CPlusPlus;
+        << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus;
 
     APValue Value;
     if (!EvaluateIntegerOrLValue(SubExpr, Value, Info))
@@ -11177,7 +11177,7 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
       // Give up if the input isn't an int, float, or vector.  For example, we
       // reject "(v4i16)(intptr_t)&a".
       Info.FFDiag(E, diag::note_constexpr_invalid_cast)
-          << 2 << Info.Ctx.getLangOpts().CPlusPlus;
+          << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus;
       return false;
     }
 
@@ -15196,7 +15196,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
 
   case CK_PointerToIntegral: {
     CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
+        << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
 
     LValue LV;
     if (!EvaluatePointer(SubExpr, LV, Info))

>From 2a0c5e3afcd0762946aa028bb84956a0d2b73da1 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle...@users.noreply.github.com>
Date: Wed, 19 Mar 2025 08:03:25 -0600
Subject: [PATCH 3/4] fix style

---
 clang/lib/AST/ByteCode/Interp.h |  6 ++++--
 clang/lib/AST/ExprConstant.cpp  | 18 ++++++++++++------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 8956a69c7124c..24d596b3a5d27 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2366,12 +2366,14 @@ static inline bool PtrPtrCast(InterpState &S, CodePtr 
OpPC, bool SrcIsVoidPtr) {
     } else if (!S.getLangOpts().CPlusPlus26) {
       const SourceInfo &E = S.Current->getSource(OpPC);
       S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-          << diag::CastKind::CastFrom << "'void *'" << 
S.Current->getRange(OpPC);
+          << diag::CastKind::CastFrom << "'void *'"
+          << S.Current->getRange(OpPC);
     }
   } else {
     const SourceInfo &E = S.Current->getSource(OpPC);
     S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus 
<< S.Current->getRange(OpPC);
+        << diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus
+        << S.Current->getRange(OpPC);
   }
 
   return true;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 9eb8c6717900b..1ca0a122203f1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8103,7 +8103,8 @@ class ExprEvaluatorBase
   }
 
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) {
-    CCEDiag(E, diag::note_constexpr_invalid_cast) << 
diag::CastKind::Reinterpret;
+    CCEDiag(E, diag::note_constexpr_invalid_cast)
+        << diag::CastKind::Reinterpret;
     return static_cast<Derived*>(this)->VisitCastExpr(E);
   }
   bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) {
@@ -8833,7 +8834,8 @@ class LValueExprEvaluator
 
     case CK_LValueBitCast:
       this->CCEDiag(E, diag::note_constexpr_invalid_cast)
-          << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus;
+          << diag::CastKind::ThisCastOrReinterpret
+          << Info.Ctx.getLangOpts().CPlusPlus;
       if (!Visit(E->getSubExpr()))
         return false;
       Result.Designator.setInvalid();
@@ -9673,7 +9675,8 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
                 << diag::CastKind::CastFrom << SubExpr->getType();
         } else
           CCEDiag(E, diag::note_constexpr_invalid_cast)
-              << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus;
+              << diag::CastKind::ThisCastOrReinterpret
+              << Info.Ctx.getLangOpts().CPlusPlus;
         Result.Designator.setInvalid();
       }
     }
@@ -9712,7 +9715,8 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
 
   case CK_IntegralToPointer: {
     CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus;
+        << diag::CastKind::ThisCastOrReinterpret
+        << Info.Ctx.getLangOpts().CPlusPlus;
 
     APValue Value;
     if (!EvaluateIntegerOrLValue(SubExpr, Value, Info))
@@ -11177,7 +11181,8 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
       // Give up if the input isn't an int, float, or vector.  For example, we
       // reject "(v4i16)(intptr_t)&a".
       Info.FFDiag(E, diag::note_constexpr_invalid_cast)
-          << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus;
+          << diag::CastKind::ThisCastOrReinterpret
+          << Info.Ctx.getLangOpts().CPlusPlus;
       return false;
     }
 
@@ -15196,7 +15201,8 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
 
   case CK_PointerToIntegral: {
     CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << diag::CastKind::ThisCastOrReinterpret << 
Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
+        << diag::CastKind::ThisCastOrReinterpret
+        << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
 
     LValue LV;
     if (!EvaluatePointer(SubExpr, LV, Info))

>From 37e6e47d92e7baf0a01c2a9cca875c24a494e351 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle...@users.noreply.github.com>
Date: Wed, 19 Mar 2025 08:24:09 -0600
Subject: [PATCH 4/4] change invalid constexpr name for an enum_select

---
 .../include/clang/Basic/DiagnosticASTKinds.td  |  2 +-
 clang/lib/AST/ByteCode/Interp.h                |  9 +++++----
 clang/lib/AST/ExprConstant.cpp                 | 18 ++++++++++--------
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 7167f95e88296..721d9e0b26fde 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -11,7 +11,7 @@ let Component = "AST" in {
 // Constant expression diagnostics. These (and their users) belong in Sema.
 def note_expr_divide_by_zero : Note<"division by zero">;
 def note_constexpr_invalid_cast : Note<
-  
"%enum_select<CastKind>{%Reinterpret{reinterpret_cast}|%Dynamic{dynamic_cast}|"
+  
"%enum_select<ConstexprInvalidCastKind>{%Reinterpret{reinterpret_cast}|%Dynamic{dynamic_cast}|"
   "%ThisCastOrReinterpret{%select{this conversion|cast that performs the 
conversions "
   "of a reinterpret_cast}1}|%CastFrom{cast from %1}}0"
   " is not allowed in a constant expression"
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 24d596b3a5d27..7a3ed8313e54d 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2366,14 +2366,14 @@ static inline bool PtrPtrCast(InterpState &S, CodePtr 
OpPC, bool SrcIsVoidPtr) {
     } else if (!S.getLangOpts().CPlusPlus26) {
       const SourceInfo &E = S.Current->getSource(OpPC);
       S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-          << diag::CastKind::CastFrom << "'void *'"
+          << diag::ConstexprInvalidCastKind::CastFrom << "'void *'"
           << S.Current->getRange(OpPC);
     }
   } else {
     const SourceInfo &E = S.Current->getSource(OpPC);
     S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus
-        << S.Current->getRange(OpPC);
+        << diag::ConstexprInvalidCastKind::ThisCastOrReinterpret
+        << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
   }
 
   return true;
@@ -2738,7 +2738,8 @@ inline bool GetIntPtr(InterpState &S, CodePtr OpPC, const 
Descriptor *Desc) {
 
   if (Desc)
     S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
-        << diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus;
+        << diag::ConstexprInvalidCastKind::ThisCastOrReinterpret
+        << S.getLangOpts().CPlusPlus;
 
   S.Stk.push<Pointer>(static_cast<uint64_t>(IntVal), Desc);
   return true;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 1ca0a122203f1..7c18afce15e4a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8104,12 +8104,13 @@ class ExprEvaluatorBase
 
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) {
     CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << diag::CastKind::Reinterpret;
+        << diag::ConstexprInvalidCastKind::Reinterpret;
     return static_cast<Derived*>(this)->VisitCastExpr(E);
   }
   bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) {
     if (!Info.Ctx.getLangOpts().CPlusPlus20)
-      CCEDiag(E, diag::note_constexpr_invalid_cast) << diag::CastKind::Dynamic;
+      CCEDiag(E, diag::note_constexpr_invalid_cast)
+          << diag::ConstexprInvalidCastKind::Dynamic;
     return static_cast<Derived*>(this)->VisitCastExpr(E);
   }
   bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E) {
@@ -8834,7 +8835,7 @@ class LValueExprEvaluator
 
     case CK_LValueBitCast:
       this->CCEDiag(E, diag::note_constexpr_invalid_cast)
-          << diag::CastKind::ThisCastOrReinterpret
+          << diag::ConstexprInvalidCastKind::ThisCastOrReinterpret
           << Info.Ctx.getLangOpts().CPlusPlus;
       if (!Visit(E->getSubExpr()))
         return false;
@@ -9672,10 +9673,11 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
                 << E->getType()->getPointeeType();
           else
             CCEDiag(E, diag::note_constexpr_invalid_cast)
-                << diag::CastKind::CastFrom << SubExpr->getType();
+                << diag::ConstexprInvalidCastKind::CastFrom
+                << SubExpr->getType();
         } else
           CCEDiag(E, diag::note_constexpr_invalid_cast)
-              << diag::CastKind::ThisCastOrReinterpret
+              << diag::ConstexprInvalidCastKind::ThisCastOrReinterpret
               << Info.Ctx.getLangOpts().CPlusPlus;
         Result.Designator.setInvalid();
       }
@@ -9715,7 +9717,7 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
 
   case CK_IntegralToPointer: {
     CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << diag::CastKind::ThisCastOrReinterpret
+        << diag::ConstexprInvalidCastKind::ThisCastOrReinterpret
         << Info.Ctx.getLangOpts().CPlusPlus;
 
     APValue Value;
@@ -11181,7 +11183,7 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
       // Give up if the input isn't an int, float, or vector.  For example, we
       // reject "(v4i16)(intptr_t)&a".
       Info.FFDiag(E, diag::note_constexpr_invalid_cast)
-          << diag::CastKind::ThisCastOrReinterpret
+          << diag::ConstexprInvalidCastKind::ThisCastOrReinterpret
           << Info.Ctx.getLangOpts().CPlusPlus;
       return false;
     }
@@ -15201,7 +15203,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
 
   case CK_PointerToIntegral: {
     CCEDiag(E, diag::note_constexpr_invalid_cast)
-        << diag::CastKind::ThisCastOrReinterpret
+        << diag::ConstexprInvalidCastKind::ThisCastOrReinterpret
         << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
 
     LValue LV;

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to