[llvm-branch-commits] [clang] [llvm] [ConstantTime][Clang] Add __builtin_ct_select for constant-time selection (PR #166703)

Julius Alexandre via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Jul 19 20:07:05 PDT 2026


================
@@ -3845,6 +3845,70 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
     if (BuiltinCountedByRef(TheCall))
       return ExprError();
     break;
+
+  case Builtin::BI__builtin_ct_select: {
+    if (TheCall->getNumArgs() != 3) {
+      // Simple argument count check without complex diagnostics
+      if (TheCall->getNumArgs() < 3) {
+        return Diag(TheCall->getEndLoc(),
+                    diag::err_typecheck_call_too_few_args_at_least)
+               << 0 << 3 << TheCall->getNumArgs() << 0
+               << TheCall->getCallee()->getSourceRange();
+      } else {
+        return Diag(TheCall->getEndLoc(),
+                    diag::err_typecheck_call_too_many_args)
+               << 0 << 3 << TheCall->getNumArgs() << 0
+               << TheCall->getCallee()->getSourceRange();
+      }
+    }
+    auto *Cond = TheCall->getArg(0);
+    auto *A = TheCall->getArg(1);
+    auto *B = TheCall->getArg(2);
+
+    QualType CondTy = Cond->getType();
+    if (!CondTy->isIntegerType()) {
+      return Diag(Cond->getBeginLoc(), diag::err_typecheck_cond_expect_scalar)
----------------
wizardengineer wrote:

This is covered by test_noninteger_cond in clang/test/Sema/builtin-ct-select.c. It passes a non-integer condition and checks for the "arithmetic or pointer type is required" error.

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


More information about the llvm-branch-commits mailing list