aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEnji Cooper <ngie@FreeBSD.org>2026-02-15 01:57:42 +0000
committerEnji Cooper <ngie@FreeBSD.org>2026-02-15 02:12:44 +0000
commite8dbf2b6df199526a660f81de07d17925cfd8518 (patch)
treecd0c09449bea5df56ef67059e797737d70587070 /include
parent56a7ce8416d181a2060d7a428aed9c3c6a431e6d (diff)
Diffstat (limited to 'include')
-rw-r--r--include/t_stddef.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/include/t_stddef.c b/include/t_stddef.c
new file mode 100644
index 000000000000..b5f2c89b86a4
--- /dev/null
+++ b/include/t_stddef.c
@@ -0,0 +1,127 @@
+/* $NetBSD: t_stddef.c,v 1.1 2025/04/01 00:33:55 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2025 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Include <stddef.h> first to verify it declares everything we need.
+ */
+#include <stddef.h>
+
+#if __STDC_VERSION__ - 0 >= 202311L
+#if __STDC_VERSION_STDDEF_H__ - 0 < 202311L
+#error __STDC_VERSION_STDDEF_H__ not defined appropriately
+#endif
+#endif
+
+typedef ptrdiff_t nbtest_ptrdiff_t;
+typedef size_t nbtest_size_t;
+#if __STDC_VERSION__ - 0 >= 201112L
+typedef max_align_t nbtest_max_align_t;
+#endif
+typedef wchar_t nbtest_wchar_t;
+#if __STDC_VERSION__ - 0 >= 202311L
+typedef nullptr_t nbtest_nullptr_t;
+#endif
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_stddef.c,v 1.1 2025/04/01 00:33:55 riastradh Exp $");
+
+#include <atf-c.h>
+#include <stdalign.h>
+
+ATF_TC(macros);
+ATF_TC_HEAD(macros, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test <stddef.h> macros work");
+}
+ATF_TC_BODY(macros, tc)
+{
+ void *volatile pNULL = NULL;
+#if __STDC_VERSION__ - 0 >= 202311L
+ void *volatile pnullptr = nullptr;
+#endif
+ struct s { char x[3], y; };
+ size_t o;
+
+ ATF_CHECK(!pNULL);
+#if __STDC_VERSION__ - 0 >= 202311L
+ ATF_CHECK(!pnullptr);
+#endif
+
+#if __STDC_VERSION__ - 0 >= 202311L
+ volatile enum { A, B } x = A;
+ switch (x) {
+ case A:
+ break;
+ case B:
+ default:
+ unreachable();
+ }
+#endif
+
+ ATF_CHECK_MSG((o = offsetof(struct s, y)) == 3,
+ "o=%zu", o);
+}
+
+ATF_TC(types);
+ATF_TC_HEAD(types, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test <stddef.h> types are reasonable");
+}
+ATF_TC_BODY(types, tc)
+{
+
+#ifdef __GNUC__
+ char *p, *q;
+ ATF_CHECK(__builtin_types_compatible_p(ptrdiff_t, typeof(p - q)));
+ ATF_CHECK(__builtin_types_compatible_p(size_t, typeof(sizeof(p))));
+#if __STDC_VERSION__ - 0 >= 202311L
+ ATF_CHECK(__builtin_types_compatible_p(nullptr_t, typeof(nullptr)));
+#endif
+#endif
+
+#if __STDC_VERSION__ - 0 >= 201112L
+ size_t a;
+ ATF_CHECK_MSG((a = alignof(max_align_t)) >= alignof(long long),
+ "a=%zu", a);
+ ATF_CHECK_MSG((a = alignof(max_align_t)) >= alignof(long double),
+ "a=%zu", a);
+ ATF_CHECK_MSG((a = alignof(max_align_t)) >= alignof(void *),
+ "a=%zu", a);
+ ATF_CHECK_MSG((a = alignof(max_align_t)) >= alignof(int (*)(void)),
+ "a=%zu", a);
+#endif
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, macros);
+ ATF_TP_ADD_TC(tp, types);
+
+ return atf_no_error();
+}