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
125 lines
3.0 KiB
C++
125 lines
3.0 KiB
C++
// RUN: %clang_analyze_cc1 -verify %s \
|
|
// RUN: -analyzer-checker=alpha.clone.CloneChecker \
|
|
// RUN: -analyzer-config alpha.clone.CloneChecker:ReportNormalClones=false \
|
|
// RUN: -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=10
|
|
|
|
// Tests finding a suspicious clone that references local variables.
|
|
|
|
void log();
|
|
|
|
int max(int a, int b) {
|
|
log();
|
|
if (a > b)
|
|
return a;
|
|
return b; // expected-note{{Similar code using 'b' here}}
|
|
}
|
|
|
|
int maxClone(int x, int y, int z) {
|
|
log();
|
|
if (x > y)
|
|
return x;
|
|
return z; // expected-warning{{Potential copy-paste error; did you really mean to use 'z' here?}}
|
|
}
|
|
|
|
// Test that the checker works with [[clang::suppress]].
|
|
int max_suppressed(int a, int b) {
|
|
log();
|
|
if (a > b)
|
|
return a;
|
|
|
|
// This [[clang::suppress]] doesn't suppress anything but we need it here
|
|
// because otherwise the other function won't count as a perfect clone.
|
|
// FIXME: The checker should probably skip the attribute entirely
|
|
// when detecting clones. Otherwise warnings will still get suppressed,
|
|
// but for a completely wrong reason.
|
|
[[clang::suppress]]
|
|
return b; // no-note
|
|
}
|
|
|
|
int maxClone_suppressed(int x, int y, int z) {
|
|
log();
|
|
if (x > y)
|
|
return x;
|
|
[[clang::suppress]]
|
|
return z; // no-warning
|
|
}
|
|
|
|
|
|
// Tests finding a suspicious clone that references global variables.
|
|
|
|
struct mutex {
|
|
bool try_lock();
|
|
void unlock();
|
|
};
|
|
|
|
mutex m1;
|
|
mutex m2;
|
|
int i;
|
|
|
|
void busyIncrement() {
|
|
while (true) {
|
|
if (m1.try_lock()) {
|
|
++i;
|
|
m1.unlock(); // expected-note{{Similar code using 'm1' here}}
|
|
if (i > 1000) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void faultyBusyIncrement() {
|
|
while (true) {
|
|
if (m1.try_lock()) {
|
|
++i;
|
|
m2.unlock(); // expected-warning{{Potential copy-paste error; did you really mean to use 'm2' here?}}
|
|
if (i > 1000) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Tests that we provide two suggestions in cases where two fixes are possible.
|
|
|
|
int foo(int a, int b, int c) {
|
|
a += b + c;
|
|
b /= a + b;
|
|
c -= b * a; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}}
|
|
return c;
|
|
}
|
|
|
|
int fooClone(int a, int b, int c) {
|
|
a += b + c;
|
|
b /= a + b;
|
|
c -= a * a; // expected-note{{Similar code using 'a' here}}
|
|
return c;
|
|
}
|
|
|
|
|
|
// Tests that for clone groups with a many possible suspicious clone pairs, at
|
|
// most one warning per clone group is generated and every relevant clone is
|
|
// reported through either a warning or a note.
|
|
|
|
long bar1(long a, long b, long c, long d) {
|
|
c = a - b;
|
|
c = c / d * a;
|
|
d = b * b - c; // expected-warning{{Potential copy-paste error; did you really mean to use 'b' here?}}
|
|
return d;
|
|
}
|
|
|
|
long bar2(long a, long b, long c, long d) {
|
|
c = a - b;
|
|
c = c / d * a;
|
|
d = c * b - c; // expected-note{{Similar code using 'c' here}} \
|
|
// expected-warning{{Potential copy-paste error; did you really mean to use 'c' here?}}
|
|
return d;
|
|
}
|
|
|
|
long bar3(long a, long b, long c, long d) {
|
|
c = a - b;
|
|
c = c / d * a;
|
|
d = a * b - c; // expected-note{{Similar code using 'a' here}}
|
|
return d;
|
|
}
|