<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 17, 2011, at 2:56 AM, Hans Wennborg wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">This breaks the Chrome build, where we have some code like this:<br><br>template <bool extendArray><br>void myFunc() {<br> int arr[3 + (extendArray ? 1 : 0)];<br><br> if (extendArray)<br> arr[3] = 42;<br>}<br><br>void f() {<br> myFunc<false>();<br>}<br><br></span></blockquote><div><br></div><div>I'm certain why it is warning here. The check looks at the array type for 'arr', sees that it has a ConstantArrayType with a specific size (which the compiler believes is the size of the array), and then compares the index to that size. I'll look into it.</div><br><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">(The real code is here:<br><a href="http://trac.webkit.org/browser/trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp#L245">http://trac.webkit.org/browser/trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp#L245</a>)<br><br>In fact, it seems to warn also in a case like this:<br><br>void f() {<br> int arr[42];<br> if (0)<br> arr[100] = 5;<br>}<br><br>Would it be possible to make the warning a bit more conservative?<br><br></span></blockquote></div><br><div>Why? I don't think that's reasonable. Yes the access is dead code, but it's a turd in the code waiting to turn into a real bug. It makes no sense to have it. I can understand being concerned about buffer overflows that can truly only occur because of control-dependencies (e.g., the buffer size and the index is dependent on program flow), but throwing flow-analysis here when the warning will flag genuine issues in 99.9% of the cases doesn't seem worth it to me.</div><div><br></div><div>The point of the warning is to be 100% accurate aside from control-flow dependencies like these. The compiler knows that the array has a fixed size, and any access beyond that size is a problem if that code were to execute. We're not trying to prove that the code executes, only that if it were this would be real problem.</div></body></html>