Files
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

81 lines
2.7 KiB
C++

// Checks the ASan memory address type debugging API, makes sure it returns
// the correct memory type for heap, stack, global and shadow addresses and
// that it correctly finds out which region (and name and size) the address
// belongs to.
// RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1
// UNSUPPORTED: msvc
#include <assert.h>
#include <sanitizer/asan_interface.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int global_var;
int main() {
int local_var;
char *heap_ptr = (char *)malloc(10);
char name[100];
void *region_address;
size_t region_size;
const char *type;
type = __asan_locate_address(&global_var, name, 100,
&region_address, &region_size);
assert(nullptr != strstr(name, "global_var"));
assert(0 == strcmp(type, "global"));
assert(region_address == &global_var);
assert(region_size == sizeof(global_var));
type = __asan_locate_address((char *)(&global_var)+1, name, 100,
&region_address, &region_size);
assert(nullptr != strstr(name, "global_var"));
assert(0 == strcmp(type, "global"));
assert(region_address == &global_var);
assert(region_size == sizeof(global_var));
type = __asan_locate_address(&local_var, name, 100,
&region_address, &region_size);
assert(0 == strcmp(name, "local_var"));
assert(0 == strcmp(type, "stack"));
assert(region_address == &local_var);
assert(region_size == sizeof(local_var));
type = __asan_locate_address((char *)(&local_var)+1, name, 100,
&region_address, &region_size);
assert(0 == strcmp(name, "local_var"));
assert(0 == strcmp(type, "stack"));
assert(region_address == &local_var);
assert(region_size == sizeof(local_var));
type = __asan_locate_address(heap_ptr, name, 100,
&region_address, &region_size);
assert(0 == strcmp(type, "heap"));
assert(region_address == heap_ptr);
assert(10 == region_size);
type = __asan_locate_address(heap_ptr+1, name, 100,
&region_address, &region_size);
assert(0 == strcmp(type, "heap"));
assert(region_address == heap_ptr);
assert(10 == region_size);
size_t shadow_scale;
size_t shadow_offset;
__asan_get_shadow_mapping(&shadow_scale, &shadow_offset);
uintptr_t shadow_ptr = (((uintptr_t)heap_ptr) >> shadow_scale)
+ shadow_offset;
type = __asan_locate_address((void *)shadow_ptr, NULL, 0, NULL, NULL);
assert((0 == strcmp(type, "high shadow")) || 0 == strcmp(type, "low shadow"));
uintptr_t shadow_gap = (shadow_ptr >> shadow_scale) + shadow_offset;
type = __asan_locate_address((void *)shadow_gap, NULL, 0, NULL, NULL);
assert(0 == strcmp(type, "shadow gap"));
free(heap_ptr);
return 0;
}