[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 20 06:46:07 PDT 2024


================
@@ -1844,6 +1844,44 @@ static ExprResult BuiltinLaunder(Sema &S, CallExpr *TheCall) {
   return TheCall;
 }
 
+static ExprResult BuiltinIsWithinLifetime(Sema &S, CallExpr *TheCall) {
+  if (S.checkArgCount(TheCall, 1))
+    return ExprError();
+
+  ExprResult Arg = S.DefaultFunctionArrayLvalueConversion(TheCall->getArg(0));
+  if (Arg.isInvalid())
+    return ExprError();
+  QualType ParamTy = Arg.get()->getType();
+  TheCall->setArg(0, Arg.get());
+  TheCall->setType(S.Context.BoolTy);
+
+  // This function should only be called through `std::is_within_lifetime`,
+  // which requires a pointer type
----------------
cor3ntin wrote:

Not sure this comment make sense, the built in expect a pointer regardless of how it's called

https://github.com/llvm/llvm-project/pull/91895


More information about the cfe-commits mailing list