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
99 lines
2.7 KiB
C++
99 lines
2.7 KiB
C++
// RUN: %clang_analyze_cc1 -verify \
|
|
// RUN: -analyzer-checker=core \
|
|
// RUN: -analyzer-checker=alpha.deadcode.UnreachableCode \
|
|
// RUN: -analyzer-checker=unix.Malloc \
|
|
// RUN: -analyzer-config unix.DynamicMemoryModeling:Optimistic=true %s
|
|
|
|
typedef __typeof(sizeof(int)) size_t;
|
|
void *malloc(size_t);
|
|
void free(void *);
|
|
|
|
struct MemoryAllocator {
|
|
void __attribute((ownership_returns(malloc))) * my_malloc(size_t);
|
|
void __attribute((ownership_takes(malloc, 2))) my_free(void *);
|
|
void __attribute((ownership_holds(malloc, 2))) my_hold(void *);
|
|
};
|
|
|
|
void *myglobalpointer;
|
|
|
|
struct stuff {
|
|
void *somefield;
|
|
};
|
|
|
|
struct stuff myglobalstuff;
|
|
|
|
void af1(MemoryAllocator &Alloc) {
|
|
void *p = Alloc.my_malloc(12);
|
|
return; // expected-warning{{Potential leak of memory pointed to by}}
|
|
}
|
|
|
|
void af1_b(MemoryAllocator &Alloc) {
|
|
void *p = Alloc.my_malloc(12);
|
|
} // expected-warning{{Potential leak of memory pointed to by}}
|
|
|
|
void af1_c(MemoryAllocator &Alloc) {
|
|
myglobalpointer = Alloc.my_malloc(12); // no-warning
|
|
}
|
|
|
|
// Test that we can pass out allocated memory via pointer-to-pointer.
|
|
void af1_e(MemoryAllocator &Alloc, void **pp) {
|
|
*pp = Alloc.my_malloc(42); // no-warning
|
|
}
|
|
|
|
void af1_f(MemoryAllocator &Alloc, struct stuff *somestuff) {
|
|
somestuff->somefield = Alloc.my_malloc(12); // no-warning
|
|
}
|
|
|
|
// Allocating memory for a field via multiple indirections to our arguments is OK.
|
|
void af1_g(MemoryAllocator &Alloc, struct stuff **pps) {
|
|
*pps = (struct stuff *)Alloc.my_malloc(sizeof(struct stuff)); // no-warning
|
|
(*pps)->somefield = Alloc.my_malloc(42); // no-warning
|
|
}
|
|
|
|
void af2(MemoryAllocator &Alloc) {
|
|
void *p = Alloc.my_malloc(12);
|
|
Alloc.my_free(p);
|
|
free(p); // expected-warning{{Attempt to release already released memory}}
|
|
}
|
|
|
|
void af2b(MemoryAllocator &Alloc) {
|
|
void *p = Alloc.my_malloc(12);
|
|
free(p);
|
|
Alloc.my_free(p); // expected-warning{{Attempt to release already released memory}}
|
|
}
|
|
|
|
void af2c(MemoryAllocator &Alloc) {
|
|
void *p = Alloc.my_malloc(12);
|
|
free(p);
|
|
Alloc.my_hold(p); // expected-warning{{Attempt to release already released memory}}
|
|
}
|
|
|
|
// No leak if malloc returns null.
|
|
void af2e(MemoryAllocator &Alloc) {
|
|
void *p = Alloc.my_malloc(12);
|
|
if (!p)
|
|
return; // no-warning
|
|
free(p); // no-warning
|
|
}
|
|
|
|
// This case inflicts a possible double-free.
|
|
void af3(MemoryAllocator &Alloc) {
|
|
void *p = Alloc.my_malloc(12);
|
|
Alloc.my_hold(p);
|
|
free(p); // expected-warning{{Attempt to release non-owned memory}}
|
|
}
|
|
|
|
void * af4(MemoryAllocator &Alloc) {
|
|
void *p = Alloc.my_malloc(12);
|
|
Alloc.my_free(p);
|
|
return p; // expected-warning{{Use of memory after it is released}}
|
|
}
|
|
|
|
// This case is (possibly) ok, be conservative
|
|
void * af5(MemoryAllocator &Alloc) {
|
|
void *p = Alloc.my_malloc(12);
|
|
Alloc.my_hold(p);
|
|
return p; // no-warning
|
|
}
|
|
|