<div dir="ltr">I would actually not recommend that for simple tests like this one. <div>We want tests that are easy to debug (e.e. by looking at the generated IR, etc)</div><div>and any extra level of abstraction complicates that. <br><div><br></div><div> <div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 29, 2016 at 4:53 PM, David Blaikie via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Any chance of using unique_ptr or similar?</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 29, 2016 at 4:42 PM, Filipe Cabecinhas via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: filcab<br>
Date: Fri Apr 29 18:42:34 2016<br>
New Revision: 268138<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=268138&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=268138&view=rev</a><br>
Log:<br>
Fix test's memory leaks.<br>
<br>
Modified:<br>
compiler-rt/trunk/test/asan/TestCases/invalid-pointer-pairs.cc<br>
<br>
Modified: compiler-rt/trunk/test/asan/TestCases/invalid-pointer-pairs.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/invalid-pointer-pairs.cc?rev=268138&r1=268137&r2=268138&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/invalid-pointer-pairs.cc?rev=268138&r1=268137&r2=268138&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/asan/TestCases/invalid-pointer-pairs.cc (original)<br>
+++ compiler-rt/trunk/test/asan/TestCases/invalid-pointer-pairs.cc Fri Apr 29 18:42:34 2016<br>
@@ -8,19 +8,15 @@<br>
#include <assert.h><br>
#include <stdlib.h><br>
<br>
-char *p;<br>
-int main(int argc, char **argv) {<br>
+int f(char c, char *p, char *q) {<br>
// ALL-ERRORS: ERROR: AddressSanitizer: invalid-pointer-pair<br>
// [[PTR1:0x[0-9a-f]+]] [[PTR2:0x[0-9a-f]+]]<br>
- assert(argc >= 2);<br>
- p = (char *)malloc(42);<br>
- char *q = (char *)malloc(42);<br>
- switch (argv[1][0]) {<br>
+ switch (c) {<br>
case 'g':<br>
- // CMP: #0 {{.*}} in main {{.*}}invalid-pointer-pairs.cc:[[@LINE+1]]:14<br>
+ // CMP: #0 {{.*}} in f(char, char*, char*) {{.*}}invalid-pointer-pairs.cc:[[@LINE+1]]:14<br>
return p > q;<br>
case 's':<br>
- // SUB: #0 {{.*}} in main {{.*}}invalid-pointer-pairs.cc:[[@LINE+1]]:14<br>
+ // SUB: #0 {{.*}} in f(char, char*, char*) {{.*}}invalid-pointer-pairs.cc:[[@LINE+1]]:14<br>
return p - q;<br>
case 'k': {<br>
// OK-NOT: ERROR<br>
@@ -30,9 +26,19 @@ int main(int argc, char **argv) {<br>
case 'f': {<br>
char *p3 = p + 20;<br>
free(p);<br>
- // FREE: #0 {{.*}} in main {{.*}}invalid-pointer-pairs.cc:[[@LINE+2]]:14<br>
+ // FREE: #0 {{.*}} in f(char, char*, char*) {{.*}}invalid-pointer-pairs.cc:[[@LINE+2]]:14<br>
// FREE: freed by thread<br>
return p < p3;<br>
}<br>
}<br>
+ assert(0);<br>
+}<br>
+<br>
+int main(int argc, char **argv) {<br>
+ char *p = (char *)malloc(42);<br>
+ char *q = (char *)malloc(42);<br>
+ assert(argc >= 2);<br>
+ f(argv[1][0], p, q);<br>
+ free(p);<br>
+ free(q);<br>
}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>