This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Fix a regression introduced in "[AST][Sema] Remove CallExpr::setNumArgs"
ClosedPublic

Authored by riccibruno on Feb 8 2019, 5:58 AM.

Details

Summary

D54902 removed CallExpr::setNumArgs in preparation of tail-allocating the arguments of CallExpr. It did this by allocating storage for max(number of arguments, number of parameters in the prototype). The temporarily nulled arguments however causes issues in BuildResolvedCallExpr when typo correction is done just after the creation of the call expression.

This was unfortunately missed by the tests /:

To fix this, delay setting the number of arguments to max(number of arguments, number of parameters in the prototype) until we are ready for it. It would be nice to have this encapsulated in CallExpr but this is the best I can come up with under the constraint that we cannot add anything the CallExpr.

Fixes PR40286. This should probably be cherry-picked into the release branch.

Diff Detail

Repository
rC Clang

Event Timeline

riccibruno created this revision.Feb 8 2019, 5:58 AM
aaron.ballman added inline comments.Feb 11 2019, 5:36 AM
lib/AST/Expr.cpp
1272–1274 ↗(On Diff #185954)

Could use std::fill() here to remove the for-loop. Your call whether that looks cleaner or not.

lib/Sema/SemaExpr.cpp
5813

case rebuild -> case, rebuild

lib/Sema/SemaOverload.cpp
12909–12910 ↗(On Diff #185954)

Oye. When we had to call this hack in one place, I could hold my nose, but having to call it randomly any time something like a call expression is created is a bit too much for me.

How awful is the alternative fix, such as making things resilient to null parameters in BuildResolvedCallExpr()?

Rewrote the patch to make it local to BuildResolvedCallExpr. It is still a hack though.

riccibruno marked an inline comment as done.Feb 12 2019, 6:17 AM
This revision is now accepted and ready to land.Feb 12 2019, 1:20 PM
This revision was automatically updated to reflect the committed changes.

(Following up on a discussion on IRC) I have looked at what would be needed to revert the set of patches which introduced this change, but this results in a >1k lines diff which do not apply cleanly. I think it might be safer to just merge this fix. Unless @aaron.ballman disagree, @hans could you please merge this into the release branch ?

(Following up on a discussion on IRC) I have looked at what would be needed to revert the set of patches which introduced this change, but this results in a >1k lines diff which do not apply cleanly. I think it might be safer to just merge this fix. Unless @aaron.ballman disagree, @hans could you please merge this into the release branch ?

Thank you for looking into the 8.0 revert approach, @riccibruno! I'm okay with putting this patch on 8.0 instead -- you should file a new bug, mark it as blocking https://bugs.llvm.org/show_bug.cgi?id=40331, and make sure @hansw is CCed on the bug.

hans removed a subscriber: hansw.Feb 18 2019, 2:05 AM

Done, thanks!

That was https://bugs.llvm.org/show_bug.cgi?id=40742 and it's now been merged.