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
275 lines
5.4 KiB
C++
275 lines
5.4 KiB
C++
// RUN: %check_clang_tidy %s readability-redundant-control-flow %t
|
|
|
|
void g(int i);
|
|
void j();
|
|
|
|
void f() {
|
|
return;
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement at the end of a function with a void return type [readability-redundant-control-flow]
|
|
// CHECK-FIXES: void f() {
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
void g() {
|
|
f();
|
|
return;
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
|
|
// CHECK-FIXES: f();
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
void g(int i) {
|
|
if (i < 0) {
|
|
return;
|
|
}
|
|
if (i < 10) {
|
|
f();
|
|
}
|
|
}
|
|
|
|
int h() {
|
|
return 1;
|
|
}
|
|
|
|
void j() {
|
|
}
|
|
|
|
void k() {
|
|
for (int i = 0; i < 10; ++i) {
|
|
continue;
|
|
}
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement at the end of loop statement
|
|
// CHECK-FIXES: for (int i = 0; i < 10; ++i) {
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
void k2() {
|
|
int v[10] = { 0 };
|
|
for (auto i : v) {
|
|
continue;
|
|
}
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
|
|
// CHECK-FIXES: for (auto i : v) {
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
void m() {
|
|
int i = 0;
|
|
do {
|
|
++i;
|
|
continue;
|
|
} while (i < 10);
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
|
|
// CHECK-FIXES: do {
|
|
// CHECK-FIXES-NEXT: ++i;
|
|
// CHECK-FIXES-NEXT: } while (i < 10);
|
|
|
|
void p() {
|
|
int i = 0;
|
|
while (i < 10) {
|
|
++i;
|
|
continue;
|
|
}
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
|
|
// CHECK-FIXES: while (i < 10) {
|
|
// CHECK-FIXES-NEXT: ++i;
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
void im_not_dead(int i) {
|
|
if (i > 0) {
|
|
return;
|
|
}
|
|
g();
|
|
}
|
|
|
|
void im_still_not_dead(int i) {
|
|
for (int j = 0; j < 10; ++j) {
|
|
if (i < 10) {
|
|
continue;
|
|
}
|
|
g();
|
|
}
|
|
}
|
|
|
|
void im_dead(int i) {
|
|
if (i > 0) {
|
|
return;
|
|
g();
|
|
}
|
|
g();
|
|
}
|
|
|
|
void im_still_dead(int i) {
|
|
for (int j = 0; j < 10; ++j) {
|
|
if (i < 10) {
|
|
continue;
|
|
g();
|
|
}
|
|
g();
|
|
}
|
|
}
|
|
|
|
void void_return() {
|
|
return g();
|
|
}
|
|
|
|
void nested_return_unmolested() {
|
|
g();
|
|
{
|
|
g();
|
|
return;
|
|
}
|
|
}
|
|
|
|
void nested_continue_unmolested() {
|
|
for (int i = 0; i < 10; ++i) {
|
|
if (i < 5) {
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
#define MACRO_RETURN_UNMOLESTED(fn_) \
|
|
(fn_)(); \
|
|
return
|
|
|
|
#define MACRO_CONTINUE_UNMOLESTED(x_) \
|
|
do { \
|
|
for (int i = 0; i < (x_); ++i) { \
|
|
continue; \
|
|
} \
|
|
} while (false)
|
|
|
|
void macro_return() {
|
|
MACRO_RETURN_UNMOLESTED(g);
|
|
}
|
|
|
|
void macro_continue() {
|
|
MACRO_CONTINUE_UNMOLESTED(10);
|
|
}
|
|
|
|
#define MACRO_RETURN_ARG(stmt_) \
|
|
stmt_
|
|
|
|
#define MACRO_CONTINUE_ARG(stmt_) \
|
|
do { \
|
|
for (int i = 0; i < 10; ++i) { \
|
|
stmt_; \
|
|
} \
|
|
} while (false)
|
|
|
|
void macro_arg_return() {
|
|
MACRO_RETURN_ARG(return);
|
|
}
|
|
|
|
void macro_arg_continue() {
|
|
MACRO_CONTINUE_ARG(continue);
|
|
}
|
|
|
|
template <typename T>
|
|
void template_return(T check) {
|
|
if (check < T(0)) {
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
|
|
// CHECK-FIXES: if (check < T(0)) {
|
|
// CHECK-FIXES-NEXT: return;
|
|
// CHECK-FIXES-NEXT: }
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
template <>
|
|
void template_return(int check) {
|
|
if (check < 0) {
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
|
|
// CHECK-FIXES: if (check < 0) {
|
|
// CHECK-FIXES-NEXT: return;
|
|
// CHECK-FIXES-NEXT: }
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
template <typename T>
|
|
void template_loop(T end) {
|
|
for (T i = 0; i < end; ++i) {
|
|
continue;
|
|
}
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
|
|
// CHECK-FIXES: for (T i = 0; i < end; ++i) {
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
template <>
|
|
void template_loop(int end) {
|
|
for (int i = 0; i < end; ++i) {
|
|
continue;
|
|
}
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
|
|
// CHECK-FIXES: for (int i = 0; i < end; ++i) {
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
void call_templates() {
|
|
template_return(10);
|
|
template_return(10.0f);
|
|
template_return(10.0);
|
|
template_loop(10);
|
|
template_loop(10L);
|
|
template_loop(10U);
|
|
}
|
|
|
|
void dont_delete_lines_before_return_statement() {
|
|
do {} while (0);
|
|
#ifdef FOO
|
|
#endif
|
|
return;
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
|
|
// CHECK-FIXES: void dont_delete_lines_before_return_statement() {
|
|
// CHECK-FIXES-NEXT: do {} while (0);
|
|
// CHECK-FIXES-NEXT: #ifdef FOO
|
|
// CHECK-FIXES-NEXT: #endif
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
void dont_delete_lines_before_continue_statement() {
|
|
for (;;) {
|
|
do {} while (0);
|
|
#ifdef BAR
|
|
#endif
|
|
continue;
|
|
}
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
|
|
// CHECK-FIXES: void dont_delete_lines_before_continue_statement() {
|
|
// CHECK-FIXES-NEXT: for (;;) {
|
|
// CHECK-FIXES-NEXT: do {} while (0);
|
|
// CHECK-FIXES-NEXT: #ifdef BAR
|
|
// CHECK-FIXES-NEXT: #endif
|
|
// CHECK-FIXES-NEXT: }
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
void semicolon_far_from_return() {
|
|
return
|
|
|
|
;
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: redundant return statement at the end of a function with a void return type [readability-redundant-control-flow]
|
|
// CHECK-FIXES: void semicolon_far_from_return() {
|
|
// CHECK-FIXES-NEXT: }
|
|
|
|
void semicolon_far_from_continue() {
|
|
for (int i = 0; i < 20; ++i) {
|
|
continue
|
|
|
|
;
|
|
}
|
|
}
|
|
// CHECK-MESSAGES: :[[@LINE-5]]:5: warning: redundant continue statement at the end of loop statement
|
|
// CHECK-FIXES: for (int i = 0; i < 20; ++i) {
|
|
// CHECK-FIXES-NEXT: }
|