[PATCH] [Sema] Handle TypoExpr for function calls correctly

Davide Italiano dccitaliano at gmail.com
Tue Jun 23 15:05:56 PDT 2015


+Rikka.

On Tue, Jun 23, 2015 at 3:05 PM, Davide Italiano <dccitaliano at gmail.com> wrote:
> Discussed yesterday with rikka on IRC.
> In the example of the test we call CheckFunctionCall with 'a' being a dependent type, C is not able to handle that correctly and we hit an assertion later on in the code.
>
> (gdb) p TheCall->dump()
> CallExpr 0x807dc07e0 'double'
> |-ImplicitCastExpr 0x807dc07c8 'double (*)(double)' <FunctionToPointerDecay>
> | `-DeclRefExpr 0x807dc0750 'double (double)' Function 0x807d6b8c0 'fabs' 'double (double)'
> `-TypoExpr 0x807dc0790 '<dependent type>' lvalue
>
> Force a call to CorrectDelayedTypoExpr() before we go through checkFunctionCall() to avoid the issue.
> Do this only in !C++ because C++ is able ho handle dependent types properly.
>
> http://reviews.llvm.org/D10670
>
> Files:
>   lib/Sema/SemaExpr.cpp
>   test/Sema/typo-builtin-crash.c
>
> Index: lib/Sema/SemaExpr.cpp
> ===================================================================
> --- lib/Sema/SemaExpr.cpp
> +++ lib/Sema/SemaExpr.cpp
> @@ -5063,6 +5063,15 @@
>
>    // Do special checking on direct calls to functions.
>    if (FDecl) {
> +    if (!getLangOpts().CPlusPlus) {
> +      // C cannot handle TypoExpr nodes because it
> +      // doesn't handle dependent types properly.
> +      ExprResult Result = CorrectDelayedTyposInExpr(TheCall);
> +      if (!Result.isUsable() || !isa<CallExpr>(Result.get()))
> +        return ExprError();
> +      TheCall = cast<CallExpr>(Result.get());
> +    }
> +
>      if (CheckFunctionCall(FDecl, TheCall, Proto))
>        return ExprError();
>
> Index: test/Sema/typo-builtin-crash.c
> ===================================================================
> --- test/Sema/typo-builtin-crash.c
> +++ test/Sema/typo-builtin-crash.c
> @@ -0,0 +1,9 @@
> +// RUN: %clang_cc1 -fsyntax-only -verify %s
> +
> +int main(void)
> +{
> +  fabs(a);  // expected-error {{undeclared identifier 'a'}} \
> +            // expected-warning {{implicitly declaring library function 'fabs' with type 'double (double)'}} \
> +            // expected-warning {{include the header <math.h> or explicitly provide a declaration for 'fabs'}}
> +  return (0);
> +}
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/



More information about the cfe-commits mailing list