Files
TheRock/compiler/amd-llvm/clang/test/Sema/attr-counted-by-void-ptr-gnu.c
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

102 lines
3.7 KiB
C

// RUN: %clang_cc1 -fsyntax-only -verify=expected-nowarn %s
// RUN: %clang_cc1 -Wpointer-arith -fsyntax-only -verify=expected-warn %s
// RUN: %clang_cc1 -fexperimental-bounds-safety -fsyntax-only -verify=expected-bounds %s
// expected-nowarn-no-diagnostics
// expected-bounds-no-diagnostics
#define NULL (void*)0
#define __counted_by(f) __attribute__((counted_by(f)))
#define __counted_by_or_null(f) __attribute__((counted_by_or_null(f)))
#define __sized_by(f) __attribute__((sized_by(f)))
//==============================================================================
// Test: counted_by on void* is allowed (warns with -Wpointer-arith)
//==============================================================================
struct test_void_ptr_gnu {
int count;
// expected-warn-warning@+2{{'counted_by' on a pointer to void is a GNU extension, treated as 'sized_by'}}
// expected-warn-note@+1{{use '__sized_by' to suppress this warning}}
void* buf __counted_by(count);
};
struct test_const_void_ptr_gnu {
int count;
// expected-warn-warning@+2{{'counted_by' on a pointer to void is a GNU extension, treated as 'sized_by'}}
// expected-warn-note@+1{{use '__sized_by' to suppress this warning}}
const void* buf __counted_by(count);
};
struct test_volatile_void_ptr_gnu {
int count;
// expected-warn-warning@+2{{'counted_by' on a pointer to void is a GNU extension, treated as 'sized_by'}}
// expected-warn-note@+1{{use '__sized_by' to suppress this warning}}
volatile void* buf __counted_by(count);
};
struct test_const_volatile_void_ptr_gnu {
int count;
// expected-warn-warning@+2{{'counted_by' on a pointer to void is a GNU extension, treated as 'sized_by'}}
// expected-warn-note@+1{{use '__sized_by' to suppress this warning}}
const volatile void* buf __counted_by(count);
};
// Verify sized_by still works the same way (always allowed, no warning)
struct test_sized_by_void_ptr {
int size;
void* buf __sized_by(size); // OK in both modes, no warning
};
//==============================================================================
// Test: counted_by_or_null on void* behaves the same
//==============================================================================
struct test_void_ptr_or_null_gnu {
int count;
// expected-warn-warning@+2{{'counted_by_or_null' on a pointer to void is a GNU extension, treated as 'sized_by_or_null'}}
// expected-warn-note@+1{{use '__sized_by_or_null' to suppress this warning}}
void* buf __counted_by_or_null(count);
};
struct test_const_void_ptr_or_null_gnu {
int count;
// expected-warn-warning@+2{{'counted_by_or_null' on a pointer to void is a GNU extension, treated as 'sized_by_or_null'}}
// expected-warn-note@+1{{use '__sized_by_or_null' to suppress this warning}}
const void* buf __counted_by_or_null(count);
};
//==============================================================================
// Test: Using void* __counted_by(...) pointers (not just declaring them)
//==============================================================================
// Verify that void* __counted_by pointers can be used as rvalues, assigned to,
// passed to functions, etc.
void* use_as_rvalue(struct test_void_ptr_gnu* t) {
return t->buf;
}
void assign_to_pointer(struct test_void_ptr_gnu* t) {
t->buf = NULL;
t->count = 0;
}
extern void* my_allocator(unsigned long);
void assign_from_allocator(struct test_void_ptr_gnu* t) {
t->buf = my_allocator(100);
t->count = 100;
}
void takes_void_ptr(void* p);
void pass_to_function(struct test_void_ptr_gnu* t) {
takes_void_ptr(t->buf);
}
void* pointer_arithmetic(struct test_void_ptr_gnu* t) {
// expected-warn-warning@+1{{arithmetic on a pointer to void is a GNU extension}}
return t->buf + 10;
}