[llvm] bc65fc8 - [LLVM][Casting.h] Remove CastInfo pointer partial specialization.

via llvm-commits llvm-commits at lists.llvm.org
Fri May 13 15:31:16 PDT 2022


Author: bzcheeseman
Date: 2022-05-13T18:31:10-04:00
New Revision: bc65fc8bb31452107583d683a3da4b171440715c

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

LOG: [LLVM][Casting.h] Remove CastInfo pointer partial specialization.

Since cast_convert_val now has pointer specializations, we don't need the pointer partial specialization for CastInfo. We want to trim these down when possible to avoid future ambiguous partial specialization errors.

Reviewed By: rriddle

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

Added: 
    

Modified: 
    llvm/include/llvm/Support/Casting.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index 5e87495135d1..da511e94dc98 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -456,47 +456,18 @@ struct CastInfo : public CastIsPossible<To, From> {
 
   using CastReturnType = typename cast_retty<To, From>::ret_type;
 
-  static inline CastReturnType doCast(From &f) {
-    return cast_convert_val<To, From,
-                            typename simplify_type<From>::SimpleType>::doit(f);
+  static inline CastReturnType doCast(const From &f) {
+    return cast_convert_val<
+        To, From,
+        typename simplify_type<From>::SimpleType>::doit(const_cast<From &>(f));
   }
 
   // This assumes that you can construct the cast return type from `nullptr`.
   // This is largely to support legacy use cases - if you don't want this
   // behavior you should specialize CastInfo for your use case.
-  //
-  // FIXME: fix legacy use cases to specialize CastInfo so we can remove these
-  //        two - they don't really belong here, as it doesn't make sense to
-  //        have a fallible reference-to-reference cast if the type isn't
-  //        constructible from nullptr, which doesn't really happen in LLVM
-  //        outside of MLIR (which is a separate use case in itself).
   static inline CastReturnType castFailed() { return CastReturnType(nullptr); }
 
-  static inline CastReturnType doCastIfPossible(From &f) {
-    if (!Self::isPossible(f))
-      return castFailed();
-    return doCast(f);
-  }
-};
-
-/// Provides a CastInfo partial specialization for pointers. This version *does*
-/// provide castFailed and doCastIfPossible because for pointers, a fallible
-/// cast is trivial - just return nullptr.
-template <typename To, typename From>
-struct CastInfo<To, From *, std::enable_if_t<is_simple_type<From>::value>>
-    : public CastIsPossible<To, From *> {
-  using Self = CastInfo<To, From *>;
-
-  using CastReturnType = typename cast_retty<To, From *>::ret_type;
-
-  static inline CastReturnType doCast(From *f) {
-    // We know it is a simple type, so we can just do cast_convert_val.
-    return cast_convert_val<To, From *, From *>::doit(f);
-  }
-
-  static inline CastReturnType castFailed() { return CastReturnType(nullptr); }
-
-  static inline CastReturnType doCastIfPossible(From *f) {
+  static inline CastReturnType doCastIfPossible(const From &f) {
     if (!Self::isPossible(f))
       return castFailed();
     return doCast(f);


        


More information about the llvm-commits mailing list