This is an archive of the discontinued LLVM Phabricator instance.

[AST][Sema] Remove CallExpr::setNumArgs
ClosedPublic

Authored by riccibruno on Nov 26 2018, 8:14 AM.

Details

Summary

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 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.

Diff Detail

Repository
rL LLVM

Event Timeline

riccibruno created this revision.Nov 26 2018, 8:14 AM
aaron.ballman added inline comments.Nov 26 2018, 1:05 PM
include/clang/AST/ExprCXX.h
168 ↗(On Diff #175261)

Since you're already touching the line, can you correct the names fn, args, and t to match our naming conventions?

212 ↗(On Diff #175261)

Same here.

lib/AST/Expr.cpp
1272 ↗(On Diff #175261)

If you want to fix these up as well, feel free.

lib/Sema/SemaExpr.cpp
5565 ↗(On Diff #175261)

typechecking -> type checking

5594 ↗(On Diff #175261)

parameter -> parameters

5607 ↗(On Diff #175261)

Why did this go away?

lib/Sema/SemaOverload.cpp
12990 ↗(On Diff #175261)

You can use const auto * here.

riccibruno marked 9 inline comments as done.

style fixes

added inline comments

include/clang/AST/ExprCXX.h
168 ↗(On Diff #175261)

I was going to submit an NFC cleaning up all of CallExpr +
the classes deriving from it in one go (capitalization style,
clang-format, and so on).

I would prefer to avoid mixing style fixes in existing code
and functional changes.

lib/Sema/SemaExpr.cpp
5607 ↗(On Diff #175261)

Because it is now set by the constructor of CallExpr or
CUDAKernelCallExpr. The call to setCallee was needed
before because the call expression was constructed before
this piece of code, but now we can just pass Fn to the
constructor.

aaron.ballman accepted this revision.Nov 27 2018, 5:22 AM

LGTM aside from two small NFC nits.

include/clang/AST/ExprCXX.h
168 ↗(On Diff #175261)

That's fine by me, thanks!

lib/Sema/SemaExpr.cpp
5625 ↗(On Diff #175434)

typechecking -> type checking

5607 ↗(On Diff #175261)

Thank you for the explanation, that makes sense to me.

lib/Serialization/ASTReaderStmt.cpp
2499 ↗(On Diff #175434)

I would drop the + 0 from all of these; they look a bit like a typo from a casual reading of the code.

This revision is now accepted and ready to land.Nov 27 2018, 5:22 AM
This revision was automatically updated to reflect the committed changes.