[PATCH] D54902: [AST][Sema] Remove CallExpr::setNumArgs

Bruno Ricci via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 26 08:15:30 PST 2018


riccibruno created this revision.
riccibruno added reviewers: rsmith, aaron.ballman.
riccibruno added a project: clang.
Herald added subscribers: cfe-commits, dexonsmith, mehdi_amini.

`CallExpr::setNumArgs` is the only thing that prevents storing the arguments
in a trailing array. There is only 3 places in `Sema` where `setNumArgs` is called.
D54900 <https://reviews.llvm.org/D54900> dealt with one of them.

This patch remove the other two calls to `setNumArgs` in `ConvertArgumentsForCall`.
To do this we do the following changes:

1.) Replace the first call to `setNumArgs` by an assertion since we are moving the responsability
to allocate enough space for the arguments from `Sema::ConvertArgumentsForCall`
to its callers. (which are `Sema::BuildCallToMemberFunction`, and `Sema::BuildResolvedCallExpr`)

2.) Add a new member function `CallExpr::shrinkNumArgs`, which can only be used
to drop arguments and then replace the second call to `setNumArgs` by `shrinkNumArgs`.

3.) Add a new defaulted parameter `MinNumArgs` to `CallExpr` and its derived classes,
which specifies a minimum number of argument slots to allocate. The actual number of
arguments slots allocated will be `max(number of args, MinNumArgs)`, with the extra
args nulled. Note that after the creation of the call expression all of the arguments will
be non-null. It is just during the creation of the call expression that some of the
last arguments can be temporarily null, until filled by default arguments.

4.) Update `Sema::BuildCallToMemberFunction` by passing the number of parameters
in the function prototype to the constructor of `CXXMemberCallExpr`.
Here the change is pretty straightforward.

5.) Update `Sema::BuildResolvedCallExpr`. Here the change is more complicated since
the type-checking for the function type was done after the creation of the call expression.
We need to move this before the creation of the call expression, and then pass the number
of parameters in the function prototype (if any) to the constructor of the call expression.

6.) Update the deserialization of `CallExpr` and its derived classes.


Repository:
  rC Clang

https://reviews.llvm.org/D54902

Files:
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  lib/AST/Expr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderStmt.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54902.175261.patch
Type: text/x-patch
Size: 19993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181126/26b0d269/attachment-0001.bin>


More information about the cfe-commits mailing list