stack-use-after-return.cc revision ec2ee9b51256b37ce637eee766fd9a454c02da2b
1// XFAIL: * 2// RUN: %clangxx_asan -fsanitize=use-after-return -O0 %s -o %t && \ 3// RUN: %t 2>&1 | FileCheck %s 4// RUN: %clangxx_asan -fsanitize=use-after-return -O1 %s -o %t && \ 5// RUN: %t 2>&1 | FileCheck %s 6// RUN: %clangxx_asan -fsanitize=use-after-return -O2 %s -o %t && \ 7// RUN: %t 2>&1 | FileCheck %s 8// RUN: %clangxx_asan -fsanitize=use-after-return -O3 %s -o %t && \ 9// RUN: %t 2>&1 | FileCheck %s 10 11#include <stdio.h> 12 13__attribute__((noinline)) 14char *Ident(char *x) { 15 fprintf(stderr, "1: %p\n", x); 16 return x; 17} 18 19__attribute__((noinline)) 20char *Func1() { 21 char local; 22 return Ident(&local); 23} 24 25__attribute__((noinline)) 26void Func2(char *x) { 27 fprintf(stderr, "2: %p\n", x); 28 *x = 1; 29 // CHECK: WRITE of size 1 {{.*}} thread T0 30 // CHECK: #0{{.*}}Func2{{.*}}stack-use-after-return.cc:[[@LINE-2]] 31 // CHECK: is located {{.*}} in frame <{{.*}}Func1{{.*}}> of T0's stack 32} 33 34int main(int argc, char **argv) { 35 Func2(Func1()); 36 return 0; 37} 38