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
47 lines
3.2 KiB
C
47 lines
3.2 KiB
C
// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -Walloc-size %s
|
|
struct Foo { int x[10]; };
|
|
|
|
typedef __typeof__(sizeof(int)) size_t;
|
|
void *my_malloc(size_t) __attribute__((alloc_size(1)));
|
|
void *my_calloc(size_t, size_t) __attribute__((alloc_size(2, 1)));
|
|
|
|
void foo_consumer(struct Foo* p);
|
|
|
|
void alloc_foo(void) {
|
|
struct Foo *ptr1 = my_malloc(sizeof(struct Foo));
|
|
struct Foo *ptr2 = my_malloc(sizeof(*ptr2));
|
|
struct Foo *ptr3 = my_calloc(1, sizeof(*ptr3));
|
|
struct Foo *ptr4 = my_calloc(sizeof(*ptr4), 1);
|
|
struct Foo (*ptr5)[5] = my_malloc(sizeof(*ptr5));
|
|
void *ptr6 = my_malloc(4);
|
|
|
|
// Test insufficient size with different allocation functions.
|
|
struct Foo *ptr7 = my_malloc(sizeof(ptr7)); // expected-warning {{allocation of insufficient size '8' for type 'struct Foo' with size '40'}}
|
|
struct Foo *ptr8 = my_calloc(1, sizeof(ptr8)); // expected-warning {{allocation of insufficient size '8' for type 'struct Foo' with size '40'}}
|
|
struct Foo *ptr9 = my_calloc(sizeof(ptr9), 1); // expected-warning {{allocation of insufficient size '8' for type 'struct Foo' with size '40'}}
|
|
|
|
// Test function arguments.
|
|
foo_consumer(my_malloc(4)); // expected-warning {{allocation of insufficient size '4' for type 'struct Foo' with size '40'}}
|
|
|
|
// Test explicit cast.
|
|
struct Foo *ptr10 = (struct Foo *)my_malloc(sizeof(*ptr10));
|
|
struct Foo *ptr11 = (struct Foo *)my_malloc(sizeof(ptr11)); // expected-warning {{allocation of insufficient size '8' for type 'struct Foo' with size '40'}}
|
|
struct Foo *ptr12 = (struct Foo *)my_calloc(1, sizeof(ptr12)); // expected-warning {{allocation of insufficient size '8' for type 'struct Foo' with size '40'}}
|
|
struct Foo *ptr13 = (struct Foo *)my_malloc(4); // expected-warning {{allocation of insufficient size '4' for type 'struct Foo' with size '40'}}
|
|
void *ptr14 = (struct Foo *)my_malloc(4); // expected-warning {{allocation of insufficient size '4' for type 'struct Foo' with size '40'}}
|
|
|
|
struct Foo *ptr15 = (void *)(struct Foo *)my_malloc(4); // expected-warning 2 {{allocation of insufficient size '4' for type 'struct Foo' with size '40'}}
|
|
int *ptr16 = (unsigned *)(void *)(int *)my_malloc(1); // expected-warning {{initializing 'int *' with an expression of type 'unsigned int *' converts between pointers to integer types with different sign}}
|
|
// expected-warning@-1 {{allocation of insufficient size '1' for type 'int' with size '4'}}
|
|
// expected-warning@-2 {{allocation of insufficient size '1' for type 'unsigned int' with size '4'}}
|
|
int *ptr17 = (void *)(int *)my_malloc(1); // expected-warning {{allocation of insufficient size '1' for type 'int' with size '4'}}
|
|
// expected-warning@-1 {{allocation of insufficient size '1' for type 'int' with size '4'}}
|
|
(void)(int *)my_malloc(1); // expected-warning {{allocation of insufficient size '1' for type 'int' with size '4'}}
|
|
|
|
void *funcptr_1 = (void (*)(int))my_malloc(1);
|
|
|
|
// Zero size allocations are assumed to be intentional.
|
|
int *zero_alloc1 = my_malloc(0);
|
|
int *zero_alloc2 = (int *)my_malloc(0);
|
|
}
|