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
135 lines
2.8 KiB
C
135 lines
2.8 KiB
C
// RUN: %clang_cc1 -fsyntax-only -Wunused-but-set-variable -I %S/Inputs -verify %s
|
|
// RUN: %clang_cc1 -fsyntax-only -Wunused-but-set-variable -Wno-unused-but-set-global -I %S/Inputs -verify=no-global %s
|
|
// no-global-no-diagnostics
|
|
|
|
// Test that header-defined static globals don't warn.
|
|
#include "warn-unused-but-set-static-global-header.h"
|
|
|
|
#define NULL (void*)0
|
|
|
|
void *set(int size);
|
|
void func_call(void *);
|
|
|
|
static int set_unused; // expected-warning {{variable 'set_unused' set but not used}}
|
|
static int set_and_used;
|
|
static int only_used;
|
|
static int addr_taken;
|
|
extern int external_var; // No warning (external linkage).
|
|
extern int global_var; // No warning (not static).
|
|
|
|
void f1() {
|
|
set_unused = 1;
|
|
set_and_used = 2;
|
|
|
|
int x = set_and_used;
|
|
(void)x;
|
|
|
|
int y = only_used;
|
|
(void)y;
|
|
|
|
int *p = &addr_taken;
|
|
(void)p;
|
|
|
|
external_var = 3;
|
|
global_var = 4;
|
|
}
|
|
|
|
// Test across multiple functions.
|
|
static int set_used1;
|
|
static int set_used2;
|
|
|
|
static int set1; // expected-warning {{variable 'set1' set but not used}}
|
|
static int set2; // expected-warning {{variable 'set2' set but not used}}
|
|
|
|
void f2() {
|
|
set1 = 1;
|
|
set_used1 = 1;
|
|
|
|
int x = set_used2;
|
|
(void)x;
|
|
}
|
|
|
|
void f3() {
|
|
set2 = 2;
|
|
set_used2 = 2;
|
|
|
|
int x = set_used1;
|
|
(void)x;
|
|
}
|
|
|
|
static volatile int vol_set;
|
|
void f4() {
|
|
vol_set = 1;
|
|
}
|
|
|
|
// Read and use
|
|
static int compound; // expected-warning{{variable 'compound' set but not used}}
|
|
static volatile int vol_compound;
|
|
static int unary; // expected-warning{{variable 'unary' set but not used}}
|
|
static volatile int vol_unary;
|
|
void f5() {
|
|
compound += 1;
|
|
vol_compound += 1;
|
|
unary++;
|
|
vol_unary++;
|
|
}
|
|
|
|
struct S {
|
|
int i;
|
|
};
|
|
static struct S s_set; // expected-warning{{variable 's_set' set but not used}}
|
|
static struct S s_used;
|
|
void f6() {
|
|
struct S t;
|
|
s_set = t;
|
|
t = s_used;
|
|
}
|
|
|
|
// Multiple assignments
|
|
static int multi; // expected-warning{{variable 'multi' set but not used}}
|
|
void f7() {
|
|
multi = 1;
|
|
multi = 2;
|
|
multi = 3;
|
|
}
|
|
|
|
// Unused pointers
|
|
static int *unused_ptr; // expected-warning{{variable 'unused_ptr' set but not used}}
|
|
static char *str_ptr; // expected-warning{{variable 'str_ptr' set but not used}}
|
|
void f8() {
|
|
unused_ptr = set(5);
|
|
str_ptr = "hello";
|
|
}
|
|
|
|
// Used pointers
|
|
void a(void *);
|
|
static int *used_ptr;
|
|
static int *param_ptr;
|
|
static int *null_check_ptr;
|
|
void f9() {
|
|
used_ptr = set(5);
|
|
*used_ptr = 5;
|
|
|
|
param_ptr = set(5);
|
|
func_call(param_ptr);
|
|
|
|
null_check_ptr = set(5);
|
|
if (null_check_ptr == NULL) {}
|
|
}
|
|
|
|
// Function pointers (unused)
|
|
static void (*unused_func_ptr)(); // expected-warning {{variable 'unused_func_ptr' set but not used}}
|
|
void SetUnusedCallback(void (*f)()) {
|
|
unused_func_ptr = f;
|
|
}
|
|
|
|
// Function pointers (used)
|
|
static void (*used_func_ptr)();
|
|
void SetUsedCallback(void (*f)()) {
|
|
used_func_ptr = f;
|
|
}
|
|
void CallUsedCallback() {
|
|
if (used_func_ptr)
|
|
used_func_ptr();
|
|
}
|