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
132 lines
6.6 KiB
C
132 lines
6.6 KiB
C
// RUN: %check_clang_tidy %s bugprone-assignment-in-selection-statement %t
|
|
|
|
void test_if(int a, int b, int c, int d) {
|
|
if (a = b) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
if ((a = b)) {}
|
|
if (a == b) {}
|
|
|
|
if ((b > 0) ? (a = b) : c) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
if ((b > 0) ? c : (a = b)) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
if (a = c, b = c) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
if ((b > 0) ?: (a = b)) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
if ((b = c) ?: (a > b)) {}
|
|
// FIXME: why is this not found?
|
|
}
|
|
|
|
void test_while(int a, int b, int c) {
|
|
while (a = b) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: assignment within condition of a loop may indicate programmer error
|
|
while ((a = b)) {}
|
|
while (a == b) {}
|
|
|
|
while ((b > 0) ? (a = b) : c) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: assignment within condition of a loop may indicate programmer error
|
|
while ((b > 0) ? c : (a = b)) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: assignment within condition of a loop may indicate programmer error
|
|
while (a = b, b = c) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: assignment within condition of a loop may indicate programmer error
|
|
}
|
|
|
|
void test_do(int a, int b, int c) {
|
|
do {} while (a = b);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: assignment within condition of a loop may indicate programmer error
|
|
do {} while ((a = b));
|
|
do {} while (a == b);
|
|
|
|
do {} while ((b > 0) ? (a = b) : c);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: assignment within condition of a loop may indicate programmer error
|
|
do {} while ((b > 0) ? c : (a = b));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: assignment within condition of a loop may indicate programmer error
|
|
}
|
|
|
|
void test_for(int a, int b, int c) {
|
|
for (int i = 0; a = b; i++) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: assignment within condition of a loop may indicate programmer error
|
|
for (int i = 0; (a = b); i++) {}
|
|
for (int i = 0; a == b; i++) {}
|
|
|
|
for (int i = 0; (b > 0) ? (a = b) : c; ++i) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: assignment within condition of a loop may indicate programmer error
|
|
for (int i = 0; (b > 0) ? c : (a = b); ++i) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: assignment within condition of a loop may indicate programmer error
|
|
}
|
|
|
|
void test_conditional(int a, int b, int c, int d) {
|
|
int c1 = (a = b) ? 1 : 2;
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: assignment within condition of a ternary operator may indicate programmer error
|
|
int c2 = ((a = b)) ? 1 : 2;
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: assignment within condition of a ternary operator may indicate programmer error
|
|
int c3 = (a == b) ? 1 : 2;
|
|
|
|
if ((c ? (a = b) : d) ? 1 : -1) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: assignment within condition of a ternary operator may indicate programmer error
|
|
if ((c ? ((a = b)) : d) ? 1 : -1) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: assignment within condition of a ternary operator may indicate programmer error
|
|
while ((c ? d : (a = b)) ? 1 : -1) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: assignment within condition of a ternary operator may indicate programmer error
|
|
|
|
int c4 = (c ? (a = b) : 2);
|
|
int c5 = (c ? 2 : (a = b));
|
|
}
|
|
|
|
void test_bin_op(int a, int b, int c, int d) {
|
|
int c1 = (a = b) && c;
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: assignment within operand of a logical operator may indicate programmer error
|
|
int c2 = c || (a = b);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: assignment within operand of a logical operator may indicate programmer error
|
|
int c3 = ((a = b) && c) || (c == b - a);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: assignment within operand of a logical operator may indicate programmer error
|
|
int c4 = c || ((a = b));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: assignment within operand of a logical operator may indicate programmer error
|
|
int c5 = (a = b) + 2;
|
|
int c6 = ((a = b) + 2) && c;
|
|
}
|
|
|
|
int f(int);
|
|
|
|
void test_misc(int a, int b, int c, int d) {
|
|
if ((a = c, b = c)) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
if (a = c, (b = c)) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
if ((a > 0) ? ((b < 0) ? (a = b) : (a = c)) : (a = d)) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:41: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:52: warning: assignment within condition of 'if' statement may indicate programmer error
|
|
while (a = c, (b = c, c = d)) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: assignment within condition of a loop may indicate programmer error
|
|
for (d = 0; a = c, b = c, ((a > 0) ? d == a : (d = b)); ++d) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:52: warning: assignment within condition of a loop may indicate programmer error
|
|
do {} while ((a > 0) ? (a = c, b = c) : d);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: assignment within condition of a loop may indicate programmer error
|
|
if ((a = b) && (c = d)) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: assignment within operand of a logical operator may indicate programmer error
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:21: warning: assignment within operand of a logical operator may indicate programmer error
|
|
if ((a ? (b = c) : d) && (d ? c : (b = a))) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: assignment within operand of a logical operator may indicate programmer error
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:40: warning: assignment within operand of a logical operator may indicate programmer error
|
|
if (f((a = b) ? c : d)) {}
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: assignment within condition of a ternary operator may indicate programmer error
|
|
}
|
|
|
|
void test_no_warning(int a, int b, int c) {
|
|
if ((a = b) != 0) {}
|
|
if (!(a = b)) {}
|
|
if ((int)(a = b)) {}
|
|
if ((a = b) + c > 0) {}
|
|
if ((b > 0) ? (a == b) : c) {}
|
|
if ((b > 0) ? c : (a == b)) {}
|
|
if (a = c, b == c) {}
|
|
|
|
int arr[10] = {0};
|
|
if (f(a = b)) {}
|
|
if (arr[c = a]) {};
|
|
|
|
switch (a = b) {}
|
|
}
|