Files
RedBear-OS/local/recipes/dev/libclc/source/clang/test/Analysis/ArrayDelete.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

112 lines
5.4 KiB
C++

// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.ArrayDelete -std=c++11 -verify -analyzer-output=text %s
struct Base {
virtual ~Base() = default;
};
struct Derived : public Base {};
struct DoubleDerived : public Derived {};
Derived *get();
Base *create() {
Base *b = new Derived[3]; // expected-note{{Casting from 'Derived' to 'Base' here}}
return b;
}
void sink(Base *b) {
delete[] b; // expected-warning{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
// expected-note@-1{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
}
void sink_cast(Base *b) {
delete[] static_cast<Derived*>(b); // no-warning
}
void sink_derived(Derived *d) {
delete[] d; // no-warning
}
void same_function() {
Base *sd = new Derived[10]; // expected-note{{Casting from 'Derived' to 'Base' here}}
delete[] sd; // expected-warning{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
// expected-note@-1{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
Base *dd = new DoubleDerived[10]; // expected-note{{Casting from 'DoubleDerived' to 'Base' here}}
delete[] dd; // expected-warning{{Deleting an array of 'DoubleDerived' objects as their base class 'Base' is undefined}}
// expected-note@-1{{Deleting an array of 'DoubleDerived' objects as their base class 'Base' is undefined}}
}
void different_function() {
Base *assigned = get(); // expected-note{{Casting from 'Derived' to 'Base' here}}
delete[] assigned; // expected-warning{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
// expected-note@-1{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
Base *indirect;
indirect = get(); // expected-note{{Casting from 'Derived' to 'Base' here}}
delete[] indirect; // expected-warning{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
// expected-note@-1{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
Base *created = create(); // expected-note{{Calling 'create'}}
// expected-note@-1{{Returning from 'create'}}
delete[] created; // expected-warning{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
// expected-note@-1{{Deleting an array of 'Derived' objects as their base class 'Base' is undefined}}
Base *sb = new Derived[10]; // expected-note{{Casting from 'Derived' to 'Base' here}}
sink(sb); // expected-note{{Calling 'sink'}}
}
void safe_function() {
Derived *d = new Derived[10];
delete[] d; // no-warning
Base *b = new Derived[10];
delete[] static_cast<Derived*>(b); // no-warning
Base *sb = new Derived[10];
sink_cast(sb); // no-warning
Derived *sd = new Derived[10];
sink_derived(sd); // no-warning
}
void multiple_derived() {
Base *b = new DoubleDerived[10]; // expected-note{{Casting from 'DoubleDerived' to 'Base' here}}
delete[] b; // expected-warning{{Deleting an array of 'DoubleDerived' objects as their base class 'Base' is undefined}}
// expected-note@-1{{Deleting an array of 'DoubleDerived' objects as their base class 'Base' is undefined}}
Base *b2 = new DoubleDerived[10]; // expected-note{{Casting from 'DoubleDerived' to 'Base' here}}
Derived *d2 = static_cast<Derived*>(b2); // expected-note{{Casting from 'Base' to 'Derived' here}}
delete[] d2; // expected-warning{{Deleting an array of 'DoubleDerived' objects as their base class 'Derived' is undefined}}
// expected-note@-1{{Deleting an array of 'DoubleDerived' objects as their base class 'Derived' is undefined}}
Derived *d3 = new DoubleDerived[10]; // expected-note{{Casting from 'DoubleDerived' to 'Derived' here}}
Base *b3 = d3; // expected-note{{Casting from 'Derived' to 'Base' here}}
delete[] b3; // expected-warning{{Deleting an array of 'DoubleDerived' objects as their base class 'Base' is undefined}}
// expected-note@-1{{Deleting an array of 'DoubleDerived' objects as their base class 'Base' is undefined}}
Base *b4 = new DoubleDerived[10];
Derived *d4 = static_cast<Derived*>(b4);
DoubleDerived *dd4 = static_cast<DoubleDerived*>(d4);
delete[] dd4; // no-warning
Base *b5 = new DoubleDerived[10]; // expected-note{{Casting from 'DoubleDerived' to 'Base' here}}
DoubleDerived *dd5 = static_cast<DoubleDerived*>(b5); // expected-note{{Casting from 'Base' to 'DoubleDerived' here}}
Derived *d5 = dd5; // expected-note{{Casting from 'DoubleDerived' to 'Derived' here}}
delete[] d5; // expected-warning{{Deleting an array of 'DoubleDerived' objects as their base class 'Derived' is undefined}}
// expected-note@-1{{Deleting an array of 'DoubleDerived' objects as their base class 'Derived' is undefined}}
}
void unrelated_casts() {
Base *b = new DoubleDerived[10]; // expected-note{{Casting from 'DoubleDerived' to 'Base' here}}
Base &b2 = *b; // no-note: See the FIXME.
// FIXME: Displaying casts of reference types is not supported.
Derived &d2 = static_cast<Derived&>(b2); // no-note: See the FIXME.
Derived *d = &d2; // no-note: See the FIXME.
delete[] d; // expected-warning{{Deleting an array of 'DoubleDerived' objects as their base class 'Derived' is undefined}}
// expected-note@-1{{Deleting an array of 'DoubleDerived' objects as their base class 'Derived' is undefined}}
}