Blame gl/attribute.h

Packit Service 991b93
/* ATTRIBUTE_* macros for using attributes in GCC and similar compilers
Packit Service 991b93
Packit Service 991b93
   Copyright 2020 Free Software Foundation, Inc.
Packit Service 991b93
Packit Service 991b93
   This program is free software: you can redistribute it and/or modify it
Packit Service 991b93
   under the terms of the GNU Lesser General Public License as published
Packit Service 991b93
   by the Free Software Foundation; either version 2.1 of the License, or
Packit Service 991b93
   (at your option) any later version.
Packit Service 991b93
Packit Service 991b93
   This program is distributed in the hope that it will be useful,
Packit Service 991b93
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 991b93
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 991b93
   Lesser General Public License for more details.
Packit Service 991b93
Packit Service 991b93
   You should have received a copy of the GNU Lesser General Public License
Packit Service 991b93
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit Service 991b93
Packit Service 991b93
/* Written by Paul Eggert.  */
Packit Service 991b93
Packit Service 991b93
/* Provide public ATTRIBUTE_* names for the private _GL_ATTRIBUTE_*
Packit Service 991b93
   macros used within Gnulib.  */
Packit Service 991b93
Packit Service 991b93
/* These attributes can be placed in two ways:
Packit Service 991b93
     - At the start of a declaration (i.e. even before storage-class
Packit Service 991b93
       specifiers!); then they apply to all entities that are declared
Packit Service 991b93
       by the declaration.
Packit Service 991b93
     - Immediately after the name of an entity being declared by the
Packit Service 991b93
       declaration; then they apply to that entity only.  */
Packit Service 991b93
Packit Service 991b93
#ifndef _GL_ATTRIBUTE_H
Packit Service 991b93
#define _GL_ATTRIBUTE_H
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* This file defines two types of attributes:
Packit Service 991b93
   * C2X standard attributes.  These have macro names that do not begin with
Packit Service 991b93
     'ATTRIBUTE_'.
Packit Service 991b93
   * Selected GCC attributes; see:
Packit Service 991b93
     https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
Packit Service 991b93
     https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
Packit Service 991b93
     https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html
Packit Service 991b93
     These names begin with 'ATTRIBUTE_' to avoid name clashes.  */
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* =============== Attributes for specific kinds of functions =============== */
Packit Service 991b93
Packit Service 991b93
/* Attributes for functions that should not be used.  */
Packit Service 991b93
Packit Service 991b93
/* Warn if the entity is used.  */
Packit Service 991b93
/* Applies to:
Packit Service 991b93
     - function, variable,
Packit Service 991b93
     - struct, union, struct/union member,
Packit Service 991b93
     - enumeration, enumeration item,
Packit Service 991b93
     - typedef,
Packit Service 991b93
   in C++ also: namespace, class, template specialization.  */
Packit Service 991b93
#define DEPRECATED _GL_ATTRIBUTE_DEPRECATED
Packit Service 991b93
Packit Service 991b93
/* If a function call is not optimized way, warn with MSG.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_WARNING(msg) _GL_ATTRIBUTE_WARNING (msg)
Packit Service 991b93
Packit Service 991b93
/* If a function call is not optimized way, report an error with MSG.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_ERROR(msg) _GL_ATTRIBUTE_ERROR (msg)
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* Attributes for memory-allocating functions.  */
Packit Service 991b93
Packit Service 991b93
/* The function returns a pointer to freshly allocated memory.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_MALLOC _GL_ATTRIBUTE_MALLOC
Packit Service 991b93
Packit Service 991b93
/* ATTRIBUTE_ALLOC_SIZE ((N)) - The Nth argument of the function
Packit Service 991b93
   is the size of the returned memory block.
Packit Service 991b93
   ATTRIBUTE_ALLOC_SIZE ((M, N)) - Multiply the Mth and Nth arguments
Packit Service 991b93
   to determine the size of the returned memory block.  */
Packit Service 991b93
/* Applies to: function, pointer to function, function types.  */
Packit Service 991b93
#define ATTRIBUTE_ALLOC_SIZE(args) _GL_ATTRIBUTE_ALLOC_SIZE (args)
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* Attributes for variadic functions.  */
Packit Service 991b93
Packit Service 991b93
/* The variadic function expects a trailing NULL argument.
Packit Service 991b93
   ATTRIBUTE_SENTINEL () - The last argument is NULL.
Packit Service 991b93
   ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_SENTINEL(pos) _GL_ATTRIBUTE_SENTINEL (pos)
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* ================== Attributes for compiler diagnostics ================== */
Packit Service 991b93
Packit Service 991b93
/* Attributes that help the compiler diagnose programmer mistakes.
Packit Service 991b93
   Some of them may also help for some compiler optimizations.  */
Packit Service 991b93
Packit Service 991b93
/* ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)) -
Packit Service 991b93
   The STRING-INDEXth function argument is a format string of style
Packit Service 991b93
   ARCHETYPE, which is one of:
Packit Service 991b93
     printf, gnu_printf
Packit Service 991b93
     scanf, gnu_scanf,
Packit Service 991b93
     strftime, gnu_strftime,
Packit Service 991b93
     strfmon,
Packit Service 991b93
   or the same thing prefixed and suffixed with '__'.
Packit Service 991b93
   If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
Packit Service 991b93
   are suitable for the format string.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_FORMAT(spec) _GL_ATTRIBUTE_FORMAT (spec)
Packit Service 991b93
Packit Service 991b93
/* ATTRIBUTE_NONNULL ((N1, N2,...)) - Arguments N1, N2,... must not be NULL.
Packit Service 991b93
   ATTRIBUTE_NONNULL () - All pointer arguments must not be null.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_NONNULL(args) _GL_ATTRIBUTE_NONNULL (args)
Packit Service 991b93
Packit Service 991b93
/* The function's return value is a non-NULL pointer.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_RETURNS_NONNULL _GL_ATTRIBUTE_RETURNS_NONNULL
Packit Service 991b93
Packit Service 991b93
/* Warn if the caller does not use the return value,
Packit Service 991b93
   unless the caller uses something like ignore_value.  */
