[compiler-rt] r268138 - Fix test's memory leaks.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 17:03:31 PDT 2016


fair enough - just seemed like if memory leaks were an issue/to be avoided,
that'd be the thing to do, but I appreciate the tradeoff & Filipe's change
makes it easier to manage the follow the allocation/deallocation (side
note: this looks like C code, but it's a C++ file - perhaps it should just
be a C file/code? (avoids complex language features & makes it clearer that
all the fun tools of C++ aren't relevant here))

On Fri, Apr 29, 2016 at 4:57 PM, Kostya Serebryany <kcc at google.com> wrote:

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


More information about the llvm-commits mailing list