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
91 lines
2.0 KiB
C
91 lines
2.0 KiB
C
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.C11Lock -verify %s
|
|
|
|
typedef int mtx_t;
|
|
struct timespec;
|
|
|
|
enum {
|
|
// FIXME: The value if this enum is implementation defined. While all the
|
|
// implementations I am aware of using 0, the right solution would be to
|
|
// look this value up in the AST (and disable the check if it is not found).
|
|
thrd_success = 0,
|
|
thrd_error = 2
|
|
};
|
|
|
|
int mtx_init(mtx_t *mutex, int type);
|
|
int mtx_lock(mtx_t *mutex);
|
|
int mtx_timedlock(mtx_t *mutex,
|
|
const struct timespec *time_point);
|
|
int mtx_trylock(mtx_t *mutex);
|
|
int mtx_unlock(mtx_t *mutex);
|
|
int mtx_destroy(mtx_t *mutex);
|
|
|
|
mtx_t mtx1;
|
|
mtx_t mtx2;
|
|
|
|
void bad1(void)
|
|
{
|
|
mtx_lock(&mtx1); // no-warning
|
|
mtx_lock(&mtx1); // expected-warning{{This lock has already been acquired}}
|
|
}
|
|
|
|
void bad2(void) {
|
|
mtx_t mtx;
|
|
mtx_init(&mtx, 0);
|
|
mtx_lock(&mtx);
|
|
} // TODO: Warn for missing unlock?
|
|
|
|
void bad3(void) {
|
|
mtx_t mtx;
|
|
mtx_init(&mtx, 0);
|
|
} // TODO: Warn for missing destroy?
|
|
|
|
void bad4(void) {
|
|
mtx_t mtx;
|
|
mtx_init(&mtx, 0);
|
|
mtx_lock(&mtx);
|
|
mtx_unlock(&mtx);
|
|
} // TODO: warn for missing destroy?
|
|
|
|
void bad5(void) {
|
|
mtx_lock(&mtx1);
|
|
mtx_unlock(&mtx1);
|
|
mtx_unlock(&mtx1); // expected-warning {{This lock has already been unlocked}}
|
|
}
|
|
|
|
void bad6(void) {
|
|
mtx_init(&mtx1, 0);
|
|
if (mtx_trylock(&mtx1) != thrd_success)
|
|
mtx_unlock(&mtx1); // expected-warning {{This lock has already been unlocked}}
|
|
}
|
|
|
|
void bad7(void) {
|
|
mtx_lock(&mtx1);
|
|
mtx_lock(&mtx2);
|
|
mtx_unlock(&mtx1); // expected-warning {{This was not the most recently acquired lock. Possible lock order reversal}}
|
|
mtx_unlock(&mtx2);
|
|
}
|
|
|
|
void good(void) {
|
|
mtx_t mtx;
|
|
mtx_init(&mtx, 0);
|
|
mtx_lock(&mtx);
|
|
mtx_unlock(&mtx);
|
|
mtx_destroy(&mtx);
|
|
}
|
|
|
|
void good2(void) {
|
|
mtx_t mtx;
|
|
mtx_init(&mtx, 0);
|
|
if (mtx_trylock(&mtx) == thrd_success)
|
|
mtx_unlock(&mtx);
|
|
mtx_destroy(&mtx);
|
|
}
|
|
|
|
void good3(void) {
|
|
mtx_t mtx;
|
|
mtx_init(&mtx, 0);
|
|
if (mtx_timedlock(&mtx, 0) == thrd_success)
|
|
mtx_unlock(&mtx);
|
|
mtx_destroy(&mtx);
|
|
}
|