Packit Service 991b93
/* Applies to: function, enumeration, class.  */
Packit Service 991b93
#define NODISCARD _GL_ATTRIBUTE_NODISCARD
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* Attributes that disable false alarms when the compiler diagnoses
Packit Service 991b93
   programmer "mistakes".  */
Packit Service 991b93
Packit Service 991b93
/* Do not warn if the entity is not used.  */
Packit Service 991b93
/* Applies to:
Packit Service 991b93
     - function, variable,
Packit Service 991b93
     - struct, union, struct/union member,
Packit Service 991b93
     - enumeration, enumeration item,
Packit Service 991b93
     - typedef,
Packit Service 991b93
   in C++ also: class.  */
Packit Service 991b93
#define MAYBE_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
Packit Service 991b93
Packit Service 991b93
/* The contents of a character array is not meant to be NUL-terminated.  */
Packit Service 991b93
/* Applies to: struct/union members and variables that are arrays of element
Packit Service 991b93
   type '[[un]signed] char'.  */
Packit Service 991b93
#define ATTRIBUTE_NONSTRING _GL_ATTRIBUTE_NONSTRING
Packit Service 991b93
Packit Service 991b93
/* Do not warn if control flow falls through to the immediately
Packit Service 991b93
   following 'case' or 'default' label.  */
Packit Service 991b93
/* Applies to: Empty statement (;), inside a 'switch' statement.  */
Packit Service 991b93
#define FALLTHROUGH _GL_ATTRIBUTE_FALLTHROUGH
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* ================== Attributes for debugging information ================== */
Packit Service 991b93
Packit Service 991b93
/* Attributes regarding debugging information emitted by the compiler.  */
Packit Service 991b93
Packit Service 991b93
/* Omit the function from stack traces when debugging.  */
Packit Service 991b93
/* Applies to: function.  */
Packit Service 991b93
#define ATTRIBUTE_ARTIFICIAL _GL_ATTRIBUTE_ARTIFICIAL
Packit Service 991b93
Packit Service 991b93
/* Make the entity visible to debuggers etc., even with '-fwhole-program'.  */
Packit Service 991b93
/* Applies to: functions, variables.  */
Packit Service 991b93
#define ATTRIBUTE_EXTERNALLY_VISIBLE _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* ========== Attributes that mainly direct compiler optimizations ========== */
Packit Service 991b93
Packit Service 991b93
/* The function does not throw exceptions.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_NOTHROW
Packit Service 991b93
Packit Service 991b93
/* Do not inline the function.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_NOINLINE _GL_ATTRIBUTE_NOINLINE
Packit Service 991b93
Packit Service 991b93
/* Always inline the function, and report an error if the compiler
Packit Service 991b93
   cannot inline.  */
Packit Service 991b93
/* Applies to: function.  */
Packit Service 991b93
#define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE
Packit Service 991b93
Packit Service 991b93
/* The function does not affect observable state, and always returns a value.
Packit Service 991b93
   Compilers can omit duplicate calls with the same arguments if
Packit Service 991b93
   observable state is not changed between calls.  (This attribute is
Packit Service 991b93
   looser than ATTRIBUTE_CONST.)  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE
Packit Service 991b93
Packit Service 991b93
/* The function neither depends on nor affects observable state,
Packit Service 991b93
   and always returns a value.  Compilers can omit duplicate calls with
Packit Service 991b93
   the same arguments.  (This attribute is stricter than ATTRIBUTE_PURE.)  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
Packit Service 991b93
Packit Service 991b93
/* The function is rarely executed.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_COLD _GL_ATTRIBUTE_COLD
Packit Service 991b93
Packit Service 991b93
/* If called from some other compilation unit, the function executes
Packit Service 991b93
   code from that unit only by return or by exception handling,
Packit Service 991b93
   letting the compiler optimize that unit more aggressively.  */
Packit Service 991b93
/* Applies to: functions.  */
Packit Service 991b93
#define ATTRIBUTE_LEAF _GL_ATTRIBUTE_LEAF
Packit Service 991b93
Packit Service 991b93
/* For struct members: The member has the smallest possible alignment.
Packit Service 991b93
   For struct, union, class: All members have the smallest possible alignment,
Packit Service 991b93
   minimizing the memory required.  */
Packit Service 991b93
/* Applies to: struct members, struct, union,
Packit Service 991b93
   in C++ also: class.  */
Packit Service 991b93
#define ATTRIBUTE_PACKED _GL_ATTRIBUTE_PACKED
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* ================ Attributes that make invalid code valid ================ */
Packit Service 991b93
Packit Service 991b93
/* Attributes that prevent fatal compiler optimizations for code that is not
Packit Service 991b93
   fully ISO C compliant.  */
Packit Service 991b93
Packit Service 991b93
/* Pointers to the type may point to the same storage as pointers to
Packit Service 991b93
   other types, thus disabling strict aliasing optimization.  */
Packit Service 991b93
/* Applies to: types.  */
Packit Service 991b93
#define ATTRIBUTE_MAY_ALIAS _GL_ATTRIBUTE_MAY_ALIAS
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
#endif /* _GL_ATTRIBUTE_H */