This is an archive of the discontinued LLVM Phabricator instance.

Fix a codegen bug for variadic functions with pass_object_size params
ClosedPublic

Authored by george.burgess.iv on Feb 19 2016, 12:59 PM.

Details

Summary

Currently, we get assertion failures/segfaults for variadic functions with pass_object_size params, e.g.:

void foo(void *const __attribute__((pass_object_size(0))) a, ...) {}

This is because we didn't consider the parameter injected by pass_object_size "required" when generating the CGFunctionInfo for foo. This patch teaches clang that said injected params are required.

(N.B. Only one user of appendParameterTypes is patched here because the other user, arrangeCXXStructorDeclaration, considers all args to be required).

Diff Detail

Repository
rL LLVM

Event Timeline

george.burgess.iv retitled this revision from to Fix a codegen bug for variadic functions with pass_object_size params.
george.burgess.iv updated this object.
george.burgess.iv added a reviewer: rsmith.
rsmith added inline comments.Mar 22 2016, 3:09 PM
lib/CodeGen/CGCall.cpp
142–143 ↗(On Diff #48538)

Would it make sense for RequiredArgs::forPrototypePlus to do this computation? Are the other callers of that function also getting the wrong number of required arguments in this case?

george.burgess.iv marked an inline comment as done.

Addressed all feedback

lib/CodeGen/CGCall.cpp
142–143 ↗(On Diff #48538)

...There was a reason I didn't do that. I don't remember what it was, so either it disappeared, or I was just being dumb, but there was a reason. Either way, I moved this logic into RequiredArgs, and ended up fixing a few more bugs in the process. Yay for (fixing) bugs!

rsmith added inline comments.Jun 16 2016, 12:30 PM
lib/CodeGen/CGExprCXX.cpp
57–58 ↗(On Diff #51374)

Comment doesn't seem to match the code; Args.size() here includes only the 'this' pointer and the possible destructor VTT parameter. Delete comment?

331 ↗(On Diff #51374)

Seems inconsistent to pass E->getDirectCallee() here but not above. Since you can't take the address of a pass_object_size function, do we need to pass the callee in either place?

george.burgess.iv marked 2 inline comments as done.

Addressed all feedback.

lib/CodeGen/CGExprCXX.cpp
331 ↗(On Diff #51374)

Good point. :)

rsmith accepted this revision.Jun 16 2016, 3:31 PM
rsmith edited edge metadata.
This revision is now accepted and ready to land.Jun 16 2016, 3:31 PM
This revision was automatically updated to reflect the committed changes.