]> git.proxmox.com Git - mirror_frr.git/blame - lib/compiler.h
zebra: Allow ns delete to happen after under/over flow checks
[mirror_frr.git] / lib / compiler.h
CommitLineData
de1a880c
DL
1/*
2 * Copyright (c) 2015-2017 David Lamparter, for NetDEF, Inc.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _FRR_COMPILER_H
18#define _FRR_COMPILER_H
19
20/* function attributes, use like
21 * void prototype(void) __attribute__((_CONSTRUCTOR(100)));
22 */
23#if defined(__clang__)
996c9314 24#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 5)
de1a880c 25# define _RET_NONNULL , returns_nonnull
996c9314 26#endif
bd27ea43
DL
27#if __has_attribute(fallthrough)
28# define _FALLTHROUGH __attribute__((fallthrough));
29#endif
de1a880c
DL
30# define _CONSTRUCTOR(x) constructor(x)
31#elif defined(__GNUC__)
996c9314 32#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
de1a880c 33# define _RET_NONNULL , returns_nonnull
996c9314
LB
34#endif
35#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
de1a880c
DL
36# define _CONSTRUCTOR(x) constructor(x)
37# define _DESTRUCTOR(x) destructor(x)
38# define _ALLOC_SIZE(x) alloc_size(x)
996c9314 39#endif
bd27ea43
DL
40#if __GNUC__ >= 7
41# define _FALLTHROUGH __attribute__((fallthrough));
42#endif
de1a880c
DL
43#endif
44
45#ifdef __sun
46/* Solaris doesn't do constructor priorities due to linker restrictions */
996c9314
LB
47#undef _CONSTRUCTOR
48#undef _DESTRUCTOR
de1a880c
DL
49#endif
50
51/* fallback versions */
52#ifndef _RET_NONNULL
53# define _RET_NONNULL
54#endif
55#ifndef _CONSTRUCTOR
56# define _CONSTRUCTOR(x) constructor
57#endif
58#ifndef _DESTRUCTOR
59# define _DESTRUCTOR(x) destructor
60#endif
61#ifndef _ALLOC_SIZE
62# define _ALLOC_SIZE(x)
63#endif
bd27ea43
DL
64#ifndef _FALLTHROUGH
65#define _FALLTHROUGH
66#endif
de1a880c
DL
67
68/*
69 * for warnings on macros, put in the macro content like this:
70 * #define MACRO BLA CPP_WARN("MACRO has been deprecated")
71 */
72#define CPP_STR(X) #X
73
74#if defined(__ICC)
75#define CPP_NOTICE(text) _Pragma(CPP_STR(message __FILE__ ": " text))
76#define CPP_WARN(text) CPP_NOTICE(text)
77
78#elif (defined(__GNUC__) \
79 && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) \
80 || (defined(__clang__) \
81 && (__clang_major__ >= 4 \
82 || (__clang_major__ == 3 && __clang_minor__ >= 5)))
83#define CPP_WARN(text) _Pragma(CPP_STR(GCC warning text))
84#define CPP_NOTICE(text) _Pragma(CPP_STR(message text))
85
86#else
87#define CPP_WARN(text)
ec40eaf9 88#define CPP_NOTICE(text)
de1a880c
DL
89#endif
90
91#endif /* _FRR_COMPILER_H */