<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>That FIXME, and indeed the code to support case ranges, actually predates RangeConstraintManager, which implements most of what the FIXME is referring to. (That is, the technical/historical reason we couldn't do it symbolically is "it wasn't implemented yet".) So your change is in fact on the right track.</div><div><br></div><div>However, what you've done is construct the expression "$x >= LOWER && $x <= UPPER". This is correct, but it's not a form that RangeConstraintManager will actually handle right now:</div><div><br></div><div>void clang_analyzer_eval(int);</div><div>void test(int i) {</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>switch (i) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>case 1 ... 5:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return;</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>clang_analyzer_eval(x == 2); // should print FALSE, but will print UNKNOWN with your patch.</div><div>}</div><div><br></div><div>(clang_analyzer_eval is a special function used to probe the analyzer state, handled by the debug.ExprInspection checker.)</div><div><br></div><div>The easiest way to fix this would be to use assumeDual on each expression individually. Then you end up with three cases: $x < LOWER, $x is in range, and $x > UPPER. Unfortunately, you'd then have to restructure the whole function, which currently assumes that you end up with exactly one state that can end up in the "default" branch. That wouldn't be too hard.</div><div><br></div><div>The harder way to solve this is to actually teach [Range]ConstraintManager to recognize constraints like this, and do the right thing. The implementation is already set up to handle disjoint sets of ranges, so you could actually do this without changing <i>everything.</i> It's probably more messy than you'd like, though.</div><div><br></div><div>The sneaky way to do this is to realize that "$x >= LOWER && $x <= UPPER" is actually equivalent to "$x - (LOWER - MIN) <= UPPER - (LOWER - MIN)", where MIN is the minimum value for the integer type, for integers with wraparound semantics. (RangeConstraintManager actually takes advantage of this in reverse to translate "$x - OFFSET <= VALUE" back into a pair of range disjunctions.) The only trouble with doing something like this is that wraparound is Hard™ and you/we will want to be very careful that this actually handles everything correctly, for all the integer types we care about. A definite benefit of this is that we're back to only having one state, which prevents potential exponential explosion as analysis continues.</div><div><br></div><div>What do you think we should do here?</div><div>Jordan</div><div><br></div><br><div><div>On Aug 12, 2014, at 12:39 , Zach Davis <<a href="mailto:zdavkeos@gmail.com">zdavkeos@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">All-<br><br>I was looking over 16833 and had a few questions.<br><br>The issue is the analyzer tries to concretize all the values in a case<br>statement with a range value:<br><br>    switch (a) {<br>        case 1 ... 0xfffff: // hang's trying each value in the range<br>           return 1;<br>        default:<br>           return 0;<br>    }<br><br>Is there any reason we can't symbolically evaluate 1 <= a <= 0xfffff,<br>rather than trying each 'a == v for v in 1..0xfffff'? I've attached a<br>patch that attempts to do this and it seems to work (it no longer<br>hangs anyway).  Is there a technical/historical reason for doing it<br>the current way?<br><br>The FIXME above the block mentions using '"ranges" for NonLVals'. I'm<br>not sure what this means, or if any work has been done toward this.<br>If not, would there be any value in pursing a patch like this in the<br>meantime to resolve the performance issue?<br><br>Thanks,<br>Zach<br><span><16833_hang_on_large_case_range.patch></span>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br></blockquote></div><br></body></html>