[PATCH] D127231: Restore isa<Ty>(X) asserts inside cast<Ty>(X)
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 7 10:32:23 PDT 2022
reames created this revision.
reames added reviewers: nikic, fhahn, lattner, bzcheeseman.
Herald added subscribers: bollu, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added a project: LLVM.
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.
There will shortly be a discourse post to "llvm-dev" describing the current situation in tree and the plan to address.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127231
Files:
llvm/include/llvm/Support/Casting.h
Index: llvm/include/llvm/Support/Casting.h
===================================================================
--- llvm/include/llvm/Support/Casting.h
+++ llvm/include/llvm/Support/Casting.h
@@ -570,21 +570,25 @@
template <typename To, typename From>
LLVM_NODISCARD inline decltype(auto) cast(const From &Val) {
+ assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
return CastInfo<To, const From>::doCast(Val);
}
template <typename To, typename From>
LLVM_NODISCARD inline decltype(auto) cast(From &Val) {
+ assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
return CastInfo<To, From>::doCast(Val);
}
template <typename To, typename From>
LLVM_NODISCARD inline decltype(auto) cast(From *Val) {
+ assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
return CastInfo<To, From *>::doCast(Val);
}
template <typename To, typename From>
LLVM_NODISCARD inline decltype(auto) cast(std::unique_ptr<From> &&Val) {
+ assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
return CastInfo<To, std::unique_ptr<From>>::doCast(std::move(Val));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127231.434876.patch
Type: text/x-patch
Size: 1135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220607/42296ea8/attachment.bin>
More information about the llvm-commits
mailing list