[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)
Mital Ashok via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 12 14:18:54 PDT 2024
================
@@ -17160,3 +17184,72 @@ bool Expr::tryEvaluateStrLen(uint64_t &Result, ASTContext &Ctx) const {
EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantFold);
return EvaluateBuiltinStrLen(this, Result, Info);
}
+
+namespace {
+struct IsWithinLifetimeHandler {
+ EvalInfo &Info;
+ static constexpr AccessKinds AccessKind = AccessKinds::AK_IsWithinLifetime;
+ using result_type = std::optional<bool>;
+ std::optional<bool> failed() { return std::nullopt; }
+ template <typename T>
+ std::optional<bool> found(T &Subobj, QualType SubobjType) {
+ return true;
+ }
+};
+
+std::optional<bool> EvaluateBuiltinIsWithinLifetime(IntExprEvaluator &IEE,
+ const CallExpr *E) {
+ EvalInfo &Info = IEE.Info;
+ // assert(Info.InConstantContext && "Call to consteval builtin not in constant
+ // context?");
+ assert(E->getBuiltinCallee() == Builtin::BI__builtin_is_within_lifetime);
----------------
MitalAshok wrote:
It was being called from here: https://github.com/llvm/llvm-project/blob/b368404dee8c341dc022a9e9a868f5a268e92033/clang/lib/Sema/SemaChecking.cpp#L12702
I've now made it so it explicitly does not work in those sorts of cases
https://github.com/llvm/llvm-project/pull/91895
More information about the cfe-commits
mailing list