brintos

brintos / llvm-project-archived public Read only

0
0
Text · 517 B · ff65f59 Raw
20 lines · cpp
1// RUN: %clangxx_asan %if MSVC %{ /Od %} %else %{ -O1 %} \2// RUN:     %s -o %t && not %run %t 2>&1 | FileCheck %s3 4#include "defines.h"5 6struct IntHolder {7  ATTRIBUTE_NOINLINE const IntHolder &Self() const { return *this; }8  int val = 3;9};10 11const IntHolder *saved;12 13int main(int argc, char *argv[]) {14  saved = &IntHolder().Self();15  int x = saved->val;  // BOOM16  // CHECK: ERROR: AddressSanitizer: stack-use-after-scope17  // CHECK:  #0 0x{{.*}} in main {{.*}}use-after-scope-temp2.cpp:[[@LINE-2]]18  return x;19}20