[cfe-commits] r160691 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Sema/uninit-variables.c

Ted Kremenek kremenek at apple.com
Wed Jul 25 13:52:39 PDT 2012


Thanks so much for fixing this.  I was out all last weekend and didn't see your report of a problem.

On Jul 24, 2012, at 2:02 PM, Richard Smith <richard-llvm at metafoo.co.uk> wrote:

> Author: rsmith
> Date: Tue Jul 24 16:02:14 2012
> New Revision: 160691
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=160691&view=rev
> Log:
> When a && or || appears as the condition of a ?:, perform appropriate
> short-circuiting when building the CFG. Also be sure to skip parens before
> checking for the && / || special cases. Finally, fix some crashes in CFG
> printing in the presence of calls to destructors for array of array of class
> type.
> 
> Modified:
>    cfe/trunk/lib/Analysis/CFG.cpp
>    cfe/trunk/test/Sema/uninit-variables.c
> 
> Modified: cfe/trunk/lib/Analysis/CFG.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=160691&r1=160690&r2=160691&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Analysis/CFG.cpp (original)
> +++ cfe/trunk/lib/Analysis/CFG.cpp Tue Jul 24 16:02:14 2012
> @@ -1491,6 +1491,12 @@
>   if (badCFG)
>     return 0;
> 
> +  // If the condition is a logical '&&' or '||', build a more accurate CFG.
> +  if (BinaryOperator *Cond =
> +        dyn_cast<BinaryOperator>(C->getCond()->IgnoreParens()))
> +    if (Cond->isLogicalOp())
> +      return VisitLogicalOperator(Cond, C, LHSBlock, RHSBlock).first;
> +
>   // Create the block that will contain the condition.
>   Block = createBlock(false);
> 
> @@ -1708,7 +1714,8 @@
>   // control-flow transfer of '&&' or '||' go directly into the then/else
>   // blocks directly.
>   if (!I->getConditionVariable())
> -    if (BinaryOperator *Cond = dyn_cast<BinaryOperator>(I->getCond()))
> +    if (BinaryOperator *Cond =
> +            dyn_cast<BinaryOperator>(I->getCond()->IgnoreParens()))
>       if (Cond->isLogicalOp())
>         return VisitLogicalOperator(Cond, I, ThenBlock, ElseBlock).first;
> 
> @@ -1928,7 +1935,8 @@
> 
>     // Specially handle logical operators, which have a slightly
>     // more optimal CFG representation.
> -    if (BinaryOperator *Cond = dyn_cast_or_null<BinaryOperator>(C))
> +    if (BinaryOperator *Cond =
> +            dyn_cast_or_null<BinaryOperator>(C ? C->IgnoreParens() : 0))
>       if (Cond->isLogicalOp()) {
>         llvm::tie(EntryConditionBlock, ExitConditionBlock) =
>           VisitLogicalOperator(Cond, F, BodyBlock, LoopSuccessor);
> @@ -2237,7 +2245,7 @@
> 
>     // Specially handle logical operators, which have a slightly
>     // more optimal CFG representation.
> -    if (BinaryOperator *Cond = dyn_cast<BinaryOperator>(C))
> +    if (BinaryOperator *Cond = dyn_cast<BinaryOperator>(C->IgnoreParens()))
>       if (Cond->isLogicalOp()) {
>         llvm::tie(EntryConditionBlock, ExitConditionBlock) =
>           VisitLogicalOperator(Cond, W, BodyBlock,
> @@ -3712,8 +3720,7 @@
>     const Type* T = VD->getType().getTypePtr();
>     if (const ReferenceType* RT = T->getAs<ReferenceType>())
>       T = RT->getPointeeType().getTypePtr();
> -    else if (const Type *ET = T->getArrayElementTypeNoTypeQual())
> -      T = ET;
> +    T = T->getBaseElementTypeUnsafe();
> 
>     OS << ".~" << T->getAsCXXRecordDecl()->getName().str() << "()";
>     OS << " (Implicit destructor)\n";
> @@ -3725,11 +3732,7 @@
> 
>   } else if (const CFGMemberDtor *ME = E.getAs<CFGMemberDtor>()) {
>     const FieldDecl *FD = ME->getFieldDecl();
> -
> -    const Type *T = FD->getType().getTypePtr();
> -    if (const Type *ET = T->getArrayElementTypeNoTypeQual())
> -      T = ET;
> -
> +    const Type *T = FD->getType()->getBaseElementTypeUnsafe();
>     OS << "this->" << FD->getName();
>     OS << ".~" << T->getAsCXXRecordDecl()->getName() << "()";
>     OS << " (Member object destructor)\n";
> 
> Modified: cfe/trunk/test/Sema/uninit-variables.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=160691&r1=160690&r2=160691&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/uninit-variables.c (original)
> +++ cfe/trunk/test/Sema/uninit-variables.c Tue Jul 24 16:02:14 2012
> @@ -503,3 +503,8 @@
>   x *= 0; // expected-warning {{variable 'x' is uninitialized}}
>   return x;
> }
> +
> +int self_init_in_cond(int *p) {
> +  int n = ((p && (0 || 1)) && (n = *p)) ? n : -1; // ok
> +  return n;
> +}
> 
> 
> _______________________________________________
> 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