[clang] 8ce6896 - [Sema] Add missing entries to the arrays in GetImplicitConversionName and GetConversionRank.

Craig Topper via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 28 11:17:20 PST 2023


Author: Craig Topper
Date: 2023-02-28T11:16:45-08:00
New Revision: 8ce68969b90288a3dc75c5c15283fc11f97b278a

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

LOG: [Sema] Add missing entries to the arrays in GetImplicitConversionName and GetConversionRank.

It appears that ICK_Zero_Queue_Conversion was inserted into the ICK
enum without updating this table. Easy to do since the table size
was set to ICK_Num_Conversion_Kinds.

I've used ICR_Exact_Match to match what was previously done for
ICK_Zero_Event_Conversion that last time someone noticed this had happened.

To prevent this from happening again, I've removed the explicit size
and used a static_assert to check the size against ICK_Num_Conversion_Kinds.

Differential Revision: https://reviews.llvm.org/D144990

Added: 
    

Modified: 
    clang/lib/Sema/SemaOverload.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 80b414c369777..3f1bb3f571222 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -120,7 +120,7 @@ CompareDerivedToBaseConversions(Sema &S, SourceLocation Loc,
 /// corresponding to the given implicit conversion kind.
 ImplicitConversionRank clang::GetConversionRank(ImplicitConversionKind Kind) {
   static const ImplicitConversionRank
-    Rank[(int)ICK_Num_Conversion_Kinds] = {
+    Rank[] = {
     ICR_Exact_Match,
     ICR_Exact_Match,
     ICR_Exact_Match,
@@ -149,16 +149,20 @@ ImplicitConversionRank clang::GetConversionRank(ImplicitConversionKind Kind) {
     ICR_Exact_Match, // NOTE(gbiv): This may not be completely right --
                      // it was omitted by the patch that added
                      // ICK_Zero_Event_Conversion
+    ICR_Exact_Match, // NOTE(ctopper): This may not be completely right --
+                     // it was omitted by the patch that added
+                     // ICK_Zero_Queue_Conversion
     ICR_C_Conversion,
     ICR_C_Conversion_Extension
   };
+  static_assert(std::size(Rank) == (int)ICK_Num_Conversion_Kinds);
   return Rank[(int)Kind];
 }
 
 /// GetImplicitConversionName - Return the name of this kind of
 /// implicit conversion.
 static const char* GetImplicitConversionName(ImplicitConversionKind Kind) {
-  static const char* const Name[(int)ICK_Num_Conversion_Kinds] = {
+  static const char* const Name[] = {
     "No conversion",
     "Lvalue-to-rvalue",
     "Array-to-pointer",
@@ -185,9 +189,11 @@ static const char* GetImplicitConversionName(ImplicitConversionKind Kind) {
     "Transparent Union Conversion",
     "Writeback conversion",
     "OpenCL Zero Event Conversion",
+    "OpenCL Zero Queue Conversion",
     "C specific type conversion",
     "Incompatible pointer conversion"
   };
+  static_assert(std::size(Name) == (int)ICK_Num_Conversion_Kinds);
   return Name[Kind];
 }
 


        


More information about the cfe-commits mailing list