cb424d7448
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).
118 lines
4.7 KiB
C
118 lines
4.7 KiB
C
// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -ffreestanding -Wno-null-conversion -Wno-tautological-compare %s
|
|
#include <stdint.h>
|
|
|
|
typedef typeof(nullptr) nullptr_t;
|
|
|
|
struct A {};
|
|
|
|
__attribute__((overloadable)) int o1(char*);
|
|
__attribute__((overloadable)) void o1(uintptr_t);
|
|
|
|
nullptr_t f(nullptr_t null)
|
|
{
|
|
// Implicit conversions.
|
|
null = nullptr;
|
|
void *p = nullptr;
|
|
p = null;
|
|
int *pi = nullptr;
|
|
pi = null;
|
|
null = 0;
|
|
bool b = nullptr;
|
|
|
|
// Can't convert nullptr to integral implicitly.
|
|
uintptr_t i = nullptr; // expected-error-re {{initializing 'uintptr_t' (aka '{{.*}}') with an expression of incompatible type 'nullptr_t'}}
|
|
|
|
// Operators
|
|
(void)(null == nullptr);
|
|
(void)(null <= nullptr); // expected-error {{invalid operands to binary expression}}
|
|
(void)(null == 0);
|
|
(void)(null == (void*)0);
|
|
(void)((void*)0 == nullptr);
|
|
(void)(null <= 0); // expected-error {{invalid operands to binary expression}}
|
|
(void)(null <= (void*)0); // expected-error {{invalid operands to binary expression}}
|
|
(void)((void*)0 <= nullptr); // expected-error {{invalid operands to binary expression}}
|
|
(void)(0 == nullptr);
|
|
(void)(nullptr == 0);
|
|
(void)(nullptr <= 0); // expected-error {{invalid operands to binary expression}}
|
|
(void)(0 <= nullptr); // expected-error {{invalid operands to binary expression}}
|
|
(void)(1 > nullptr); // expected-error {{invalid operands to binary expression}}
|
|
(void)(1 != nullptr); // expected-error {{invalid operands to binary expression}}
|
|
(void)(1 + nullptr); // expected-error {{invalid operands to binary expression}}
|
|
(void)(0 ? nullptr : 0); // expected-error {{non-pointer operand type 'int' incompatible with nullptr}}
|
|
(void)(0 ? nullptr : (void*)0);
|
|
(void)(0 ? nullptr : (struct A){}); // expected-error {{non-pointer operand type 'struct A' incompatible with nullptr}}
|
|
(void)(0 ? (struct A){} : nullptr); // expected-error {{non-pointer operand type 'struct A' incompatible with nullptr}}
|
|
|
|
// Overloading
|
|
int t = o1(nullptr);
|
|
t = o1(null);
|
|
|
|
// nullptr is an rvalue, null is an lvalue
|
|
(void)&nullptr; // expected-error {{cannot take the address of an rvalue of type 'nullptr_t'}}
|
|
nullptr_t *pn = &null;
|
|
|
|
int *ip = *pn;
|
|
if (*pn) { }
|
|
}
|
|
|
|
__attribute__((overloadable)) void *g(void*);
|
|
__attribute__((overloadable)) bool g(bool);
|
|
|
|
// Test that we prefer g(void*) over g(bool).
|
|
static_assert(__builtin_types_compatible_p(typeof(g(nullptr)), void *), "");
|
|
|
|
void sent(int, ...) __attribute__((sentinel));
|
|
|
|
void g() {
|
|
// nullptr can be used as the sentinel value.
|
|
sent(10, nullptr);
|
|
}
|
|
|
|
void printf(const char*, ...) __attribute__((format(printf, 1, 2)));
|
|
|
|
void h() {
|
|
// Don't warn when using nullptr with %p.
|
|
printf("%p", nullptr);
|
|
}
|
|
|
|
static_assert(sizeof(nullptr_t) == sizeof(void*), "");
|
|
|
|
static_assert(!nullptr, "");
|
|
static_assert(!(bool){nullptr}, "");
|
|
|
|
static_assert(!(nullptr < nullptr), ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert(!(nullptr > nullptr), ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert( nullptr <= nullptr, ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert( nullptr >= nullptr, ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert( nullptr == nullptr, "");
|
|
static_assert(!(nullptr != nullptr), "");
|
|
|
|
static_assert(!(0 < nullptr), ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert(!(0 > nullptr), ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert( 0 <= nullptr, ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert( 0 >= nullptr, ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert( 0 == nullptr, "");
|
|
static_assert(!(0 != nullptr), "");
|
|
|
|
static_assert(!(nullptr < 0), ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert(!(nullptr > 0), ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert( nullptr <= 0, ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert( nullptr >= 0, ""); // expected-error {{invalid operands to binary expression}}
|
|
static_assert( nullptr == 0, "");
|
|
static_assert(!(nullptr != 0), "");
|
|
|
|
__attribute__((overloadable)) int f1(int*);
|
|
__attribute__((overloadable)) float f1(bool);
|
|
|
|
void test_f1() {
|
|
int ir = (f1)(nullptr);
|
|
}
|
|
|
|
// __nullptr keyword in C
|
|
void foo(void *);
|
|
void bar() { foo(__nullptr); }
|
|
static_assert(nullptr == __nullptr);
|
|
static_assert(__nullptr == 0); // Test that its value matches that of NULL
|
|
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
|
|
static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 1)); // Test that it's type is not the same as what NULL would generally have.
|