This is an archive of the discontinued LLVM Phabricator instance.

Restore isa<Ty>(X) asserts inside cast<Ty>(X)
ClosedPublic

Authored by reames on Jun 7 2022, 10:32 AM.

Details

Summary

PLEASE DO NOT REVERT without careful consideration, and preferably prior discussion.

cast<Ty>(X) is a "checked cast". Its entire purpose is explicitly documented (https://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates) as catching bad casts by asserting that the cast is valid. Unfortunately, in a recent rewrite of our casting infrastructure about three months back, these asserts got dropped.

This is discussed in more detail on discourse in https://discourse.llvm.org/t/cast-x-is-broken-implications-and-proposal-to-address/63033.

Diff Detail

Event Timeline

reames created this revision.Jun 7 2022, 10:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 10:32 AM
reames requested review of this revision.Jun 7 2022, 10:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 10:32 AM
reames edited the summary of this revision. (Show Details)Jun 7 2022, 10:59 AM
rriddle accepted this revision.Jun 7 2022, 11:12 AM
rriddle added a subscriber: rriddle.

Really appreciate catching this and raising the discussion! (Approval for whenever you need/want to land)

This revision is now accepted and ready to land.Jun 7 2022, 11:12 AM

Is it possible to create simple testcase?

craig.topper added inline comments.
llvm/include/llvm/Support/Casting.h
578

It doesn't look like there is an implementation of isa that takes From *. It fails to compile on a Casting unittest.

craig.topper added inline comments.Jun 7 2022, 12:38 PM
llvm/include/llvm/Support/Casting.h
578
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]’:
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]’
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*]’
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*]’
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]’
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]’
llvm/include/llvm/Support/Casting.h:556:46:   required from ‘bool llvm::isa(const From&) [with To = llvm::bar*; From = llvm::bar*]’
llvm/include/llvm/Support/Casting.h:585:3:   required from ‘decltype(auto) llvm::cast(From*) [with To = llvm::bar*; From = llvm::bar]’
llvm/unittests/Support/Casting.cpp:181:27:   required from here
llvm/include/llvm/Support/Casting.h:64:64: error: ‘classof’ is not a member of ‘llvm::bar*’
   static inline bool doit(const From &Val) { return To::classof(&Val); }
craig.topper added inline comments.Jun 7 2022, 12:48 PM
llvm/include/llvm/Support/Casting.h
578

Nevermind. I think this is fixed by the reverting of 0809f63826d36c89574d6ac056ebf46a4b6f29ff that you mentioned in your email.

reames added inline comments.Jun 7 2022, 12:52 PM
llvm/include/llvm/Support/Casting.h
578

Yep, exactly. I just pushed that as 781de11f.

This got slightly delayed from when I'd expected as my build infrastructure went down for a bit. We should now be fully clean build (if not test) on ToT.

MaskRay accepted this revision.Jun 7 2022, 11:57 PM
MaskRay added a subscriber: MaskRay.

-DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;flang;lldb;lld;compiler-rt;openmp;mlir;polly;cross-project-tests seems fine.

bzcheeseman accepted this revision.Jun 8 2022, 12:43 AM
This revision was landed with ongoing or failed builds.Jun 8 2022, 7:32 AM
This revision was automatically updated to reflect the committed changes.

Maybe we can introduce an LLVM_ASSERT that supports severity levels and plays nice with GTEST?