1/*
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#ifndef SHARE_UTILITIES_COMPILERWARNINGS_GCC_HPP
26#define SHARE_UTILITIES_COMPILERWARNINGS_GCC_HPP
27
28// Macros related to control of compiler warnings.
29
30// Diagnostic pragmas like the ones defined below in PRAGMA_FORMAT_NONLITERAL_IGNORED
31// were only introduced in GCC 4.2. Because we have no other possibility to ignore
32// these warnings for older versions of GCC, we simply don't decorate our printf-style
33// functions with __attribute__(format) in that case.
34#if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ > 4)
35#ifndef ATTRIBUTE_PRINTF
36#define ATTRIBUTE_PRINTF(fmt,vargs) __attribute__((format(printf, fmt, vargs)))
37#endif
38#ifndef ATTRIBUTE_SCANF
39#define ATTRIBUTE_SCANF(fmt,vargs) __attribute__((format(scanf, fmt, vargs)))
40#endif
41#endif // gcc version check
42
43#define PRAGMA_DISABLE_GCC_WARNING_AUX(x) _Pragma(#x)
44#define PRAGMA_DISABLE_GCC_WARNING(option_string) \
45 PRAGMA_DISABLE_GCC_WARNING_AUX(GCC diagnostic ignored option_string)
46
47#define PRAGMA_FORMAT_NONLITERAL_IGNORED \
48 PRAGMA_DISABLE_GCC_WARNING("-Wformat-nonliteral") \
49 PRAGMA_DISABLE_GCC_WARNING("-Wformat-security")
50
51#define PRAGMA_FORMAT_IGNORED PRAGMA_DISABLE_GCC_WARNING("-Wformat")
52
53#if defined(__clang_major__) && \
54 (__clang_major__ >= 4 || \
55 (__clang_major__ >= 3 && __clang_minor__ >= 1)) || \
56 ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
57// Tested to work with clang version 3.1 and better.
58#define PRAGMA_DIAG_PUSH _Pragma("GCC diagnostic push")
59#define PRAGMA_DIAG_POP _Pragma("GCC diagnostic pop")
60
61#endif // clang/gcc version check
62
63#endif // SHARE_UTILITIES_COMPILERWARNINGS_GCC_HPP
64