[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 05:45:15 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:
```suggestion
// Reject calls with more args than the builtin's declared prototype.
```
What makes me uncomfortable about this is that, in general, custom type checking means you cannot count on anything in the signature being valid. So there are a lot of builtins which do things like:
```
def IsGreater : Builtin {
let Spellings = ["__builtin_isgreater"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
CustomTypeChecking, Constexpr];
let Prototype = "int(...)";
}
```
where the prototype is purely variadic. I checked the specific builtins you're using this for and PPC doesn't seem to use this convention and so the changes are correct. But I worry for folks adding new builtins later which follow the pattern used outside of the PPC builtins.
However, it also seems like these builtins don't necessarily require custom type checking to begin with. `BI__builtin_ppc_national2packed`, `BI__builtin_ppc_packed2zoned`, `BI__builtin_ppc_zoned2packed` don't do any type checking of their args that I can see, and the other ones do some type checking but it seems like the kind of type checking that can be done by encoding the information in the prototype (possibly by extending the builtin logic for what types can be expressed).
Would it be viable to disable custom type checking for these builtins instead?
https://github.com/llvm/llvm-project/pull/222841
More information about the cfe-commits
mailing list