llvm-project/clang/test/CodeGen/asan-use-after-return.cpp
Kevin Athey e0b469ffa1 [clang-cl][sanitizer] Add -fsanitize-address-use-after-return to clang.
Also:
  - add driver test (fsanitize-use-after-return.c)
  - add basic IR test (asan-use-after-return.cpp)
  - (NFC) cleaned up logic for generating table of __asan_stack_malloc
    depending on flag.

for issue: https://github.com/google/sanitizers/issues/1394

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D104076
2021-06-11 12:07:35 -07:00

34 lines
1.4 KiB
C++

// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-linux %s \
// RUN: | FileCheck %s --check-prefixes=CHECK-RUNTIME \
// RUN: --implicit-check-not="__asan_stack_malloc_always_"
// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-linux %s \
// RUN: -fsanitize-address-use-after-return=runtime \
// RUN: | FileCheck %s --check-prefixes=CHECK-RUNTIME \
// RUN: --implicit-check-not="__asan_stack_malloc_always_"
// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-linux %s \
// RUN: -fsanitize-address-use-after-return=always \
// RUN: | FileCheck %s --check-prefixes=CHECK-ALWAYS \
// RUN: --implicit-check-not=__asan_option_detect_stack_use_after_return \
// RUN: --implicit-check-not="__asan_stack_malloc_{{[0-9]}}"
// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-linux %s \
// RUN: -fsanitize-address-use-after-return=never \
// RUN: | FileCheck %s \
// RUN: --implicit-check-not=__asan_option_detect_stack_use_after_return \
// RUN: --implicit-check-not="__asan_stack_malloc_"
// CHECK-RUNTIME: load{{.*}}@__asan_option_detect_stack_use_after_return
// CHECK-RUNTIME: call{{.*}}__asan_stack_malloc_0
// CHECK-ALWAYS: call{{.*}}__asan_stack_malloc_always_0
int *function1() {
int x = 0;
#pragma clang diagnostic ignored "-Wreturn-stack-address"
return &x;
}
int main() {
auto px = function1();
return 0;
}