[cfe-commits] r126797 - in /cfe/trunk: lib/Analysis/CFG.cpp lib/StaticAnalyzer/Core/ExprEngine.cpp test/Analysis/misc-ps.m test/SemaCXX/array-bounds.cpp

Ted Kremenek kremenek at apple.com
Thu Mar 3 17:07:56 PST 2011


Fixed here:

r126977

On Mar 3, 2011, at 2:14 PM, Jeffrey Yasskin wrote:

> On Tue, Mar 1, 2011 at 3:12 PM, Ted Kremenek <kremenek at apple.com> wrote:
>> Author: kremenek
>> Date: Tue Mar  1 17:12:55 2011
>> New Revision: 126797
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=126797&view=rev
>> Log:
>> Teach CFGBuilder to prune trivially unreachable case statements.
>> 
>> Modified:
>>    cfe/trunk/lib/Analysis/CFG.cpp
>>    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
>>    cfe/trunk/test/Analysis/misc-ps.m
>>    cfe/trunk/test/SemaCXX/array-bounds.cpp
>> 
>> Modified: cfe/trunk/lib/Analysis/CFG.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=126797&r1=126796&r2=126797&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Analysis/CFG.cpp (original)
>> +++ cfe/trunk/lib/Analysis/CFG.cpp Tue Mar  1 17:12:55 2011
>> @@ -2213,6 +2237,44 @@
>> 
>>   return Block;
>>  }
>> +
>> +static bool shouldAddCase(bool &switchExclusivelyCovered,
>> +                          const Expr::EvalResult &switchCond,
>> +                          const CaseStmt *CS,
>> +                          ASTContext &Ctx) {
>> +  bool addCase = false;
>> +
>> +  if (!switchExclusivelyCovered) {
>> +    if (switchCond.Val.isInt()) {
>> +      // Evaluate the LHS of the case value.
>> +      Expr::EvalResult V1;
>> +      CS->getLHS()->Evaluate(V1, Ctx);
>> +      assert(V1.Val.isInt());
>> +      const llvm::APSInt &condInt = switchCond.Val.getInt();
>> +      const llvm::APSInt &lhsInt = V1.Val.getInt();
>> +
>> +      if (condInt == lhsInt) {
>> +        addCase = true;
>> +        switchExclusivelyCovered = true;
>> +      }
>> +      else if (condInt < lhsInt) {
> 
> Hi Ted. I'm seeing an assertion failure here (synced to r126955) while
> compiling gold saying that condInt.IsUnsigned==false, but
> lhsInt.IsUnsigned==true. Does that indicate something obviously wrong
> with this code, or would you like me to reduce a test case?
> 
>> +        if (const Expr *RHS = CS->getRHS()) {
>> +          // Evaluate the RHS of the case value.
>> +          Expr::EvalResult V2;
>> +          RHS->Evaluate(V2, Ctx);
>> +          assert(V2.Val.isInt());
>> +          if (V2.Val.getInt() <= condInt) {
>> +            addCase = true;
>> +            switchExclusivelyCovered = true;
>> +          }
>> +        }
>> +      }
>> +    }
>> +    else
>> +      addCase = true;
>> +  }
>> +  return addCase;
>> +}
>> 
>>  CFGBlock* CFGBuilder::VisitCaseStmt(CaseStmt* CS) {
>>   // CaseStmts are essentially labels, so they are the first statement in a





More information about the cfe-commits mailing list