<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 26, 2014 at 8:32 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="">On Wed, Feb 26, 2014 at 5:53 AM, Kostya Serebryany <<a href="mailto:kcc@google.com">kcc@google.com</a>> wrote:<br>
> Author: kcc<br>
> Date: Wed Feb 26 07:53:23 2014<br>
> New Revision: 202266<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=202266&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=202266&view=rev</a><br>
> Log:<br>
> [asan] remove UB (comparison of two unrelated pointers) from a test<br>
<br>
</div>I assume you're aware of this (& chose the below fix as the better one<br>
anyway - which is totally fine) but you can have a well-defined<br>
comparison of unrelated pointers using std::less, if you happen to<br>
need/want/prefer that.<br></blockquote><div>I was experimenting with an implementation for a checker that find the UB case.</div><div><a href="https://code.google.com/p/address-sanitizer/issues/detail?id=269">https://code.google.com/p/address-sanitizer/issues/detail?id=269</a></div>
<div><br></div><div>The implementation is rough: it concludes the type of operand (pointer or not pointer)</div><div>from the LLVM IR Type, which is wrong, because the types in LLVM may change during optimizations from int to pointer and back.</div>
<div>The correct implementation should probably instrument the instructions in the frontend. </div><div>Before I have that, I can not rely on std::less. </div><div>(And no, I did not know about std::less, so thanks!)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5"><br>
><br>
> Modified:<br>
> compiler-rt/trunk/lib/asan/tests/asan_mem_test.cc<br>
><br>
> Modified: compiler-rt/trunk/lib/asan/tests/asan_mem_test.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_mem_test.cc?rev=202266&r1=202265&r2=202266&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_mem_test.cc?rev=202266&r1=202265&r2=202266&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/asan/tests/asan_mem_test.cc (original)<br>
> +++ compiler-rt/trunk/lib/asan/tests/asan_mem_test.cc Wed Feb 26 07:53:23 2014<br>
> @@ -76,17 +76,17 @@ TEST(AddressSanitizer, MemSetOOBTest) {<br>
> // Strictly speaking we are not guaranteed to find such two pointers,<br>
> // but given the structure of asan's allocator we will.<br>
> static bool AllocateTwoAdjacentArrays(char **x1, char **x2, size_t size) {<br>
> - vector<char *> v;<br>
> + vector<uintptr_t> v;<br>
> bool res = false;<br>
> for (size_t i = 0; i < 1000U && !res; i++) {<br>
> - v.push_back(new char[size]);<br>
> + v.push_back(reinterpret_cast<uintptr_t>(new char[size]));<br>
> if (i == 0) continue;<br>
> sort(v.begin(), v.end());<br>
> for (size_t j = 1; j < v.size(); j++) {<br>
> assert(v[j] > v[j-1]);<br>
> if ((size_t)(v[j] - v[j-1]) < size * 2) {<br>
> - *x2 = v[j];<br>
> - *x1 = v[j-1];<br>
> + *x2 = reinterpret_cast<char*>(v[j]);<br>
> + *x1 = reinterpret_cast<char*>(v[j-1]);<br>
> res = true;<br>
> break;<br>
> }<br>
> @@ -94,9 +94,10 @@ static bool AllocateTwoAdjacentArrays(ch<br>
> }<br>
><br>
> for (size_t i = 0; i < v.size(); i++) {<br>
> - if (res && v[i] == *x1) continue;<br>
> - if (res && v[i] == *x2) continue;<br>
> - delete [] v[i];<br>
> + char *p = reinterpret_cast<char *>(v[i]);<br>
> + if (res && p == *x1) continue;<br>
> + if (res && p == *x2) continue;<br>
> + delete [] p;<br>
> }<br>
> return res;<br>
> }<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div></div>