[clang] [Sema] Check arg count for builtins with CustomTypeChecking (PR #222841)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 11 11:49:47 PDT 2026


================
@@ -145,6 +145,16 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
   //  - IsIntType: enforces any integer type
   // Lambdas centralize type checks for BCD builtin handlers
 
+  // reject calls with more args than the builtin's declared prototype
----------------
AaronBallman wrote:

>>    https://godbolt.org/z/K5Pz83nsW why is this an error about an undeclared identifier vector?
> this one seems like unrelated to the issue (sorry if i am missing anything here)

Unrelated to this PR, mostly caught me by surprise. I would have expected that to say that `vector` cannot be used with the type instead of `vector` being an unknown identifier entirely. But it was in service of "are we actually doing the custom type checking at all?"

> soo this is breaking the CI.. okay what if we Restore "t" in BuiltinsPPC.def for the 7 BCD builtins and add a CheckArgCountAtMost guard inside SemaPPC.cpp that reads param count from GetBuiltinType. then add the missing type checks for national2packed/packed2zoned/zoned2packed (Arg0 must be vector unsigned char) and Keep the existing immediate-range checks (BuiltinConstantArgRange).. should this approach be good ?

I'd like to better understand what's failing. I spot checked a failure and it looks like we're breaking assumptions in CodeGen:
```
...
   # | #14 0x0000000008621827 dyn_cast<llvm::VectorType, llvm::Type> /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/Support/Casting.h:656:3
  # | #15 0x0000000008621827 (anonymous namespace)::FoldBitCast(llvm::Constant*, llvm::Type*, llvm::DataLayout const&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp:0:0
  # | #16 0x0000000006824bf6 llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::MDNode*, llvm::FMFSource) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/IR/IRBuilder.h:2297:16
  # | #17 0x0000000009f27338 clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(clang::GlobalDecl, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGBuiltin.cpp:0:0
  # | #18 0x0000000009d05ada clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGExpr.cpp:6531:5
  # | #19 0x0000000009d2748e isScalar /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGValue.h:64:41
  # | #20 0x0000000009d2748e getScalarVal /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGValue.h:73:12
  # | #21 0x0000000009d2748e (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:687:36
  # | #22 0x0000000009d2fa6f Visit /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:496:52
  # | #23 0x0000000009d2fa6f (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:2663:18
  # | #24 0x0000000009d12d4d Visit /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:496:52
  # | #25 0x0000000009d12d4d clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:6244:8
  # | #26 0x0000000009c6c5b3 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CodeGen/CGStmt.cpp:1698:26
...
```
but what assumptions are being violated and why? 

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


More information about the cfe-commits mailing list