[compiler-rt] r267084 - Enable stack-use-after-scope tests.

Dimitry Andric via llvm-commits llvm-commits at lists.llvm.org
Sun May 1 08:42:53 PDT 2016


Hi Evgeniy,

On FreeBSD (both i386 and x86_64) we are seeing failing test cases for use-after-scope-capture.  Specifically, this part in use-after-scope-capture.cc does not match:

      // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
      // CHECK: #0 0x{{.*}} in {{.*}}::operator(){{.*}}.cc:[[@LINE-2]]

The output of the test case on x86_64-freebsd is the following:

==18308==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7fffffffe330 at pc 0x00000048e278 bp 0x7fffffffe260 sp 0x7fffffffe258
READ of size 4 at 0x7fffffffe330 thread T0
    #0 0x48e277 in _ZZ4mainENK3$_0clEv /share/dim/src/llvm/trunk/projects/compiler-rt/test/asan/TestCases/use-after-scope-capture.cc:11:14
    #1 0x48e228 in __invoke<(lambda at /share/dim/src/llvm/trunk/projects/compiler-rt/test/asan/TestCases/use-after-scope-capture.cc:10:9) &> /usr/include/c++/v1/__functional_base:365:12
    #2 0x48e228 in _ZNSt3__128__invoke_void_return_wrapperIiE6__callIJRZ4mainE3$_0EEEiDpOT_ /usr/include/c++/v1/__functional_base:386
    #3 0x48e1cc in _ZNSt3__110__function6__funcIZ4mainE3$_0NS_9allocatorIS2_EEFivEEclEv /usr/include/c++/v1/functional:1533:12
    #4 0x48e312 in std::__1::function<int()(void)>::operator()(void) const /usr/include/c++/v1/functional:1891:12
    #5 0x48de5b in main /share/dim/src/llvm/trunk/projects/compiler-rt/test/asan/TestCases/use-after-scope-capture.cc:16:10
    #6 0x40ba9e in _start (/home/dim/obj/llvm-268169-trunk-freebsd11-amd64-ninja-rel-1/projects/compiler-rt/test/asan/X86_64FreeBSDConfig/TestCases/Output/use-after-scope-capture.cc.tmp+0x40ba9e)
    #7 0x8006ccfff  (<unknown module>)

E.g. the initial operator() call is at stack frame 4, not 0.  And it is generated from libc++'s <functional>, not from the use-after-scope-capture.cc file.

That said, stack frame 0 has a call to '_ZZ4mainENK3$_0clEv', which translates to 'main::$_0::operator()() const', but for some reason llvm-symbolizer fails to demangle this identifier.  Any idea what might be wrong?

-Dimitry

