[llvm] 781de11 - Revert "[LLVM][Casting.h] Add trivial self-cast"

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 7 12:50:56 PDT 2022


Author: Philip Reames
Date: 2022-06-07T12:50:40-07:00
New Revision: 781de11f42a863f0328cdc6889f6fd48787ddd72

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

LOG: Revert "[LLVM][Casting.h] Add trivial self-cast"

This reverts commit 0809f63826d36c89574d6ac056ebf46a4b6f29ff.  The patch appears not to have included corresponding isa<Ty> support.

This was revealed when reintroducing the required isa<Ty> asserts in cast<Ty>.  See https://discourse.llvm.org/t/cast-x-is-broken-implications-and-proposal-to-address/63033 for context.

Here's the template instantiation error:
In file included from /home/preames/llvm-repo/llvm-project/llvm/unittests/Support/Casting.cpp:9:
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h: In instantiation of ‘static bool llvm::isa_impl<To, From, Enabler>::doit(const From&) [with To = llvm::bar*; From = llvm::bar; Enabler = void]’:
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:110:36:   required from ‘static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::bar*; From = llvm::bar]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:137:41:   required from ‘static bool llvm::isa_impl_wrap<To, FromTy, FromTy>::doit(const FromTy&) [with To = llvm::bar*; FromTy = const llvm::bar*]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:129:13:   required from ‘static bool llvm::isa_impl_wrap<To, From, SimpleFrom>::doit(const From&) [with To = llvm::bar*; From = const llvm::bar* const; SimpleFrom = const llvm::bar*]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:263:62:   required from ‘static bool llvm::CastIsPossible<To, From, Enable>::isPossible(const From&) [with To = llvm::bar*; From = const llvm::bar*; Enable = void]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:517:38:   required from ‘static bool llvm::CastInfo<To, From, typename std::enable_if<(! llvm::is_simple_type<From>::value), void>::type>::isPossible(From&) [with To = llvm::bar*; From = llvm::bar* const]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:556:46:   required from ‘bool llvm::isa(const From&) [with To = llvm::bar*; From = llvm::bar*]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:585:3:   required from ‘decltype(auto) llvm::cast(From*) [with To = llvm::bar*; From = llvm::bar]’
/home/preames/llvm-repo/llvm-project/llvm/unittests/Support/Casting.cpp:181:27:   required from here
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:64:64: error: ‘classof’ is not a member of ‘llvm::bar*’
   64 |   static inline bool doit(const From &Val) { return To::classof(&Val); }

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index 4f2f64e865332..37f85da868b2d 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -192,12 +192,6 @@ template <class To, class From> struct cast_retty {
       To, From, typename simplify_type<From>::SimpleType>::ret_type;
 };
 
-template <class T> struct cast_retty<T, T> {
-  // Casting T to itself, but have to use a ref if so we don't get a copy if
-  // it's not a pointer.
-  using ret_type = std::conditional_t<std::is_pointer<T>::value, T, T &>;
-};
-
 //===----------------------------------------------------------------------===//
 // cast_convert_val
 //===----------------------------------------------------------------------===//
@@ -282,8 +276,7 @@ struct CastIsPossible<To, Optional<From>> {
 /// always be possible.
 template <typename To, typename From>
 struct CastIsPossible<To, From,
-                      std::enable_if_t<std::is_same<To, From>::value ||
-                                       std::is_base_of<To, From>::value>> {
+                      std::enable_if_t<std::is_base_of<To, From>::value>> {
   static inline bool isPossible(const From &f) { return true; }
 };
 

diff  --git a/llvm/unittests/Support/Casting.cpp b/llvm/unittests/Support/Casting.cpp
index 925e9eed47d40..086548f1e2128 100644
--- a/llvm/unittests/Support/Casting.cpp
+++ b/llvm/unittests/Support/Casting.cpp
@@ -144,7 +144,6 @@ extern const bar *B2;
 // test various configurations of const
 const bar &B3 = B1;
 const bar *const B4 = B2;
-bar *B5 = &B;
 
 TEST(CastingTest, isa) {
   EXPECT_TRUE(isa<foo>(B1));
@@ -176,17 +175,6 @@ TEST(CastingTest, cast) {
   foo *F8 = B1.baz();
   EXPECT_NE(F8, null_foo);
 
-  // Ensure cast-to-self works (with the type in the template verbatim
-  // equivalent to the type in the input).
-  auto B9 = cast<bar *>(B5);
-  static_assert(std::is_same<bar *, decltype(B9)>::value,
-                "Inccorrect return type!");
-  EXPECT_EQ(B9, B5);
-  auto B10 = cast<const bar *>(B2);
-  static_assert(std::is_same<const bar *, decltype(B10)>::value,
-                "Inccorrect return type!");
-  EXPECT_EQ(B10, B2);
-
   std::unique_ptr<const bar> BP(B2);
   auto FP = cast<foo>(std::move(BP));
   static_assert(std::is_same<std::unique_ptr<const foo>, decltype(FP)>::value,
@@ -224,17 +212,6 @@ TEST(CastingTest, dyn_cast) {
   // EXPECT_EQ(F4, null_foo);
   foo *F5 = B1.daz();
   EXPECT_NE(F5, null_foo);
-
-  // Ensure cast-to-self works (with the type in the template verbatim
-  // equivalent to the type in the input).
-  auto B9 = dyn_cast<bar *>(B5);
-  static_assert(std::is_same<bar *, decltype(B9)>::value,
-                "Inccorrect return type!");
-  EXPECT_EQ(B9, B5);
-  auto B10 = dyn_cast<const bar *>(B2);
-  static_assert(std::is_same<const bar *, decltype(B10)>::value,
-                "Inccorrect return type!");
-  EXPECT_EQ(B10, B2);
 }
 
 // All these tests forward to dyn_cast_if_present, so they also provde an


        


More information about the llvm-commits mailing list