Files
TheRock/compiler/amd-llvm/clang/test/Analysis/uninit-structured-binding-array.cpp
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

389 lines
8.3 KiB
C++

// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++17 -verify %s
void clang_analyzer_eval(bool);
void array_value_a(void) {
int arr[2];
auto [a, b] = arr;
arr[0] = 0;
int x = a; // expected-warning{{Assigned value is uninitialized}}
}
void array_value_b(void) {
int arr[] = {1, 2};
auto [a, b] = arr;
clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}
int x = a; // no-warning
}
void array_value_c(void) {
int arr[3];
arr[1] = 1;
auto [a, b, c] = arr;
clang_analyzer_eval(b == arr[1]); // expected-warning{{TRUE}}
int y = b; // no-warning
int x = a; // expected-warning{{Assigned value is uninitialized}}
}
void array_value_d(void) {
int arr[3];
arr[1] = 1;
auto [a, b, c] = arr;
clang_analyzer_eval(b == arr[1]); // expected-warning{{TRUE}}
int y = b; // no-warning
int x = c; // expected-warning{{Assigned value is uninitialized}}
}
void array_value_e(void) {
int uninit[2];
int init[2] = {0};
uninit[0] = init[0];
auto [i, j] = init;
clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
clang_analyzer_eval(j == 0); // expected-warning{{TRUE}}
int a = i; // no-warning
int b = j; // no-warning
}
void array_value_f(void) {
int uninit[2];
int init[2] = {0};
uninit[0] = init[0];
auto [i, j] = uninit;
clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
int a = i; // no-warning
int b = j; // expected-warning{{Assigned value is uninitialized}}
}
void array_lref_a(void) {
int arr[2];
auto &[a, b] = arr;
int x = a; // expected-warning{{Assigned value is uninitialized}}
}
void array_lref_b(void) {
int arr[] = {1, 2};
auto &[a, b] = arr;
clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}
int x = a; // no-warning
}
void array_lref_c(void) {
int arr[2];
auto &[a, b] = arr;
arr[0] = 1;
clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
int x = a; // no-warning
int y = b; // expected-warning{{Assigned value is uninitialized}}
}
void array_lref_d(void) {
int arr[3];
arr[1] = 1;
auto &[a, b, c] = arr;
clang_analyzer_eval(b == 1); // expected-warning{{TRUE}}
int y = b; // no-warning
int x = a; // expected-warning{{Assigned value is uninitialized}}
}
void array_lref_e(void) {
int arr[3];
arr[1] = 1;
auto &[a, b, c] = arr;
clang_analyzer_eval(b == 1); // expected-warning{{TRUE}}
int y = b; // no-warning
int x = c; // expected-warning{{Assigned value is uninitialized}}
}
void array_lref_f(void) {
int uninit[2];
int init[2] = {0};
uninit[0] = init[0];
auto &[i, j] = init;
clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
clang_analyzer_eval(j == 0); // expected-warning{{TRUE}}
int a = i; // no-warning
int b = j; // no-warning
}
void array_lref_g(void) {
int uninit[2];
int init[2] = {0};
uninit[0] = init[0];
auto &[i, j] = uninit;
clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
int a = i; // no-warning
int b = j; // expected-warning{{Assigned value is uninitialized}}
}
void array_rref_a(void) {
int arr[2];
auto &&[a, b] = arr;
int x = a; // expected-warning{{Assigned value is uninitialized}}
}
void array_rref_b(void) {
int arr[] = {1, 2};
auto &&[a, b] = arr;
clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}
int x = a; // no-warning
}
void array_rref_c(void) {
int arr[2];
auto &&[a, b] = arr;
arr[0] = 1;
clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
int x = a; // no-warning
int y = b; // expected-warning{{Assigned value is uninitialized}}
}
void array_rref_d(void) {
int arr[3];
arr[1] = 1;
auto &&[a, b, c] = arr;
clang_analyzer_eval(b == 1); // expected-warning{{TRUE}}
int y = b; // no-warning
int x = a; // expected-warning{{Assigned value is uninitialized}}
}
void array_rref_e(void) {
int arr[3];
arr[1] = 1;
auto &&[a, b, c] = arr;
clang_analyzer_eval(b == 1); // expected-warning{{TRUE}}
int y = b; // no-warning
int x = c; // expected-warning{{Assigned value is uninitialized}}
}
void array_rref_f(void) {
int uninit[2];
int init[2] = {0};
uninit[0] = init[0];
auto &&[i, j] = init;
clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
clang_analyzer_eval(j == 0); // expected-warning{{TRUE}}
int a = i; // no-warning
int b = j; // no-warning
}
void array_rref_g(void) {
int uninit[2];
int init[2] = {0};
uninit[0] = init[0];
auto &&[i, j] = uninit;
clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
int a = i; // no-warning
int b = j; // expected-warning{{Assigned value is uninitialized}}
}
void array_change_a(void) {
int arr[] = {1, 2};
auto [a, b] = arr;
clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
a = 3;
clang_analyzer_eval(a == 3); // expected-warning{{TRUE}}
clang_analyzer_eval(arr[0] == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(arr[1] == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}
}
void array_change_b(void) {
int arr[] = {1, 2};
auto &[a, b] = arr;
clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}
a = 3;
clang_analyzer_eval(a == 3); // expected-warning{{TRUE}}
clang_analyzer_eval(arr[0] == 3); // expected-warning{{TRUE}}
clang_analyzer_eval(arr[1] == 2); // expected-warning{{TRUE}}
}
void array_small_a(void) {
int arr[5];
auto [a, b, c, d, e] = arr;
int x = e; // expected-warning{{Assigned value is uninitialized}}
}
void array_big_a(void) {
int arr[6];
auto [a, b, c, d, e, f] = arr;
// FIXME: These will be Undefined when we handle reading Undefined values from lazyCompoundVal.
clang_analyzer_eval(a == 1); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(b == 2); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(c == 3); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(d == 4); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(e == 5); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(f == 6); // expected-warning{{UNKNOWN}}
}
struct S {
int a = 1;
int b = 2;
};
void non_pod_val(void) {
S arr[2];
auto [x, y] = arr;
clang_analyzer_eval(x.a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(x.b == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(y.a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(y.b == 2); // expected-warning{{TRUE}}
}
void non_pod_val_syntax_2(void) {
S arr[2];
auto [x, y](arr);
clang_analyzer_eval(x.a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(x.b == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(y.a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(y.b == 2); // expected-warning{{TRUE}}
}
void non_pod_lref(void) {
S arr[2];
auto &[x, y] = arr;
clang_analyzer_eval(x.a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(x.b == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(y.a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(y.b == 2); // expected-warning{{TRUE}}
}
void non_pod_rref(void) {
S arr[2];
auto &&[x, y] = arr;
clang_analyzer_eval(x.a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(x.b == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(y.a == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(y.b == 2); // expected-warning{{TRUE}}
}
struct SUD {
inline static int c = 0;
int a = 1;
int b = 2;
SUD() { ++c; };
SUD(const SUD &copy) {
a = copy.a + 1;
b = copy.b + 1;
}
};
void non_pod_user_defined_val(void) {
SUD arr[2];
auto [x, y] = arr;
clang_analyzer_eval(x.a == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(x.b == 3); // expected-warning{{TRUE}}
clang_analyzer_eval(y.a == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(y.b == 3); // expected-warning{{TRUE}}
}
void non_pod_user_defined_val_syntax_2(void) {
SUD::c = 0;
SUD arr[2];
auto [x, y](arr);
clang_analyzer_eval(SUD::c == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(x.a == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(x.b == 3); // expected-warning{{TRUE}}
clang_analyzer_eval(y.a == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(y.b == 3); // expected-warning{{TRUE}}
}