> On 22 Apr 2016, at 02:10, Evgeniy Stepanov via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Author: eugenis
> Date: Thu Apr 21 19:10:23 2016
> New Revision: 267084
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=267084&view=rev
> Log:
> Enable stack-use-after-scope tests.
> 
> Fix and enable working stack-use-after-scope tests.
> Add more failing tests for the feature, for fix later.
> 
> PR27453.
> 
> Patch by Vitaly Buka.
> 
> Added:
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope-if.cc
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-removed.cc
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop.cc
> Modified:
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope-capture.cc
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope-dtor-order.cc
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope-inlined.cc
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope-nobug.cc
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope-temp.cc
>    compiler-rt/trunk/test/asan/TestCases/use-after-scope.cc
> 
> Modified: compiler-rt/trunk/test/asan/TestCases/use-after-scope-capture.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-capture.cc?rev=267084&r1=267083&r2=267084&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope-capture.cc (original)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-capture.cc Thu Apr 21 19:10:23 2016
> @@ -1,14 +1,17 @@
> -// RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && %run %t
> -// XFAIL: *
> +// RUN: %clangxx_asan -std=c++11 -O1 -mllvm -asan-use-after-scope=1 %s -o %t && \
> +// RUN:     not %run %t 2>&1 | FileCheck %s
> +
> +#include <functional>
> 
> int main() {
>   std::function<int()> f;
>   {
>     int x = 0;
>     f = [&x]() {
> -      return x;
> -    }
> +      return x;  // BOOM
> +      // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
> +      // CHECK: #0 0x{{.*}} in {{.*}}::operator()(){{.*}}.cc:[[@LINE-2]]
> +    };
>   }
>   return f();  // BOOM
> -  // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
> }
> 
> Modified: compiler-rt/trunk/test/asan/TestCases/use-after-scope-dtor-order.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-dtor-order.cc?rev=267084&r1=267083&r2=267084&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope-dtor-order.cc (original)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-dtor-order.cc Thu Apr 21 19:10:23 2016
> @@ -1,6 +1,6 @@
> -// RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \
> +// RUN: %clangxx_asan -O1 -mllvm -asan-use-after-scope=1 %s -o %t && \
> // RUN:     not %run %t 2>&1 | FileCheck %s
> -// XFAIL: *
> +
> #include <stdio.h>
> 
> struct IntHolder {
> @@ -8,7 +8,7 @@ struct IntHolder {
>   ~IntHolder() {
>     printf("Value: %d\n", *val_);  // BOOM
>     // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
> -    // CHECK:  #0 0x{{.*}} in IntHolder::~IntHolder{{.*}}use-after-scope-dtor-order.cc:[[@LINE-2]]
> +    // CHECK:  #0 0x{{.*}} in IntHolder::~IntHolder{{.*}}.cc:[[@LINE-2]]
>   }
>   void set(int *val) { val_ = val; }
>   int *get() { return val_; }
> 
> Added: compiler-rt/trunk/test/asan/TestCases/use-after-scope-if.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-if.cc?rev=267084&view=auto
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope-if.cc (added)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-if.cc Thu Apr 21 19:10:23 2016
> @@ -0,0 +1,15 @@
> +// RUN: %clangxx_asan -O1 -mllvm -asan-use-after-scope=1 %s -o %t && \
> +// RUN:     not %run %t 2>&1 | FileCheck %s
> +
> +int *p;
> +bool b = true;
> +
> +int main() {
> +  if (b) {
> +    int x[5];
> +    p = x+1;
> +  }
> +  return *p;  // BOOM
> +  // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
> +  // CHECK:  #0 0x{{.*}} in main {{.*}}.cc:[[@LINE-2]]
> +}
> 
> Modified: compiler-rt/trunk/test/asan/TestCases/use-after-scope-inlined.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-inlined.cc?rev=267084&r1=267083&r2=267084&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope-inlined.cc (original)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-inlined.cc Thu Apr 21 19:10:23 2016
> @@ -2,8 +2,8 @@
> // happens. "always_inline" is not enough, as Clang doesn't emit
> // llvm.lifetime intrinsics at -O0.
> //
> -// RUN: %clangxx_asan -O2 -fsanitize=use-after-scope %s -o %t && not %run %t 2>&1 | FileCheck %s
> -// XFAIL: *
> +// RUN: %clangxx_asan -O2 -mllvm -asan-use-after-scope=1 %s -o %t && \
> +// RUN:     not %run %t 2>&1 | FileCheck %s
> 
> int *arr;
> 
> 
> Added: compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc?rev=267084&view=auto
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc (added)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc Thu Apr 21 19:10:23 2016
> @@ -0,0 +1,16 @@
> +// RUN: %clangxx_asan -O1 -mllvm -asan-use-after-scope=1 %s -o %t && \
> +// RUN:     not %run %t 2>&1 | FileCheck %s
> +//
> +// FIXME: @llvm.lifetime.* are not emitted for x.
> +// XFAIL: *
> +
> +int *p;
> +
> +int main() {
> +  // Variable goes in and out of scope.
> +  for (int i = 0; i < 3; ++i) {
> +    int x[3] = {i, i, i};
> +    p = x + i;
> +  }
> +  return *p;  // BOOM
> +}
> 
> Added: compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-removed.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-removed.cc?rev=267084&view=auto
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-removed.cc (added)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-removed.cc Thu Apr 21 19:10:23 2016
> @@ -0,0 +1,19 @@
> +// RUN: %clangxx_asan -O1 -mllvm -asan-use-after-scope=1 %s -o %t && \
> +// RUN:     not %run %t 2>&1 | FileCheck %s
> +//
> +// FIXME: Compiler removes for-loop but keeps x variable. For unknown reason
> +// @llvm.lifetime.* are not emitted for x.
> +// XFAIL: *
> +
> +#include <stdlib.h>
> +
> +int *p;
> +
> +int main() {
> +  for (int i = 0; i < 3; i++) {
> +    int x;
> +    p = &x;
> +  }
> +  return **p;  // BOOM
> +  // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
> +}
> 
> Added: compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop.cc?rev=267084&view=auto
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop.cc (added)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop.cc Thu Apr 21 19:10:23 2016
> @@ -0,0 +1,14 @@
> +// RUN: %clangxx_asan -O1 -mllvm -asan-use-after-scope=1 %s -o %t && \
> +// RUN:     not %run %t 2>&1 | FileCheck %s
> +
> +int *p[3];
> +
> +int main() {
> +  for (int i = 0; i < 3; i++) {
> +    int x;
> +    p[i] = &x;
> +  }
> +  return **p;  // BOOM
> +  // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
> +  // CHECK: #0 0x{{.*}} in main {{.*}}.cc:[[@LINE-2]]
> +}
> 
> Modified: compiler-rt/trunk/test/asan/TestCases/use-after-scope-nobug.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-nobug.cc?rev=267084&r1=267083&r2=267084&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope-nobug.cc (original)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-nobug.cc Thu Apr 21 19:10:23 2016
> @@ -1,14 +1,15 @@
> -// RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && %run %t
> -// XFAIL: *
> +// RUN: %clangxx_asan -O1 -mllvm -asan-use-after-scope=1 %s -o %t && %run %t
> 
> #include <stdio.h>
> +#include <stdlib.h>
> +
> +int *p[3];
> 
> int main() {
> -  int *p = 0;
>   // Variable goes in and out of scope.
>   for (int i = 0; i < 3; i++) {
> -    int x = 0;
> -    p = &x;
> +    int x;
> +    p[i] = &x;
>   }
>   printf("PASSED\n");
>   return 0;
> 
> Modified: compiler-rt/trunk/test/asan/TestCases/use-after-scope-temp.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-temp.cc?rev=267084&r1=267083&r2=267084&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope-temp.cc (original)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-temp.cc Thu Apr 21 19:10:23 2016
> @@ -1,15 +1,10 @@
> -// RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \
> -// RUN:     %run %t 2>&1 | FileCheck %s
> +// RUN: %clangxx_asan -O1 -mllvm -asan-use-after-scope=1 %s -o %t && \
> +// RUN:     not %run %t 2>&1 | FileCheck %s
> //
> // Lifetime for temporaries is not emitted yet.
> // XFAIL: *
> 
> -#include <stdio.h>
> -
> struct IntHolder {
> -  explicit IntHolder(int val) : val(val) {
> -    printf("IntHolder: %d\n", val);
> -  }
>   int val;
> };
> 
> @@ -20,10 +15,9 @@ void save(const IntHolder &holder) {
> }
> 
> int main(int argc, char *argv[]) {
> -  save(IntHolder(10));
> +  save({10});
>   int x = saved->val;  // BOOM
> -  // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
> -  // CHECK:  #0 0x{{.*}} in main {{.*}}use-after-scope-temp.cc:[[@LINE-2]]
> -  printf("saved value: %d\n", x);
> -  return 0;
> +// CHECK: ERROR: AddressSanitizer: stack-use-after-scope
> +// CHECK:  #0 0x{{.*}} in main {{.*}}use-after-scope-temp.cc:[[@LINE-2]]
> +  return x;
> }
> 
> Modified: compiler-rt/trunk/test/asan/TestCases/use-after-scope.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope.cc?rev=267084&r1=267083&r2=267084&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/use-after-scope.cc (original)
> +++ compiler-rt/trunk/test/asan/TestCases/use-after-scope.cc Thu Apr 21 19:10:23 2016
> @@ -1,10 +1,9 @@
> -// RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \
> -// RUN: not %run %t 2>&1 | FileCheck %s
> -// RUN: %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
> -// XFAIL: *
> +// RUN: %clangxx_asan -O1 -mllvm -asan-use-after-scope=1 %s -o %t && \
> +// RUN:     not %run %t 2>&1 | FileCheck %s
> +
> +int *p = 0;
> 
> int main() {
> -  int *p = 0;
>   {
>     int x = 0;
>     p = &x;
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160501/5d7e98df/attachment.sig>


More information about the llvm-commits mailing list