[cfe-commits] r145918 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/condition.cpp

Lang Hames lhames at apple.com
Tue Dec 6 10:15:01 PST 2011


Nice catch. Thanks Richard!

- Lang.

On Dec 5, 2011, at 8:48 PM, Richard Trieu wrote:

> Author: rtrieu
> Date: Mon Dec  5 22:48:01 2011
> New Revision: 145918
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=145918&view=rev
> Log:
> Switch a cast to a dyn_cast and check the pointer before using.  Fixes a crash
> in the following code:
> 
> void test4(bool (&x)(void)) {
>  while (x);
> }
> 
> 
> Modified:
>    cfe/trunk/lib/Sema/SemaChecking.cpp
>    cfe/trunk/test/SemaCXX/condition.cpp
> 
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=145918&r1=145917&r2=145918&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Dec  5 22:48:01 2011
> @@ -3771,10 +3771,11 @@
>       }
> 
>       if (D && !D->isWeak()) {
> -        FunctionDecl* F = cast<FunctionDecl>(D);
> -        S.Diag(E->getExprLoc(), diag::warn_impcast_function_to_bool)
> -          << F << E->getSourceRange() << SourceRange(CC);
> -        return;
> +        if (FunctionDecl* F = dyn_cast<FunctionDecl>(D)) {
> +          S.Diag(E->getExprLoc(), diag::warn_impcast_function_to_bool)
> +            << F << E->getSourceRange() << SourceRange(CC);
> +          return;
> +        }
>       }
>     }
>     return; // Other casts to bool are not checked.
> 
> Modified: cfe/trunk/test/SemaCXX/condition.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/condition.cpp?rev=145918&r1=145917&r2=145918&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/condition.cpp (original)
> +++ cfe/trunk/test/SemaCXX/condition.cpp Mon Dec  5 22:48:01 2011
> @@ -52,3 +52,7 @@
>   if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}}
>     (void) 0;
> }
> +
> +void test4(bool (&x)(void)) {
> +  while (x);
> +}
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list