Coverage Report

Created: 2025-07-18 06:25

/src/gpsd/gpsd-3.26.2~dev/include/compiler.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * compiler.h - compiler specific macros
3
 *
4
 * This file is Copyright 2010 by the GPSD project
5
 * SPDX-License-Identifier: BSD-2-clause
6
 *
7
 * Calling file needs to have previously included "gpsd_config.h"
8
 */
9
#ifndef _GPSD_COMPILER_H_
10
#define _GPSD_COMPILER_H_
11
12
#ifndef GPSD_CONFIG_H
13
    #error "Missing GPSD_CONFIG_H"
14
#endif
15
16
/*
17
 * Tell GCC that we want thread-safe behavior with _REENTRANT;
18
 * in particular, errno must be thread-local.
19
 * Tell POSIX-conforming implementations with _POSIX_THREAD_SAFE_FUNCTIONS.
20
 * See http://www.unix.org/whitepapers/reentrant.html
21
 */
22
#ifndef _REENTRANT
23
    #define _REENTRANT
24
#endif
25
#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
26
    #define _POSIX_THREAD_SAFE_FUNCTIONS
27
#endif
28
29
30
// Macro for declaring function with printf-like arguments.
31
# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
32
#define PRINTF_FUNC(format_index, arg_index) \
33
    __attribute__((__format__(__printf__, format_index, arg_index)))
34
#else
35
    #define PRINTF_FUNC(format_index, arg_indx)
36
#endif
37
38
// Macro for declaring function arguments unused.
39
#if defined(__GNUC__) || defined(__clang__)
40
    #define UNUSED __attribute__((unused))
41
#else
42
    #define UNUSED
43
#endif
44
45
// Macro to suppress FALLTHROUGH warnings
46
#if defined(__GNUC__) && __GNUC__ >= 7
47
    #define FALLTHROUGH __attribute__((fallthrough));
48
// At least one Clang 6 version advertises fallthrough and then chokes on it
49
#elif defined(__clang__) && __clang_major__ > 6
50
    #ifndef __has_attribute         // For backwards compatibility
51
        #define __has_attribute(x) 0
52
    #endif
53
54
    #if __has_attribute(fallthrough)
55
137M
        #define FALLTHROUGH __attribute__((fallthrough));
56
    #endif
57
#endif
58
59
#ifndef FALLTHROUGH
60
    #define FALLTHROUGH
61
#endif
62
63
/*
64
 * Macro for compile-time checking if argument is an array.
65
 * It expands to constant expression with int value 0.
66
 */
67
#if defined(__GNUC__)
68
0
    #define COMPILE_CHECK_IS_ARRAY(arr) ( \
69
0
        0 * (int) sizeof(({ \
70
0
            struct { \
71
0
                int unused_int; \
72
0
                __typeof__(arr) unused_arr; \
73
0
            } zero_init = {0}; \
74
0
            __typeof__(arr) arg_is_not_array UNUSED = { \
75
0
                zero_init.unused_arr[0], \
76
0
            }; \
77
0
            1; \
78
0
        })) \
79
0
    )
80
#else
81
    #define COMPILE_CHECK_IS_ARRAY(arr) 0
82
#endif
83
84
// Needed because 4.x versions of GCC are really annoying
85
// FIXME: in 20202, do we care about gcc 4?
86
#define ignore_return(funcall) \
87
    do { \
88
        UNUSED ssize_t locresult = (funcall); \
89
        assert(locresult != -23); \
90
    } while (0)
91
92
#ifdef __COVERITY__
93
    // do nothing
94
#elif defined(__cplusplus)
95
    // we are C++
96
    #if __cplusplus >= 201103L
97
        /* C++ before C++11 can not handle stdatomic.h or atomic
98
         * atomic is just C++ for stdatomic.h */
99
        #include <atomic>
100
    #endif
101
#elif defined(HAVE_STDATOMIC_H)
102
    // we are C and atomics are in C98 and newer
103
    #include <stdatomic.h>
104
#elif defined(HAVE_OSATOMIC_H)
105
    // do it the OS X way
106
    #include <libkern/OSAtomic.h>
