summaryrefslogtreecommitdiff
path: root/include/ruby/internal/attr
diff options
context:
space:
mode:
Diffstat (limited to 'include/ruby/internal/attr')
-rw-r--r--include/ruby/internal/attr/alloc_size.h32
-rw-r--r--include/ruby/internal/attr/artificial.h46
-rw-r--r--include/ruby/internal/attr/cold.h37
-rw-r--r--include/ruby/internal/attr/const.h46
-rw-r--r--include/ruby/internal/attr/constexpr.h85
-rw-r--r--include/ruby/internal/attr/deprecated.h59
-rw-r--r--include/ruby/internal/attr/diagnose_if.h42
-rw-r--r--include/ruby/internal/attr/enum_extensibility.h32
-rw-r--r--include/ruby/internal/attr/error.h32
-rw-r--r--include/ruby/internal/attr/flag_enum.h33
-rw-r--r--include/ruby/internal/attr/forceinline.h40
-rw-r--r--include/ruby/internal/attr/format.h38
-rw-r--r--include/ruby/internal/attr/maybe_unused.h38
-rw-r--r--include/ruby/internal/attr/noalias.h58
-rw-r--r--include/ruby/internal/attr/nodiscard.h45
-rw-r--r--include/ruby/internal/attr/noexcept.h91
-rw-r--r--include/ruby/internal/attr/noinline.h35
-rw-r--r--include/ruby/internal/attr/nonnull.h32
-rw-r--r--include/ruby/internal/attr/noreturn.h52
-rw-r--r--include/ruby/internal/attr/pure.h43
-rw-r--r--include/ruby/internal/attr/restrict.h45
-rw-r--r--include/ruby/internal/attr/returns_nonnull.h37
-rw-r--r--include/ruby/internal/attr/warning.h32
-rw-r--r--include/ruby/internal/attr/weakref.h32
24 files changed, 1062 insertions, 0 deletions
diff --git a/include/ruby/internal/attr/alloc_size.h b/include/ruby/internal/attr/alloc_size.h
new file mode 100644
index 0000000000..9dd79f15fc
--- /dev/null
+++ b/include/ruby/internal/attr/alloc_size.h
@@ -0,0 +1,32 @@
+#ifndef RBIMPL_ATTR_ALLOC_SIZE_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_ALLOC_SIZE_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_ALLOC_SIZE.
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((alloc_size))` */
+#if RBIMPL_HAS_ATTRIBUTE(alloc_size)
+# define RBIMPL_ATTR_ALLOC_SIZE(tuple) __attribute__((__alloc_size__ tuple))
+#else
+# define RBIMPL_ATTR_ALLOC_SIZE(tuple) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_ALLOC_SIZE_H */
diff --git a/include/ruby/internal/attr/artificial.h b/include/ruby/internal/attr/artificial.h
new file mode 100644
index 0000000000..7c9dc3e175
--- /dev/null
+++ b/include/ruby/internal/attr/artificial.h
@@ -0,0 +1,46 @@
+#ifndef RBIMPL_ATTR_ARTIFICIAL_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_ARTIFICIAL_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_ARTIFICIAL.
+ *
+ * ### Q&A ###
+ *
+ * - Q: What is this attribute? I don't get what GCC manual is talking about.
+ *
+ * - A: In short it is an attribute to manipulate GDB backtraces. The
+ * attribute makes the best sense when it comes with
+ * __attribute__((always_inline)). When a function annotated with this
+ * attribute gets inlined, and when you somehow look at a backtrace which
+ * includes such inlined call site, then the backtrace shows the caller
+ * and not the callee. This is handy for instance when an identical
+ * function is inlined more than once in a single big function. On such
+ * case it gets vital to know where the inlining happened in the callee.
+ * See also https://stackoverflow.com/a/21936099
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((artificial))` */
+#if RBIMPL_HAS_ATTRIBUTE(artificial)
+# define RBIMPL_ATTR_ARTIFICIAL() __attribute__((__artificial__))
+#else
+# define RBIMPL_ATTR_ARTIFICIAL() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_ARTIFICIAL_H */
diff --git a/include/ruby/internal/attr/cold.h b/include/ruby/internal/attr/cold.h
new file mode 100644
index 0000000000..85877b6136
--- /dev/null
+++ b/include/ruby/internal/attr/cold.h
@@ -0,0 +1,37 @@
+#ifndef RBIMPL_ATTR_COLD_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_COLD_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_COLD.
+ */
+#include "ruby/impl/compiler_is.h"
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((cold))` */
+#if RBIMPL_COMPILER_IS(SunPro)
+# /* Recent SunPro has __has_attribute, and is borken. */
+# /* It reports it has attribute cold, reality isn't (warnings issued). */
+# define RBIMPL_ATTR_COLD() /* void */
+#elif RBIMPL_HAS_ATTRIBUTE(cold)
+# define RBIMPL_ATTR_COLD() __attribute__((__cold__))
+#else
+# define RBIMPL_ATTR_COLD() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_COLD_H */
diff --git a/include/ruby/internal/attr/const.h b/include/ruby/internal/attr/const.h
new file mode 100644
index 0000000000..85892ea464
--- /dev/null
+++ b/include/ruby/internal/attr/const.h
@@ -0,0 +1,46 @@
+#ifndef RBIMPL_ATTR_CONST_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_CONST_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_CONST.
+ */
+#include "ruby/impl/compiler_since.h"
+#include "ruby/impl/has/attribute.h"
+#include "ruby/impl/has/declspec_attribute.h"
+
+/** Wraps (or simulates) `__attribute__((const))` */
+#if RBIMPL_HAS_ATTRIBUTE(const)
+# define RBIMPL_ATTR_CONST() __attribute__((__const__))
+#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noalias)
+# /* If a function can be a const, that is also a noalias. */
+# define RBIMPL_ATTR_CONST() __declspec(noalias)
+#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
+# define RBIMPL_ATTR_CONST() _Pragma("no_side_effect")
+#else
+# define RBIMPL_ATTR_CONST() /* void */
+#endif
+
+/** Enables #RBIMPL_ATTR_CONST iff. #RUBY_NDEBUG. */
+#if RUBY_NDEBUG
+# define RBIMPL_ATTR_CONST_ON_NDEBUG() RBIMPL_ATTR_CONST()
+#else
+# define RBIMPL_ATTR_CONST_ON_NDEBUG() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_CONST_H */
diff --git a/include/ruby/internal/attr/constexpr.h b/include/ruby/internal/attr/constexpr.h
new file mode 100644
index 0000000000..4b6cc81e3b
--- /dev/null
+++ b/include/ruby/internal/attr/constexpr.h
@@ -0,0 +1,85 @@
+#ifndef RBIMPL_ATTR_CONSTEXPR_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_CONSTEXPR_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief #RBIMPL_ATTR_CONSTEXPR.
+ */
+#include "ruby/impl/has/feature.h"
+#include "ruby/impl/compiler_is.h"
+#include "ruby/impl/token_paste.h"
+
+/** @cond INTERNAL_MACRO */
+#if ! defined(__cplusplus)
+# /* Makes no sense. */
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0
+
+#elif defined(__cpp_constexpr)
+# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cpp_constexpr >= 200704L)
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cpp_constexpr >= 201304L)
+
+#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0)
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 00)
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 00)
+
+#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 13, 0)
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L)
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L)
+
+#elif RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0)
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L)
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L)
+
+#elif RBIMPL_HAS_FEATURE(cxx_relaxed_constexpr)
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 1
+
+#elif RBIMPL_HAS_FEATURE(cxx_constexpr)
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0
+
+#else
+# /* :FIXME: icpc must have constexpr but don't know how to detect. */
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0
+# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0
+#endif
+/** @endcond */
+
+/** Wraps (or simulates) C++11 `constexpr`. */
+#if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14
+# define RBIMPL_ATTR_CONSTEXPR(_) constexpr
+
+#elif RBIMPL_HAS_ATTR_CONSTEXPR_CXX11
+# define RBIMPL_ATTR_CONSTEXPR(_) RBIMPL_TOKEN_PASTE(RBIMPL_ATTR_CONSTEXPR_, _)
+# define RBIMPL_ATTR_CONSTEXPR_CXX11 constexpr
+# define RBIMPL_ATTR_CONSTEXPR_CXX14 /* void */
+
+#else
+# define RBIMPL_ATTR_CONSTEXPR(_) /* void */
+#endif
+
+/** Enables #RBIMPL_ATTR_CONSTEXPR iff. #RUBY_NDEBUG. */
+#if RUBY_NDEBUG
+# define RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(_) RBIMPL_ATTR_CONSTEXPR(_)
+#else
+# define RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(_) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_CONSTEXPR_H */
diff --git a/include/ruby/internal/attr/deprecated.h b/include/ruby/internal/attr/deprecated.h
new file mode 100644
index 0000000000..c603d58a1f
--- /dev/null
+++ b/include/ruby/internal/attr/deprecated.h
@@ -0,0 +1,59 @@
+#ifndef RBIMPL_ATTR_DEPRECATED_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_DEPRECATED_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_DEPRECATED.
+ */
+#include "ruby/impl/compiler_since.h"
+#include "ruby/impl/has/attribute.h"
+#include "ruby/impl/has/c_attribute.h"
+#include "ruby/impl/has/cpp_attribute.h"
+#include "ruby/impl/has/declspec_attribute.h"
+#include "ruby/impl/has/extension.h"
+
+/** Wraps (or simulates) `[[deprecated]]` */
+#if RBIMPL_HAS_EXTENSION(attribute_deprecated_with_message)
+# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg))
+
+#elif RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0)
+# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg))
+
+#elif RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0)
+# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg))
+
+#elif RBIMPL_HAS_ATTRIBUTE(deprecated) /* but not with message. */
+# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__))
+
+#elif RBIMPL_COMPILER_SINCE(MSVC, 14, 0, 0)
+# define RBIMPL_ATTR_DEPRECATED(msg) __declspec(deprecated msg)
+
+#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(deprecated)
+# define RBIMPL_ATTR_DEPRECATED(msg) __declspec(deprecated)
+
+#elif RBIMPL_HAS_CPP_ATTRIBUTE(deprecated)
+# define RBIMPL_ATTR_DEPRECATED(msg) [[deprecated msg]]
+
+#elif RBIMPL_HAS_C_ATTRIBUTE(deprecated)
+# define RBIMPL_ATTR_DEPRECATED(msg) [[deprecated msg]]
+
+#else
+# define RBIMPL_ATTR_DEPRECATED(msg) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_DEPRECATED_H */
diff --git a/include/ruby/internal/attr/diagnose_if.h b/include/ruby/internal/attr/diagnose_if.h
new file mode 100644
index 0000000000..ba6e8626e3
--- /dev/null
+++ b/include/ruby/internal/attr/diagnose_if.h
@@ -0,0 +1,42 @@
+#ifndef RBIMPL_ATTR_DIAGNOSE_IF_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_DIAGNOSE_IF_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_DIAGNOSE_IF.
+ */
+#include "ruby/impl/has/attribute.h"
+#include "ruby/impl/warning_push.h"
+
+/** Wraps (or simulates) `__attribute__((diagnose_if))` */
+#if RBIMPL_COMPILER_BEFORE(Clang, 5, 0, 0)
+# /* https://bugs.llvm.org/show_bug.cgi?id=34319 */
+# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) /* void */
+
+#elif RBIMPL_HAS_ATTRIBUTE(diagnose_if)
+# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) \
+ RBIMPL_WARNING_PUSH() \
+ RBIMPL_WARNING_IGNORED(-Wgcc-compat) \
+ __attribute__((__diagnose_if__(_, __, ___))) \
+ RBIMPL_WARNING_POP()
+
+#else
+# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_DIAGNOSE_IF_H */
diff --git a/include/ruby/internal/attr/enum_extensibility.h b/include/ruby/internal/attr/enum_extensibility.h
new file mode 100644
index 0000000000..d5d25e03d7
--- /dev/null
+++ b/include/ruby/internal/attr/enum_extensibility.h
@@ -0,0 +1,32 @@
+#ifndef RBIMPL_ATTR_ENUM_EXTENSIBILITY_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_ENUM_EXTENSIBILITY_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief #RBIMPL_ATTR_ENUM_EXTENSIBILITY.
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((enum_extensibility))` */
+#if RBIMPL_HAS_ATTRIBUTE(enum_extensibility)
+# define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_) __attribute__((__enum_extensibility__(_)))
+#else
+# define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_ENUM_EXTENSIBILITY_H */
diff --git a/include/ruby/internal/attr/error.h b/include/ruby/internal/attr/error.h
new file mode 100644
index 0000000000..b46b306fb9
--- /dev/null
+++ b/include/ruby/internal/attr/error.h
@@ -0,0 +1,32 @@
+#ifndef RBIMPL_ATTR_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_ERROR_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_ERROR.
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((error))` */
+#if RBIMPL_HAS_ATTRIBUTE(error)
+# define RBIMPL_ATTR_ERROR(msg) __attribute__((__error__ msg))
+#else
+# define RBIMPL_ATTR_ERROR(msg) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_ERROR_H */
diff --git a/include/ruby/internal/attr/flag_enum.h b/include/ruby/internal/attr/flag_enum.h
new file mode 100644
index 0000000000..e769708d93
--- /dev/null
+++ b/include/ruby/internal/attr/flag_enum.h
@@ -0,0 +1,33 @@
+#ifndef RBIMPL_ATTR_FLAG_ENUM_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_FLAG_ENUM_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_FLAG_ENUM.
+ * @see https://clang.llvm.org/docs/AttributeReference.html#flag_enum
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((flag_enum)` */
+#if RBIMPL_HAS_ATTRIBUTE(flag_enum)
+# define RBIMPL_ATTR_FLAG_ENUM() __attribute__((__flag_enum__))
+#else
+# define RBIMPL_ATTR_FLAG_ENUM() /* void */
+#endif
+
+#endif /* RBIMPLATTR_FLAG_ENUM_H */
diff --git a/include/ruby/internal/attr/forceinline.h b/include/ruby/internal/attr/forceinline.h
new file mode 100644
index 0000000000..8d60a63437
--- /dev/null
+++ b/include/ruby/internal/attr/forceinline.h
@@ -0,0 +1,40 @@
+#ifndef RBIMPL_ATTR_FORCEINLINE_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_FORCEINLINE_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_FORCEINLINE.
+ */
+#include "ruby/impl/compiler_since.h"
+#include "ruby/impl/has/attribute.h"
+
+/**
+ * Wraps (or simulates) `__forceinline`. MSVC complains on declarations like
+ * `static inline __forceinline void foo()`. It seems MSVC's `inline` and
+ * `__forceinline` are mutually exclusive. We have to mimic that behaviour for
+ * non-MSVC compilers.
+ */
+#if RBIMPL_COMPILER_SINCE(MSVC, 12, 0, 0)
+# define RBIMPL_ATTR_FORCEINLINE() __forceinline
+#elif RBIMPL_HAS_ATTRIBUTE(always_inline)
+# define RBIMPL_ATTR_FORCEINLINE() __attribute__((__always_inline__)) inline
+#else
+# define RBIMPL_ATTR_FORCEINLINE() inline
+#endif
+
+#endif /* RBIMPL_ATTR_FORCEINLINE_H */
diff --git a/include/ruby/internal/attr/format.h b/include/ruby/internal/attr/format.h
new file mode 100644
index 0000000000..368c9f8797
--- /dev/null
+++ b/include/ruby/internal/attr/format.h
@@ -0,0 +1,38 @@
+#ifndef RBIMPL_ATTR_FORMAT_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_FORMAT_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_FORMAT.
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((format))` */
+#if RBIMPL_HAS_ATTRIBUTE(format)
+# define RBIMPL_ATTR_FORMAT(x, y, z) __attribute__((__format__(x, y, z)))
+#else
+# define RBIMPL_ATTR_FORMAT(x, y, z) /* void */
+#endif
+
+#if defined(__MINGW_PRINTF_FORMAT)
+# define RBIMPL_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
+#else
+# define RBIMPL_PRINTF_FORMAT __printf__
+#endif
+
+#endif /* RBIMPL_ATTR_FORMAT_H */
diff --git a/include/ruby/internal/attr/maybe_unused.h b/include/ruby/internal/attr/maybe_unused.h
new file mode 100644
index 0000000000..d554603db5
--- /dev/null
+++ b/include/ruby/internal/attr/maybe_unused.h
@@ -0,0 +1,38 @@
+#ifndef RBIMPL_ATTR_MAYBE_UNUSED_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_MAYBE_UNUSED_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_MAYBE_UNUSED.
+ */
+#include "ruby/impl/has/attribute.h"
+#include "ruby/impl/has/c_attribute.h"
+#include "ruby/impl/has/cpp_attribute.h"
+
+/** Wraps (or simulates) `[[maybe_unused]]` */
+#if RBIMPL_HAS_CPP_ATTRIBUTE(maybe_unused)
+# define RBIMPL_ATTR_MAYBE_UNUSED() [[maybe_unused]]
+#elif RBIMPL_HAS_C_ATTRIBUTE(maybe_unused)
+# define RBIMPL_ATTR_MAYBE_UNUSED() [[maybe_unused]]
+#elif RBIMPL_HAS_ATTRIBUTE(unused)
+# define RBIMPL_ATTR_MAYBE_UNUSED() __attribute__((__unused__))
+#else
+# define RBIMPL_ATTR_MAYBE_UNUSED() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_MAYBE_UNUSED */
diff --git a/include/ruby/internal/attr/noalias.h b/include/ruby/internal/attr/noalias.h
new file mode 100644
index 0000000000..0180d0c4ec
--- /dev/null
+++ b/include/ruby/internal/attr/noalias.h
@@ -0,0 +1,58 @@
+#ifndef RBIMPL_ATTR_NOALIAS_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_NOALIAS_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_NOALIAS.
+ *
+ * ### Q&A ###
+ *
+ * - Q: There are seemingly similar attributes named #RBIMPL_ATTR_CONST,
+ * #RBIMPL_ATTR_PURE, and #RBIMPL_ATTR_NOALIAS. What are the difference?
+ *
+ * - A: Allowed operations are different.
+ *
+ * - #RBIMPL_ATTR_CONST ... Functions attributed by this are not allowed to
+ * read/write _any_ pointers at all (there are exceptional situations
+ * when reading a pointer is possible but forget that; they are too
+ * exceptional to be useful). Just remember that everything pointer-
+ * related are NG.
+ *
+ * - #RBIMPL_ATTR_PURE ... Functions attributed by this can read any
+ * nonvolatile pointers, but no writes are allowed at all. The ability
+ * to read _any_ nonvolatile pointers makes it possible to mark ::VALUE-
+ * taking functions as being pure, as long as they are read-only.
+ *
+ * - #RBIMPL_ATTR_NOALIAS ... Can both read/write, but only through
+ * pointers passed to the function as parameters. This is a typical
+ * situation when you create a C++ non-static member function which only
+ * concerns `this`. No global variables are allowed to read/write. So
+ * this is not a super-set of being pure. If you want to read something,
+ * that has to be passed to the function as a pointer. ::VALUE -taking
+ * functions thus cannot be attributed as such.
+ */
+#include "ruby/impl/has/declspec_attribute.h"
+
+/** Wraps (or simulates) `__declspec((noalias))` */
+#if RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noalias)
+# define RBIMPL_ATTR_NOALIAS() __declspec(noalias)
+#else
+# define RBIMPL_ATTR_NOALIAS() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_NOALIAS_H */
diff --git a/include/ruby/internal/attr/nodiscard.h b/include/ruby/internal/attr/nodiscard.h
new file mode 100644
index 0000000000..ee3a1347df
--- /dev/null
+++ b/include/ruby/internal/attr/nodiscard.h
@@ -0,0 +1,45 @@
+#ifndef RBIMPL_ATTR_NODISCARD_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_NODISCARD_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_NODISCARD.
+ */
+#include "ruby/impl/has/attribute.h"
+#include "ruby/impl/has/c_attribute.h"
+#include "ruby/impl/has/cpp_attribute.h"
+
+/**
+ * Wraps (or simulates) `[[nodiscard]]`. In C++ (at least since C++20) a
+ * nodiscard attribute can have a message why the result shall not be ignoed.
+ * However GCC attribute and SAL annotation cannot take them.
+ */
+#if RBIMPL_HAS_CPP_ATTRIBUTE(nodiscard)
+# define RBIMPL_ATTR_NODISCARD() [[nodiscard]]
+#elif RBIMPL_HAS_C_ATTRIBUTE(nodiscard)
+# define RBIMPL_ATTR_NODISCARD() [[nodiscard]]
+#elif RBIMPL_HAS_ATTRIBUTE(warn_unused_result)
+# define RBIMPL_ATTR_NODISCARD() __attribute__((__warn_unused_result__))
+#elif defined(_Check_return_)
+# /* Take SAL definition. */
+# define RBIMPL_ATTR_NODISCARD() _Check_return_
+#else
+# define RBIMPL_ATTR_NODISCARD() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_NODISCARD_H */
diff --git a/include/ruby/internal/attr/noexcept.h b/include/ruby/internal/attr/noexcept.h
new file mode 100644
index 0000000000..ac0ec4c10d
--- /dev/null
+++ b/include/ruby/internal/attr/noexcept.h
@@ -0,0 +1,91 @@
+#ifndef RBIMPL_ATTR_NOEXCEPT_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_NOEXCEPT_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_NOEXCEPT.
+ *
+ * This isn't actually an attribute in C++ but who cares...
+ *
+ * Mainly due to aesthetic reasons, this one is rarely used in the project.
+ * But can be handy on occasions, especially when a function's noexcept-ness
+ * depends on its calling functions.
+ *
+ * ### Q&A ###
+ *
+ * - Q: Can a function that raises Ruby exceptions be attributed `noexcept`?
+ *
+ * - A: Yes. `noexcept` is about C++ exceptions, not Ruby's. They don't
+ * interface each other. You can safely attribute a function that raises
+ * Ruby exceptions as `noexcept`.
+ *
+ * - Q: How, then, can I assert that a function I wrote doesn't raise any Ruby
+ * exceptions?
+ *
+ * - A: `__attribute__((__leaf__))` is for that purpose. A function attributed
+ * as leaf can still throw C++ exceptions, but not Ruby's. Note however,
+ * that it's extremely difficult -- if not impossible -- to assert that a
+ * function doesn't raise any Ruby exceptions at all. Use of that
+ * attribute is not recommended; mere mortals can't properly use that by
+ * hand.
+ *
+ * - Q: Does it make sense to attribute an inline function `noexcept`?
+ *
+ * - A: I thought so before. But no, I don't think they are useful any longer.
+ *
+ * - When an inline function attributed `noexcept` actually doesn't throw
+ * any exceptions at all: these days I don't see any difference in
+ * generated assembly by adding/removing this attribute. C++ compilers
+ * get smarter and smarter. Today they can infer if it actually throws
+ * or not without any annotations by humans (correct me if I'm wrong).
+ *
+ * - When an inline function attributed `noexcepr` actually _does_ throw an
+ * exception: they have to call `std::terminate` then (C++ standard
+ * mandates so). This means exception handling routines are actually
+ * enforced, not omitted. This doesn't impact runtime performance (The
+ * Itanium C++ ABI has zero-cost exception handling), but does impact on
+ * generated binary size. This is bad.
+ */
+#include "ruby/impl/compiler_since.h"
+#include "ruby/impl/has/feature.h"
+
+/** Wraps (or simulates) C++11 `noexcept` */
+#if ! defined(__cplusplus)
+# /* Doesn't make sense. */
+# define RBIMPL_ATTR_NOEXCEPT(_) /* void */
+
+#elif RBIMPL_HAS_FEATURE(cxx_noexcept)
+# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
+
+#elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__
+# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
+
+#elif defined(__INTEL_CXX11_MODE__)
+# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
+
+#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0)
+# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
+
+#elif __cplusplus >= 201103L
+# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
+
+#else
+# define RBIMPL_ATTR_NOEXCEPT(_) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_NOEXCEPT_H */
diff --git a/include/ruby/internal/attr/noinline.h b/include/ruby/internal/attr/noinline.h
new file mode 100644
index 0000000000..c2cc007969
--- /dev/null
+++ b/include/ruby/internal/attr/noinline.h
@@ -0,0 +1,35 @@
+#ifndef RBIMPL_ATTR_NOINLINE_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_NOINLINE_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_NOINLINE.
+ */
+#include "ruby/impl/has/attribute.h"
+#include "ruby/impl/has/declspec_attribute.h"
+
+/** Wraps (or simulates) `__declspec(noinline)` */
+#if RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noinline)
+# define RBIMPL_ATTR_NOINLINE() __declspec(noinline)
+#elif RBIMPL_HAS_ATTRIBUTE(noinline)
+# define RBIMPL_ATTR_NOINLINE() __attribute__((__noinline__))
+#else
+# define RBIMPL_ATTR_NOINLINE() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_NOINLINE_H */
diff --git a/include/ruby/internal/attr/nonnull.h b/include/ruby/internal/attr/nonnull.h
new file mode 100644
index 0000000000..a1d0320e1d
--- /dev/null
+++ b/include/ruby/internal/attr/nonnull.h
@@ -0,0 +1,32 @@
+#ifndef RBIMPL_ATTR_NONNULL_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_NONNULL_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_NONNULL.
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((nonnull))` */
+#if RBIMPL_HAS_ATTRIBUTE(nonnull)
+# define RBIMPL_ATTR_NONNULL(list) __attribute__((__nonnull__ list))
+#else
+# define RBIMPL_ATTR_NONNULL(list) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_NONNULL_H */
diff --git a/include/ruby/internal/attr/noreturn.h b/include/ruby/internal/attr/noreturn.h
new file mode 100644
index 0000000000..66a9b42947
--- /dev/null
+++ b/include/ruby/internal/attr/noreturn.h
@@ -0,0 +1,52 @@
+#ifndef RBIMPL_ATTR_NORETURN_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_NORETURN_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_NORETURN.
+ */
+#include "ruby/impl/compiler_since.h"
+#include "ruby/impl/has/attribute.h"
+#include "ruby/impl/has/cpp_attribute.h"
+#include "ruby/impl/has/declspec_attribute.h"
+
+/** Wraps (or simulates) `[[noreturn]]` */
+#if RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
+# define RBIMPL_ATTR_NORETURN() _Pragma("does_not_return")
+
+#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noreturn)
+# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
+
+#elif RBIMPL_HAS_ATTRIBUTE(noreturn)
+# define RBIMPL_ATTR_NORETURN() __attribute__((__noreturn__))
+
+#elif RBIMPL_HAS_CPP_ATTRIBUTE(noreturn)
+# define RBIMPL_ATTR_NORETURN() [[noreturn]]
+
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112)
+# define RBIMPL_ATTR_NORETURN() _Noreturn
+
+#elif defined(_Noreturn)
+# /* glibc <sys/cdefs.h> has this macro. */
+# define RBIMPL_ATTR_NORETURN() _Noreturn
+
+#else
+# define RBIMPL_ATTR_NORETURN() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_NORETURN_H */
diff --git a/include/ruby/internal/attr/pure.h b/include/ruby/internal/attr/pure.h
new file mode 100644
index 0000000000..a5bb51b76f
--- /dev/null
+++ b/include/ruby/internal/attr/pure.h
@@ -0,0 +1,43 @@
+#ifndef RBIMPL_ATTR_PURE_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_PURE_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_PURE.
+ */
+#include "ruby/impl/compiler_since.h"
+#include "ruby/impl/has/attribute.h"
+#include "ruby/assert.h"
+
+/** Wraps (or simulates) `__attribute__((pure))` */
+#if RBIMPL_HAS_ATTRIBUTE(pure)
+# define RBIMPL_ATTR_PURE() __attribute__((__pure__))
+#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
+# define RBIMPL_ATTR_PURE() _Pragma("does_not_write_global_data")
+#else
+# define RBIMPL_ATTR_PURE() /* void */
+#endif
+
+/** Enables #RBIMPL_ATTR_PURE iff. #RUBY_NDEBUG. */
+#if RUBY_NDEBUG
+# define RBIMPL_ATTR_PURE_ON_NDEBUG() RBIMPL_ATTR_PURE()
+#else
+# define RBIMPL_ATTR_PURE_ON_NDEBUG() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_PURE_H */
diff --git a/include/ruby/internal/attr/restrict.h b/include/ruby/internal/attr/restrict.h
new file mode 100644
index 0000000000..518906f6da
--- /dev/null
+++ b/include/ruby/internal/attr/restrict.h
@@ -0,0 +1,45 @@
+#ifndef RBIMPL_ATTR_RESTRICT_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_RESTRICT_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_RESTRICT.
+ */
+#include "ruby/impl/compiler_since.h"
+#include "ruby/impl/has/attribute.h"
+#include "ruby/impl/token_paste.h"
+
+/* :FIXME: config.h includes conflicting `#define restrict`. MSVC can be
+ * detected using `RBIMPL_COMPILER_SINCE()`, but Clang & family cannot use
+ * `__has_declspec_attribute()` which involves macro substitution. */
+
+/** Wraps (or simulates) `__declspec(restrict)` */
+#if RBIMPL_COMPILER_SINCE(MSVC, 14, 0, 0)
+# define RBIMPL_ATTR_RESTRICT() __declspec(RBIMPL_TOKEN_PASTE(re, strict))
+
+#elif RBIMPL_HAS_ATTRIBUTE(malloc)
+# define RBIMPL_ATTR_RESTRICT() __attribute__((__malloc__))
+
+#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
+# define RBIMPL_ATTR_RESTRICT() _Pragma("returns_new_memory")
+
+#else
+# define RBIMPL_ATTR_RESTRICT() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_RESTRICT_H */
diff --git a/include/ruby/internal/attr/returns_nonnull.h b/include/ruby/internal/attr/returns_nonnull.h
new file mode 100644
index 0000000000..f656d70c8c
--- /dev/null
+++ b/include/ruby/internal/attr/returns_nonnull.h
@@ -0,0 +1,37 @@
+#ifndef RBIMPL_ATTR_RETURNS_NONNULL_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_RETURNS_NONNULL_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_RETURNS_NONNULL.
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((returns_nonnull))` */
+#if defined(_Ret_nonnull_)
+# /* Take SAL definition. */
+# define RBIMPL_ATTR_RETURNS_NONNULL() _Ret_nonnull_
+
+#elif RBIMPL_HAS_ATTRIBUTE(returns_nonnull)
+# define RBIMPL_ATTR_RETURNS_NONNULL() __attribute__((__returns_nonnull__))
+
+#else
+# define RBIMPL_ATTR_RETURNS_NONNULL() /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_RETURNS_NONNULL_H */
diff --git a/include/ruby/internal/attr/warning.h b/include/ruby/internal/attr/warning.h
new file mode 100644
index 0000000000..e7585e0417
--- /dev/null
+++ b/include/ruby/internal/attr/warning.h
@@ -0,0 +1,32 @@
+#ifndef RBIMPL_ATTR_WARNING_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_WARNING_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_WARNING.
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((warning))` */
+#if RBIMPL_HAS_ATTRIBUTE(warning)
+# define RBIMPL_ATTR_WARNING(msg) __attribute__((__warning__ msg))
+#else
+# define RBIMPL_ATTR_WARNING(msg) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_WARNING_H */
diff --git a/include/ruby/internal/attr/weakref.h b/include/ruby/internal/attr/weakref.h
new file mode 100644
index 0000000000..769ce017e0
--- /dev/null
+++ b/include/ruby/internal/attr/weakref.h
@@ -0,0 +1,32 @@
+#ifndef RBIMPL_ATTR_WEAKREF_H /*-*-C++-*-vi:se ft=cpp:*/
+#define RBIMPL_ATTR_WEAKREF_H
+/**
+ * @file
+ * @author Ruby developers <ruby-core@ruby-lang.org>
+ * @copyright This file is a part of the programming language Ruby.
+ * Permission is hereby granted, to either redistribute and/or
+ * modify this file, provided that the conditions mentioned in the
+ * file COPYING are met. Consult the file for details.
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
+ * implementation details. Don't take them as canon. They could
+ * rapidly appear then vanish. The name (path) of this header file
+ * is also an implementation detail. Do not expect it to persist
+ * at the place it is now. Developers are free to move it anywhere
+ * anytime at will.
+ * @note To ruby-core: remember that this header can be possibly
+ * recursively included from extension libraries written in C++.
+ * Do not expect for instance `__VA_ARGS__` is always available.
+ * We assume C99 for ruby itself but we don't assume languages of
+ * extension libraries. They could be written in C++98.
+ * @brief Defines #RBIMPL_ATTR_WEAKREF.
+ */
+#include "ruby/impl/has/attribute.h"
+
+/** Wraps (or simulates) `__attribute__((weakref))` */
+#if RBIMPL_HAS_ATTRIBUTE(weakref)
+# define RBIMPL_ATTR_WEAKREF(sym) __attribute__((__weakref__(# sym)))
+#else
+# define RBIMPL_ATTR_WEAKREF(sym) /* void */
+#endif
+
+#endif /* RBIMPL_ATTR_WEAKREF_H */