Files
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

97 lines
3.8 KiB
C++

// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.cstring,debug.ExprInspection -triple i386-apple-darwin9 -verify %s
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.cstring,debug.ExprInspection -triple x86_64-apple-darwin9 -verify %s
// This file runs in C++ mode so that the comparison type is 'bool', not 'int'.
void clang_analyzer_eval(int);
typedef typeof(sizeof(int)) size_t;
// PR12206/12510 - When SimpleSValBuilder figures out that a symbol is fully
// constrained, it should cast the value to the result type in a binary
// operation...unless the binary operation is a comparison, in which case the
// two arguments should be the same type, but won't match the result type.
//
// This is not directly related to additive folding, but we use SValBuilder's
// additive folding to tickle the bug. ExprEngine will simplify fully-constrained
// symbols, so SValBuilder will only see them if they are (a) part of an evaluated
// SymExpr (e.g. with additive folding) or (b) generated by a checker (e.g.
// unix.cstring's strlen() modelling).
void PR12206(int x) {
size_t comparisonSize = sizeof(1 == 1);
// This test is useless if size_t isn't bigger than bool.
clang_analyzer_eval(sizeof(size_t) > comparisonSize); // expected-warning{{TRUE}}
// Build a SymIntExpr, dependent on x.
int local = x - 1;
// Create a value that requires more bits to store than a comparison result.
int value = 1;
value <<= 8 * comparisonSize;
value += 1;
// Constrain the value of x.
if (x != value) return;
// Constant-folding will turn (local+1) back into the symbol for x.
// The point of this dance is to make SValBuilder be responsible for
// turning the symbol into a ConcreteInt, rather than ExprEngine.
// Test relational operators.
clang_analyzer_eval((local + 1) >= 2); // expected-warning{{TRUE}}
clang_analyzer_eval(2 <= (local + 1)); // expected-warning{{TRUE}}
// Test equality operators.
clang_analyzer_eval((local + 1) != 1); // expected-warning{{TRUE}}
clang_analyzer_eval(1 != (local + 1)); // expected-warning{{TRUE}}
}
void PR12206_truncation(signed char x) {
// Build a SymIntExpr, dependent on x.
signed char local = x - 1;
// Constrain the value of x.
if (x != 1) return;
// Constant-folding will turn (local+1) back into the symbol for x.
// The point of this dance is to make SValBuilder be responsible for
// turning the symbol into a ConcreteInt, rather than ExprEngine.
// Construct a value that cannot be represented by 'char',
// but that has the same lower bits as x.
signed int value = 1 + (1 << 8);
// Test relational operators.
clang_analyzer_eval((local + 1) < value); // expected-warning{{TRUE}}
clang_analyzer_eval(value > (local + 1)); // expected-warning{{TRUE}}
// Test equality operators.
clang_analyzer_eval((local + 1) != value); // expected-warning{{TRUE}}
clang_analyzer_eval(value != (local + 1)); // expected-warning{{TRUE}}
}
// This test is insurance in case we significantly change how SymExprs are
// evaluated.
size_t strlen(const char *s);
void PR12206_strlen(const char *x) {
size_t comparisonSize = sizeof(1 == 1);
// This test is useless if size_t isn't bigger than bool.
clang_analyzer_eval(sizeof(size_t) > comparisonSize); // expected-warning{{TRUE}}
// Create a value that requires more bits to store than a comparison result.
size_t value = 1UL;
value <<= 8 * comparisonSize;
value += 1;
// Constrain the length of x.
if (strlen(x) != value) return;
// Test relational operators.
clang_analyzer_eval(strlen(x) >= 2); // expected-warning{{TRUE}}
clang_analyzer_eval(2 <= strlen(x)); // expected-warning{{TRUE}}
// Test equality operators.
clang_analyzer_eval(strlen(x) != 1); // expected-warning{{TRUE}}
clang_analyzer_eval(1 != strlen(x)); // expected-warning{{TRUE}}
}