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
224 lines
7.1 KiB
C
224 lines
7.1 KiB
C
// RUN: %clang_cc1 -fsyntax-only -Wpointer-arith -verify %s
|
|
// RUN: %clang_cc1 -fsyntax-only -Wpointer-arith -fexperimental-late-parse-attributes %s -verify
|
|
|
|
#define __counted_by(f) __attribute__((counted_by(f)))
|
|
|
|
struct size_unknown;
|
|
struct size_known {
|
|
int field;
|
|
};
|
|
|
|
typedef void(*fn_ptr_ty)(void);
|
|
|
|
//==============================================================================
|
|
// __counted_by on struct member pointer in decl attribute position
|
|
//==============================================================================
|
|
|
|
struct on_member_pointer_complete_ty {
|
|
int count;
|
|
struct size_known * buf __counted_by(count);
|
|
};
|
|
|
|
struct on_member_pointer_incomplete_ty {
|
|
int count;
|
|
struct size_unknown * buf __counted_by(count); // ok
|
|
};
|
|
|
|
struct on_member_pointer_const_incomplete_ty {
|
|
int count;
|
|
const struct size_unknown * buf __counted_by(count); // ok
|
|
};
|
|
|
|
struct on_member_pointer_void_ty {
|
|
int count;
|
|
// expected-warning@+2{{'counted_by' on a pointer to void is a GNU extension, treated as 'sized_by'}}
|
|
// expected-note@+1{{use '__sized_by' to suppress this warning}}
|
|
void* buf __counted_by(count);
|
|
};
|
|
|
|
struct on_member_pointer_fn_ptr_ty {
|
|
int count;
|
|
// buffer of `count` function pointers is allowed
|
|
void (**fn_ptr)(void) __counted_by(count);
|
|
};
|
|
|
|
struct on_member_pointer_fn_ptr_ty_ptr_ty {
|
|
int count;
|
|
// buffer of `count` function pointers is allowed
|
|
fn_ptr_ty* fn_ptr __counted_by(count);
|
|
};
|
|
|
|
struct on_member_pointer_fn_ty {
|
|
int count;
|
|
// buffer of `count` functions is not allowed
|
|
// expected-error@+1{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
|
|
void (*fn_ptr)(void) __counted_by(count);
|
|
};
|
|
|
|
struct on_member_pointer_fn_ptr_ty_ty {
|
|
int count;
|
|
// buffer of `count` functions is not allowed
|
|
// expected-error@+1{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
|
|
fn_ptr_ty fn_ptr __counted_by(count);
|
|
};
|
|
|
|
struct has_unannotated_vla {
|
|
int count;
|
|
int buffer[];
|
|
};
|
|
|
|
struct on_member_pointer_struct_with_vla {
|
|
int count;
|
|
// expected-error@+1{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'struct has_unannotated_vla' is a struct type with a flexible array member}}
|
|
struct has_unannotated_vla* objects __counted_by(count);
|
|
};
|
|
|
|
struct has_annotated_vla {
|
|
int count;
|
|
int buffer[] __counted_by(count);
|
|
};
|
|
|
|
// Currently prevented because computing the size of `objects` at runtime would
|
|
// require an O(N) walk of `objects` to take into account the length of the VLA
|
|
// in each struct instance.
|
|
struct on_member_pointer_struct_with_annotated_vla {
|
|
int count;
|
|
// expected-error@+1{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'struct has_annotated_vla' is a struct type with a flexible array member}}
|
|
struct has_annotated_vla* objects __counted_by(count);
|
|
};
|
|
|
|
struct on_pointer_anon_buf {
|
|
int count;
|
|
struct {
|
|
struct size_known *buf __counted_by(count);
|
|
};
|
|
};
|
|
|
|
struct on_pointer_anon_count {
|
|
struct {
|
|
int count;
|
|
};
|
|
struct size_known *buf __counted_by(count);
|
|
};
|
|
|
|
//==============================================================================
|
|
// __counted_by on struct member pointer in type attribute position
|
|
//==============================================================================
|
|
// TODO: Correctly parse counted_by as a type attribute. Currently it is parsed
|
|
// as a declaration attribute
|
|
|
|
struct on_member_pointer_complete_ty_ty_pos {
|
|
int count;
|
|
struct size_known *__counted_by(count) buf;
|
|
};
|
|
|
|
struct on_member_pointer_incomplete_ty_ty_pos {
|
|
int count;
|
|
struct size_unknown * __counted_by(count) buf; // ok
|
|
};
|
|
|
|
struct on_member_pointer_const_incomplete_ty_ty_pos {
|
|
int count;
|
|
const struct size_unknown * __counted_by(count) buf; // ok
|
|
};
|
|
|
|
struct on_member_pointer_void_ty_ty_pos {
|
|
int count;
|
|
// expected-warning@+2{{'counted_by' on a pointer to void is a GNU extension, treated as 'sized_by'}}
|
|
// expected-note@+1{{use '__sized_by' to suppress this warning}}
|
|
void *__counted_by(count) buf;
|
|
};
|
|
|
|
// -
|
|
|
|
struct on_member_pointer_fn_ptr_ty_pos {
|
|
int count;
|
|
// buffer of `count` function pointers is allowed
|
|
void (** __counted_by(count) fn_ptr)(void);
|
|
};
|
|
|
|
struct on_member_pointer_fn_ptr_ty_ptr_ty_pos {
|
|
int count;
|
|
// buffer of `count` function pointers is allowed
|
|
fn_ptr_ty* __counted_by(count) fn_ptr;
|
|
};
|
|
|
|
struct on_member_pointer_fn_ty_ty_pos {
|
|
int count;
|
|
// buffer of `count` functions is not allowed
|
|
// expected-error@+1{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
|
|
void (* __counted_by(count) fn_ptr)(void);
|
|
};
|
|
|
|
struct on_member_pointer_fn_ptr_ty_ty_pos {
|
|
int count;
|
|
// buffer of `count` functions is not allowed
|
|
// expected-error@+1{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
|
|
fn_ptr_ty __counted_by(count) fn_ptr;
|
|
};
|
|
|
|
// TODO: This should be forbidden but isn't due to counted_by being treated
|
|
// as a declaration attribute.
|
|
struct on_member_pointer_fn_ptr_ty_ty_pos_inner {
|
|
int count;
|
|
void (* __counted_by(count) * fn_ptr)(void);
|
|
};
|
|
|
|
struct on_member_pointer_struct_with_vla_ty_pos {
|
|
int count;
|
|
// expected-error@+1{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'struct has_unannotated_vla' is a struct type with a flexible array member}}
|
|
struct has_unannotated_vla *__counted_by(count) objects;
|
|
};
|
|
|
|
// Currently prevented because computing the size of `objects` at runtime would
|
|
// require an O(N) walk of `objects` to take into account the length of the VLA
|
|
// in each struct instance.
|
|
struct on_member_pointer_struct_with_annotated_vla_ty_pos {
|
|
int count;
|
|
// expected-error@+1{{counted_by' cannot be applied to a pointer with pointee of unknown size because 'struct has_annotated_vla' is a struct type with a flexible array member}}
|
|
struct has_annotated_vla* __counted_by(count) objects;
|
|
};
|
|
|
|
struct on_nested_pointer_inner {
|
|
// TODO: This should be disallowed because in the `-fbounds-safety` model
|
|
// `__counted_by` can only be nested when used in function parameters.
|
|
int count;
|
|
struct size_known *__counted_by(count) *buf;
|
|
};
|
|
|
|
struct on_nested_pointer_outer {
|
|
int count;
|
|
struct size_known **__counted_by(count) buf;
|
|
};
|
|
|
|
struct on_pointer_anon_buf_ty_pos {
|
|
int count;
|
|
struct {
|
|
struct size_known * __counted_by(count) buf;
|
|
};
|
|
};
|
|
|
|
struct on_pointer_anon_count_ty_pos {
|
|
struct {
|
|
int count;
|
|
};
|
|
struct size_known *__counted_by(count) buf;
|
|
};
|
|
|
|
//==============================================================================
|
|
// __counted_by on struct non-pointer members
|
|
//==============================================================================
|
|
|
|
struct on_pod_ty {
|
|
int count;
|
|
// expected-error@+1{{'counted_by' only applies to pointers or C99 flexible array members}}
|
|
int wrong_ty __counted_by(count);
|
|
};
|
|
|
|
struct on_void_ty {
|
|
int count;
|
|
// expected-error@+2{{'counted_by' only applies to pointers or C99 flexible array members}}
|
|
// expected-error@+1{{field has incomplete type 'void'}}
|
|
void wrong_ty __counted_by(count);
|
|
};
|