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
66 lines
4.5 KiB
C
66 lines
4.5 KiB
C
// RUN: %clang_cc1 -Wno-strict-prototypes %s -verify
|
|
|
|
void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' attribute takes at least 1 argument}}
|
|
void *fail2(int a) __attribute__((alloc_size())); //expected-error{{'alloc_size' attribute takes at least 1 argument}}
|
|
|
|
void *fail3(int a) __attribute__((alloc_size(0))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
|
|
void *fail4(int a) __attribute__((alloc_size(2))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
|
|
|
|
void *fail5(int a, int b) __attribute__((alloc_size(0, 1))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
|
|
void *fail6(int a, int b) __attribute__((alloc_size(3, 1))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
|
|
|
|
void *fail7(int a, int b) __attribute__((alloc_size(1, 0))); //expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
|
|
void *fail8(int a, int b) __attribute__((alloc_size(1, 3))); //expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
|
|
|
|
int fail9(int a) __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to return values that are pointers}}
|
|
|
|
int fail10 __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to non-K&R-style functions}}
|
|
|
|
void *fail11(void *a) __attribute__((alloc_size(1))); //expected-error{{'alloc_size' attribute argument may only refer to a function parameter of integer type}}
|
|
|
|
void *fail12(int a) __attribute__((alloc_size("abc"))); //expected-error{{'alloc_size' attribute requires parameter 1 to be an integer constant}}
|
|
void *fail12(int a) __attribute__((alloc_size(1, "abc"))); //expected-error{{'alloc_size' attribute requires parameter 2 to be an integer constant}}
|
|
void *fail13(int a) __attribute__((alloc_size(1U<<31))); //expected-error{{integer constant expression evaluates to value 2147483648 that cannot be represented in a 32-bit signed integer type}}
|
|
|
|
void *(*PR31453)(int)__attribute__((alloc_size(1)));
|
|
|
|
void *KR() __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to non-K&R-style functions}}
|
|
|
|
// Applying alloc_size to function pointers should work:
|
|
void *(__attribute__((alloc_size(1))) * func_ptr1)(int);
|
|
void *(__attribute__((alloc_size(1, 2))) func_ptr2)(int, int);
|
|
|
|
// TODO: according to GCC documentation the following should actually be the type
|
|
// “pointer to pointer to alloc_size attributed function returning void*” and should
|
|
// therefore be supported
|
|
void *(__attribute__((alloc_size(1))) **ptr_to_func_ptr)(int); // expected-warning{{'alloc_size' attribute only applies to non-K&R-style functions}}
|
|
// The following definitions apply the attribute to the pointer to the function pointer which should not be possible
|
|
void *(*__attribute__((alloc_size(1))) * ptr_to_func_ptr2)(int); // expected-warning{{'alloc_size' attribute only applies to non-K&R-style functions}}
|
|
void *(**__attribute__((alloc_size(1))) ptr_to_func_ptr2)(int); // expected-warning{{'alloc_size' attribute only applies to non-K&R-style functions}}
|
|
|
|
// It should also work for typedefs:
|
|
typedef void *(__attribute__((alloc_size(1))) allocator_function_typdef)(int);
|
|
typedef void *(__attribute__((alloc_size(1, 2))) * allocator_function_typdef2)(int, int);
|
|
void *(__attribute__((alloc_size(1, 2))) * allocator_function_typdef3)(int, int);
|
|
// This typedef applies the alloc_size to the pointer to the function pointer and should not be allowed
|
|
void *(**__attribute__((alloc_size(1, 2))) * allocator_function_typdef4)(int, int); // expected-warning{{'alloc_size' attribute only applies to non-K&R-style functions}}
|
|
|
|
// We should not be warning when assigning function pointers with and without the alloc size attribute
|
|
// since it doesn't change the type of the function
|
|
typedef void *(__attribute__((alloc_size(1))) * my_malloc_fn_pointer_type)(int);
|
|
typedef void *(*my_other_malloc_fn_pointer_type)(int);
|
|
void *fn(int i);
|
|
__attribute__((alloc_size(1))) void *fn2(int i);
|
|
|
|
int main() {
|
|
my_malloc_fn_pointer_type f = fn;
|
|
my_other_malloc_fn_pointer_type f2 = fn;
|
|
my_malloc_fn_pointer_type f3 = fn2;
|
|
my_other_malloc_fn_pointer_type f4 = fn2;
|
|
}
|
|
|
|
// Regression test for GH199407: structural equivalence of alloc_size attrs
|
|
// with an unset optional ParamIdx must not crash.
|
|
#define GH199407(Ty, Name) _Alignas(Ty) char Name[sizeof(Ty)]
|
|
GH199407(struct GH199407S { float *f(long) __attribute__((alloc_size(1))); }, gbuf); // expected-error 2{{field 'f' declared as a function}} expected-error{{redefinition of 'GH199407S'}} expected-note{{previous definition is here}}
|