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
73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.StoreToImmutable -std=c++17 -verify %s
|
|
|
|
void test_write_to_const_ref_param(const int ¶m) {
|
|
*(int*)¶m = 100; // expected-warning {{Trying to write to immutable memory}}
|
|
}
|
|
|
|
// FIXME: This should warn in C mode too.
|
|
void test_write_to_string_literal() {
|
|
char *str = (char*)"hello";
|
|
str[0] = 'H'; // expected-warning {{Trying to write to immutable memory}}
|
|
}
|
|
|
|
struct ParamStruct {
|
|
const int z; // expected-note {{Memory region is declared as immutable here}}
|
|
int w;
|
|
};
|
|
|
|
void test_write_to_const_struct_ref_param(const ParamStruct &s) {
|
|
*(int*)&s.z = 100; // expected-warning {{Trying to write to immutable memory}}
|
|
}
|
|
|
|
void test_const_ref_to_nonconst_data() {
|
|
int data = 42;
|
|
const int &ref = data;
|
|
*(int*)&ref = 100; // No warning expected
|
|
}
|
|
|
|
void test_const_ref_to_const_data() {
|
|
const int data = 42; // expected-note {{Memory region is declared as immutable here}}
|
|
const int &ref = data;
|
|
*(int*)&ref = 100; // expected-warning {{Trying to write to immutable memory}}
|
|
}
|
|
|
|
void test_ref_to_nonconst_data() {
|
|
int data = 42;
|
|
int &ref = data;
|
|
ref = 100; // No warning expected
|
|
}
|
|
|
|
void test_ref_to_const_data() {
|
|
const int data = 42; // expected-note {{Memory region is declared as immutable here}}
|
|
int &ref = *(int*)&data;
|
|
ref = 100; // expected-warning {{Trying to write to immutable memory}}
|
|
}
|
|
|
|
struct MultipleLayerStruct {
|
|
MultipleLayerStruct();
|
|
const int data; // expected-note {{Memory region is declared as immutable here}}
|
|
const int buf[10]; // expected-note {{Enclosing memory region is declared as immutable here}}
|
|
};
|
|
|
|
MultipleLayerStruct MLS[10];
|
|
|
|
void test_multiple_layer_struct_array_member() {
|
|
int *p = (int*)&MLS[2].data;
|
|
*p = 4; // expected-warning {{Trying to write to immutable memory}}
|
|
}
|
|
|
|
void test_multiple_layer_struct_array_array_member() {
|
|
int *p = (int*)&MLS[2].buf[3];
|
|
*p = 4; // expected-warning {{Trying to write to immutable memory}}
|
|
}
|
|
|
|
struct StructWithNonConstMember {
|
|
int x;
|
|
};
|
|
|
|
const StructWithNonConstMember SWNCM{0}; // expected-note {{Enclosing memory region is declared as immutable here}}
|
|
|
|
void test_write_to_non_const_member_of_const_struct() {
|
|
*(int*)&SWNCM.x = 100; // expected-warning {{Trying to write to immutable memory in global read-only storage}}
|
|
}
|