diff options
author | Vlad Serebrennikov <serebrennikov.vladislav@gmail.com> | 2024-08-21 17:38:24 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-21 17:38:24 +0400 |
commit | 281d17840c35a1d80303bb6170c253fe2411f95f (patch) | |
tree | a316c63fc94648d4cdd993bfeb04fdbbf244cebb /clang/lib/Parse/ParseDecl.cpp | |
parent | 76c07984257b49dcc4786fa9fb3918a2c1342e23 (diff) | |
download | llvm-281d17840c35a1d80303bb6170c253fe2411f95f.zip llvm-281d17840c35a1d80303bb6170c253fe2411f95f.tar.gz llvm-281d17840c35a1d80303bb6170c253fe2411f95f.tar.bz2 |
[clang] Diagnose functions with too many parameters (#104833)
This patch adds a parser check when a function declaration or function
type declaration (in a function pointer declaration, for example) has
too many parameters for `FunctionTypeBits::NumParams` to hold. At the
moment of writing it's a 16-bit-wide bit-field, limiting the number of
parameters at 65536.
The check is added in the parser loop that goes over comma-separated
list of function parameters. This is not the solution Aaron suggested in
https://github.com/llvm/llvm-project/issues/35741#issuecomment-1638086571,
because it was found out that it's quite hard to recover from this
particular error in `GetFullTypeForDeclarator()`. Multiple options were
tried, but all of them led to crashes down the line.
I used LLVM Compile Time Tracker to ensure this does not introduce a
performance regression. I believe changes are in the noise:
https://llvm-compile-time-tracker.com/compare.php?from=de5ea2d122c31e1551654ff506c33df299f351b8&to=424818620766cedb2770e076ee359afeb0cc14ec&stat=instructions:u
Fixes #35741
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a8a9d3f..ed5d6ce 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -8025,6 +8025,17 @@ void Parser::ParseParameterDeclarationClause( // Consume the keyword. ConsumeToken(); } + + // We can only store so many parameters + // Skip until the the end of the parameter list, ignoring + // parameters that would overflow. + if (ParamInfo.size() == Type::FunctionTypeNumParamsLimit) { + Diag(ParmDeclarator.getBeginLoc(), + diag::err_function_parameter_limit_exceeded); + SkipUntil(tok::r_paren, SkipUntilFlags::StopBeforeMatch); + break; + } + // Inform the actions module about the parameter declarator, so it gets // added to the current scope. Decl *Param = |