107
#endif  // HAVE_OSATOMIC_H
108
109
// prevent instruction reordering across any call to this function
110
static inline void memory_barrier(void)
111
0
{
112
#ifdef __COVERITY__
113
    // do nothing
114
#elif defined(__cplusplus)
115
    // we are C++
116
    #if __cplusplus >= 201103L
117
        // C++11 and later has atomics, earlier do not
118
        std::atomic_thread_fence(std::memory_order_seq_cst);
119
    #endif
120
#elif defined HAVE_STDATOMIC_H
121
    // we are C and atomics are in C98 and newer
122
0
    atomic_thread_fence(memory_order_seq_cst);
123
#elif defined(HAVE_OSATOMIC_H)
124
    // do it the OS X way
125
    OSMemoryBarrier();
126
#elif defined(__GNUC__)
127
    __asm__ __volatile__ ("" : : : "memory");
128
#endif
129
0
}
Unexecuted instantiation: FuzzPacket.c:memory_barrier
Unexecuted instantiation: packet.c:memory_barrier
Unexecuted instantiation: driver_rtcm2.c:memory_barrier
Unexecuted instantiation: isgps.c:memory_barrier
Unexecuted instantiation: libgpsd_core.c:memory_barrier
Unexecuted instantiation: net_gnss_dispatch.c:memory_barrier
Unexecuted instantiation: net_ntrip.c:memory_barrier
Unexecuted instantiation: ppsthread.c:memory_barrier
Unexecuted instantiation: pseudonmea.c:memory_barrier
Unexecuted instantiation: serial.c:memory_barrier
Unexecuted instantiation: timebase.c:memory_barrier
Unexecuted instantiation: bsd_base64.c:memory_barrier
Unexecuted instantiation: driver_nmea0183.c:memory_barrier
Unexecuted instantiation: driver_nmea2000.c:memory_barrier
Unexecuted instantiation: drivers.c:memory_barrier
Unexecuted instantiation: driver_sirf.c:memory_barrier
Unexecuted instantiation: driver_skytraq.c:memory_barrier
Unexecuted instantiation: driver_superstar2.c:memory_barrier
Unexecuted instantiation: driver_tsip.c:memory_barrier
Unexecuted instantiation: driver_ubx.c:memory_barrier
Unexecuted instantiation: driver_zodiac.c:memory_barrier
Unexecuted instantiation: geoid.c:memory_barrier
Unexecuted instantiation: net_dgpsip.c:memory_barrier
Unexecuted instantiation: pseudoais.c:memory_barrier
Unexecuted instantiation: subframe.c:memory_barrier
Unexecuted instantiation: driver_ais.c:memory_barrier
Unexecuted instantiation: driver_allystar.c:memory_barrier
Unexecuted instantiation: driver_casic.c:memory_barrier
Unexecuted instantiation: driver_evermore.c:memory_barrier
Unexecuted instantiation: driver_garmin.c:memory_barrier
Unexecuted instantiation: driver_garmin_txt.c:memory_barrier
Unexecuted instantiation: driver_geostar.c:memory_barrier
Unexecuted instantiation: driver_greis.c:memory_barrier
Unexecuted instantiation: driver_italk.c:memory_barrier
Unexecuted instantiation: driver_navcom.c:memory_barrier
Unexecuted instantiation: driver_oncore.c:memory_barrier
Unexecuted instantiation: driver_rtcm3.c:memory_barrier
Unexecuted instantiation: gps_maskdump.c:memory_barrier
Unexecuted instantiation: gpsutils.c:memory_barrier
Unexecuted instantiation: hex.c:memory_barrier
Unexecuted instantiation: libgps_core.c:memory_barrier
Unexecuted instantiation: libgps_shm.c:memory_barrier
Unexecuted instantiation: libgps_sock.c:memory_barrier
Unexecuted instantiation: netlib.c:memory_barrier
Unexecuted instantiation: json.c:memory_barrier
Unexecuted instantiation: libgps_json.c:memory_barrier
Unexecuted instantiation: rtcm2_json.c:memory_barrier
Unexecuted instantiation: rtcm3_json.c:memory_barrier
Unexecuted instantiation: shared_json.c:memory_barrier
Unexecuted instantiation: ais_json.c:memory_barrier
130
131
/* likely(), unlikely(), branch optimization
132
 * https://kernelnewbies.org/FAQ/LikelyUnlikely
133
 */
134
#if defined(__GNUC__)
135
    #define likely(x)       __builtin_expect(!!(x), 1)
136
144M
    #define unlikely(x)     __builtin_expect(!!(x), 0)
137
#else
138
    #define likely(x)       (x)
139
    #define unlikely(x)     (x)
140
#endif
141
142
#endif  // _GPSD_COMPILER_H_
143
// vim: set expandtab shiftwidth=4