Files
RedBear-OS/local/recipes/dev/libclc/source/clang/test/Analysis/cxx23-assume-attribute.cpp
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

78 lines
2.3 KiB
C++

// RUN: %clang_analyze_cc1 -std=c++23 -triple x86_64-pc-linux-gnu \
// RUN: -analyzer-checker=core,debug.ExprInspection -verify %s
void clang_analyzer_warnIfReached();
template <typename T> void clang_analyzer_dump(T);
template <typename T> void clang_analyzer_value(T);
int ternary_in_builtin_assume(int a, int b) {
__builtin_assume(a > 10 ? b == 4 : b == 10);
clang_analyzer_value(a);
// expected-warning@-1 {{[-2147483648, 10]}}
// expected-warning@-2 {{[11, 2147483647]}}
clang_analyzer_dump(b); // expected-warning{{4}} expected-warning{{10}}
if (a > 20) {
clang_analyzer_dump(b + 100); // expected-warning {{104}}
return 2;
}
if (a > 10) {
clang_analyzer_dump(b + 200); // expected-warning {{204}}
return 1;
}
clang_analyzer_dump(b + 300); // expected-warning {{310}}
return 0;
}
// From: https://github.com/llvm/llvm-project/pull/116462#issuecomment-2517853226
int ternary_in_assume(int a, int b) {
[[assume(a > 10 ? b == 4 : b == 10)]];
clang_analyzer_value(a);
// expected-warning@-1 {{[-2147483648, 10]}}
// expected-warning@-2 {{[11, 2147483647]}}
clang_analyzer_dump(b); // expected-warning {{4}} expected-warning {{10}}
if (a > 20) {
clang_analyzer_dump(b + 100); // expected-warning {{104}}
return 2;
}
if (a > 10) {
clang_analyzer_dump(b + 200); // expected-warning {{204}}
return 1;
}
clang_analyzer_dump(b + 300); // expected-warning {{310}}
return 0;
}
int assume_and_fallthrough_at_the_same_attrstmt(int a, int b) {
[[assume(a == 2)]];
clang_analyzer_dump(a); // expected-warning {{2 S32b}}
// expected-warning-re@-1 {{reg_${{[0-9]+}}<int a>}} FIXME: We shouldn't have this dump.
switch (a) {
case 2:
[[fallthrough, assume(b == 30)]];
case 4: {
clang_analyzer_dump(b); // expected-warning {{30 S32b}}
// expected-warning-re@-1 {{reg_${{[0-9]+}}<int b>}} FIXME: We shouldn't have this dump.
return b;
}
}
// This code should be unreachable.
clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
[[assume(false)]]; // This should definitely make it so.
clang_analyzer_warnIfReached(); // no-warning
return 0;
}
void assume_opaque_gh151854_no_crash() {
extern bool opaque();
[[assume(opaque())]]; // no-crash
// expected-warning@-1 {{assumption is ignored because it contains (potential) side-effects}}
}