[cfe-commits] r76529 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Analysis/dead-stores.c

Chris Lattner clattner at apple.com
Mon Jul 20 23:47:30 PDT 2009


On Jul 20, 2009, at 6:12 PM, Mike Stump wrote:

> Author: mrs
> Date: Mon Jul 20 20:12:51 2009
> New Revision: 76529
>
> URL: http://llvm.org/viewvc/llvm-project?rev=76529&view=rev
> Log:
> Wire up for statement CFG improvements for conditionals that are  
> known.
>
> Modified:
>    cfe/trunk/lib/Analysis/CFG.cpp
>    cfe/trunk/test/Analysis/dead-stores.c
>
> Modified: cfe/trunk/lib/Analysis/CFG.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=76529&r1=76528&r2=76529&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Analysis/CFG.cpp (original)
> +++ cfe/trunk/lib/Analysis/CFG.cpp Mon Jul 20 20:12:51 2009
> @@ -863,10 +863,24 @@
> }
>
> CFGBlock* CFGBuilder::VisitForStmt(ForStmt* F) {
> -  // "for" is a control-flow statement.  Thus we stop processing  
> the current
> -  // block.
> +  // See if this is a known constant.
> +  bool KnownTrue = false;
> +  bool KnownFalse = false;
> +  Expr::EvalResult Result;
> +  if (F->getCond() && F->getCond()->Evaluate(Result, *Context)
> +      && Result.Val.isInt()) {
> +    if (Result.Val.getInt().getBoolValue())
> +      KnownTrue = true;
> +    else
> +      KnownFalse = true;
> +  }
> +  if (F->getCond() == 0)
> +    KnownTrue = true;

I've seen this code in several places now.  Please introduce a helper,  
something like:

static int TryEvaluateBool(const Expr *E) {.. }

That returns -1/0/1 for "not constant, false, true".  This can be used  
by many places in this code it seems.

-Chris



More information about the cfe-commits mailing list