Files
TheRock/compiler/amd-llvm/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

79 lines
2.7 KiB
C++

// Most Windows linkers set stack size default to 1 MB. Bump it up to 8 MB.
// DEFINE: %{stack} = %if target={{.*-windows-gnu}} %{ -Wl,--stack,8388608 %} \
// DEFINE: %if target={{.*-windows-msvc.*}} %{ -Wl,/STACK:8388608 %}
// RUN: %clangxx_asan %{stack} -O0 %s -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan %{stack} -O2 %s -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan %{stack} -O0 %s -o %t -fsanitize-address-use-after-return=always && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan %{stack} -O2 %s -o %t -fsanitize-address-use-after-return=always && not %run %t 2>&1 | FileCheck %s
// FIXME: Fix this test under GCC.
// REQUIRES: Clang
// FIXME: Fix this test for dynamic runtime on arm linux.
// UNSUPPORTED: (arm-linux || armhf-linux) && asan-dynamic-runtime
// UNSUPPORTED: ios
#include "defines.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
# include <windows.h>
#endif
ATTRIBUTE_NOINLINE
char *pretend_to_do_something(char *x) {
__asm__ __volatile__("" : : "r" (x) : "memory");
return x;
}
ATTRIBUTE_NOINLINE
char *LeakStack() {
char x[1024];
memset(x, 0, sizeof(x));
return pretend_to_do_something(x);
}
template <size_t kFrameSize>
ATTRIBUTE_NOINLINE void RecursiveFunctionWithStackFrame(int depth) {
if (depth <= 0) return;
char x[kFrameSize];
x[0] = depth;
pretend_to_do_something(x);
RecursiveFunctionWithStackFrame<kFrameSize>(depth - 1);
}
int main(int argc, char **argv) {
#ifdef _WIN32
// Prevent the crash dialog from showing in case something bad like a stack
// overflow happens.
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
#endif
int n_iter = argc >= 2 ? atoi(argv[1]) : 1000;
int depth = argc >= 3 ? atoi(argv[2]) : 500;
for (int i = 0; i < n_iter; i++) {
RecursiveFunctionWithStackFrame<10>(depth);
RecursiveFunctionWithStackFrame<100>(depth);
RecursiveFunctionWithStackFrame<500>(depth);
RecursiveFunctionWithStackFrame<1024>(depth);
RecursiveFunctionWithStackFrame<2000>(depth);
// The stack size is tight for the main thread in multithread
// environment on FreeBSD and NetBSD.
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
RecursiveFunctionWithStackFrame<5000>(depth);
RecursiveFunctionWithStackFrame<10000>(depth);
#endif
}
char *stale_stack = LeakStack();
RecursiveFunctionWithStackFrame<1024>(10);
stale_stack[100]++;
// CHECK: ERROR: AddressSanitizer: stack-use-after-return on address
// CHECK: is located in stack of thread T0 at offset {{116|132}} in frame
// CHECK: in LeakStack{{.*}}heavy_uar_test.cpp:
// CHECK: [{{16|32}}, {{1040|1056}}) 'x'
return 0;
}