Page MenuHomePhabricator

[Sema] Fix Sema checkArgCount function
Needs ReviewPublic

Authored by bsaleil on Feb 5 2020, 1:39 PM.

Details

Summary

This patch fixes the checkArgCount function in Sema that is used to check the number of arguments of a call when doing custom type-checking.
The patch fixes that function in two ways:

  1. It now displays the right range in case the number of actual arguments is greater than the number of expected arguments. Example:

Without patch:

main.c:5:36: error: too many arguments to function call, expected 3, have 7
  __builtin_add_overflow(1, 2, &r, 3, 4, 5, 6);
                            ~      ^

With patch:

main.c:5:36: error: too many arguments to function call, expected 3, have 7
  __builtin_add_overflow(1, 2, &r, 3, 4, 5, 6);
                                   ^~~~~~~~~~
  1. A side effect is that the patch also allows the function to properly handle the case in which the desired argument count is 0 and the number of actual arguments is 1. No test case is provided for that because currently no builtin with 0 expected argument is checked with that function.

Diff Detail

Event Timeline

bsaleil created this revision.Feb 5 2020, 1:39 PM
Yi-Hong.Lyu requested changes to this revision.Feb 6 2020, 3:42 AM
Yi-Hong.Lyu added a subscriber: Yi-Hong.Lyu.

Please add tests

This revision now requires changes to proceed.Feb 6 2020, 3:42 AM
bsaleil updated this revision to Diff 242963.Feb 6 2020, 11:22 AM

Adding test case

bsaleil edited the summary of this revision. (Show Details)Feb 6 2020, 11:32 AM
bsaleil edited the summary of this revision. (Show Details)Feb 6 2020, 11:35 AM