[clang] [libcxx] [Clang] Add __builtin_invoke and use it in libc++ (PR #116709)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 25 10:43:55 PDT 2025


================
@@ -2224,6 +2224,99 @@ static bool BuiltinCountZeroBitsGeneric(Sema &S, CallExpr *TheCall) {
   return false;
 }
 
+static ExprResult BuiltinInvoke(Sema &S, CallExpr *TheCall) {
+  SourceLocation Loc = TheCall->getBeginLoc();
+  MutableArrayRef Args(TheCall->getArgs(), TheCall->getNumArgs());
+  assert(llvm::none_of(Args, [](Expr *Arg) { return Arg->isTypeDependent(); }));
+
+  if (Args.size() == 0) {
+    S.Diag(TheCall->getBeginLoc(),
+           diag::err_typecheck_call_too_few_args_at_least)
+        << /*callee_type=*/0 << /*min_arg_count=*/1 << /*actual_arg_count=*/0
+        << /*is_non_object=*/0 << TheCall->getSourceRange();
+    return ExprError();
+  }
+
+  QualType FuncT = Args[0]->getType();
+
+  if (const auto *MPT = FuncT->getAs<MemberPointerType>()) {
+    if (Args.size() < 2) {
----------------
AaronBallman wrote:

We should have a test case for a member pointer to a function with an explicit object parameter. I believe this logic all still works, but the coverage would be good to have.

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


More information about the cfe-commits mailing list