LCOV - code coverage report
Current view: top level - gcc - cppbuiltin.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 98.0 % 100 98
Test Date: 2026-10-17 16:30:31 Functions: 100.0 % 6 6
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Define builtin-in macros for all front ends that perform preprocessing
       2              :    Copyright (C) 2010-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify it under
       7              : the terms of the GNU General Public License as published by the Free
       8              : Software Foundation; either version 3, or (at your option) any later
       9              : version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14              : for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #include "config.h"
      21              : #include "system.h"
      22              : #include "coretypes.h"
      23              : #include "memmodel.h"
      24              : #include "target.h"
      25              : #include "tree.h"
      26              : #include "version.h"
      27              : #include "flags.h"
      28              : #include "cpplib.h"
      29              : #include "cppbuiltin.h"
      30              : 
      31              : 
      32              : /* Parse a BASEVER version string of the format "major.minor.patchlevel"
      33              :    or "major.minor" to extract its components.  */
      34              : void
      35       316882 : parse_basever (int *major, int *minor, int *patchlevel)
      36              : {
      37       316882 :   static int s_major = -1, s_minor, s_patchlevel;
      38              : 
      39       316882 :   if (s_major == -1)
      40       215162 :     if (sscanf (BASEVER, "%d.%d.%d", &s_major, &s_minor, &s_patchlevel) != 3)
      41              :       {
      42            0 :         sscanf (BASEVER, "%d.%d", &s_major, &s_minor);
      43            0 :         s_patchlevel = 0;
      44              :       }
      45              : 
      46       316882 :   if (major)
      47       316882 :     *major = s_major;
      48              : 
      49       316882 :   if (minor)
      50       215204 :     *minor = s_minor;
      51              : 
      52       316882 :   if (patchlevel)
      53       215204 :     *patchlevel = s_patchlevel;
      54       316882 : }
      55              : 
      56              : 
      57              : /* Define __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ and __VERSION__.  */
      58              : static void
      59       215159 : define__GNUC__ (cpp_reader *pfile)
      60              : {
      61       215159 :   int major, minor, patchlevel;
      62              : 
      63       215159 :   parse_basever (&major, &minor, &patchlevel);
      64       215159 :   cpp_define_formatted (pfile, "__GNUC__=%d", major);
      65       215159 :   cpp_define_formatted (pfile, "__GNUC_MINOR__=%d", minor);
      66       215159 :   cpp_define_formatted (pfile, "__GNUC_PATCHLEVEL__=%d", patchlevel);
      67       215159 :   cpp_define_formatted (pfile, "__VERSION__=\"%s\"", version_string);
      68       215159 :   cpp_define_formatted (pfile, "__ATOMIC_RELAXED=%d", MEMMODEL_RELAXED);
      69       215159 :   cpp_define_formatted (pfile, "__ATOMIC_SEQ_CST=%d", MEMMODEL_SEQ_CST);
      70       215159 :   cpp_define_formatted (pfile, "__ATOMIC_ACQUIRE=%d", MEMMODEL_ACQUIRE);
      71       215159 :   cpp_define_formatted (pfile, "__ATOMIC_RELEASE=%d", MEMMODEL_RELEASE);
      72       215159 :   cpp_define_formatted (pfile, "__ATOMIC_ACQ_REL=%d", MEMMODEL_ACQ_REL);
      73       215159 :   cpp_define_formatted (pfile, "__ATOMIC_CONSUME=%d", MEMMODEL_CONSUME);
      74       215159 : }
      75              : 
      76              : 
      77              : /* Define various built-in CPP macros that depend on language-independent
      78              :    compilation flags.  */
      79              : static void
      80       215159 : define_builtin_macros_for_compilation_flags (cpp_reader *pfile)
      81              : {
      82       215159 :   if (flag_pic)
      83              :     {
      84         9746 :       cpp_define_formatted (pfile, "__pic__=%d", flag_pic);
      85         9746 :       cpp_define_formatted (pfile, "__PIC__=%d", flag_pic);
      86              :     }
      87       215159 :   if (flag_pie)
      88              :     {
      89         3149 :       cpp_define_formatted (pfile, "__pie__=%d", flag_pie);
      90         3149 :       cpp_define_formatted (pfile, "__PIE__=%d", flag_pie);
      91              :     }
      92              : 
      93       215159 :   if (flag_sanitize & SANITIZE_ADDRESS)
      94         2347 :     cpp_define (pfile, "__SANITIZE_ADDRESS__");
      95              : 
      96       215159 :   if (flag_sanitize & SANITIZE_HWADDRESS)
      97          264 :     cpp_define (pfile, "__SANITIZE_HWADDRESS__");
      98              : 
      99       215159 :   if (flag_sanitize & SANITIZE_THREAD)
     100          269 :     cpp_define (pfile, "__SANITIZE_THREAD__");
     101              : 
     102       215159 :   if (optimize_size)
     103         9517 :     cpp_define (pfile, "__OPTIMIZE_SIZE__");
     104       215159 :   if (optimize)
     105       118693 :     cpp_define (pfile, "__OPTIMIZE__");
     106              : 
     107       215159 :   if (fast_math_flags_set_p (&global_options))
     108         1529 :     cpp_define (pfile, "__FAST_MATH__");
     109       215159 :   if (flag_signaling_nans)
     110          309 :     cpp_define (pfile, "__SUPPORT_SNAN__");
     111       215159 :   if (!flag_errno_math)
     112         2808 :     cpp_define (pfile, "__NO_MATH_ERRNO__");
     113       215159 :   if (flag_reciprocal_math)
     114         1603 :     cpp_define (pfile, "__RECIPROCAL_MATH__");
     115       215159 :   if (!flag_signed_zeros)
     116         1624 :     cpp_define (pfile, "__NO_SIGNED_ZEROS__");
     117       215159 :   if (!flag_trapping_math)
     118         1734 :     cpp_define (pfile, "__NO_TRAPPING_MATH__");
     119       215159 :   if (flag_associative_math)
     120         1573 :     cpp_define (pfile, "__ASSOCIATIVE_MATH__");
     121       215159 :   if (flag_rounding_math)
     122          199 :     cpp_define (pfile, "__ROUNDING_MATH__");
     123       215159 :   if (flag_unsafe_math_optimizations)
     124         1597 :     cpp_define (pfile, "__UNSAFE_MATH_OPTIMIZATIONS__");
     125              : 
     126       215159 :   cpp_define_formatted (pfile, "__FINITE_MATH_ONLY__=%d",
     127              :                         flag_finite_math_only);
     128       215159 : }
     129              : 
     130              : 
     131              : /* Define built-in macros for LP64 targets. */
     132              : static void
     133       215159 : define_builtin_macros_for_lp64 (cpp_reader *pfile)
     134              : {
     135       215159 :   if (TYPE_PRECISION (long_integer_type_node) == 64
     136       209363 :       && POINTER_SIZE == 64
     137       424522 :       && TYPE_PRECISION (integer_type_node) == 32)
     138              :     {
     139       209363 :       cpp_define (pfile, "_LP64");
     140       209363 :       cpp_define (pfile, "__LP64__");
     141              :     }
     142       215159 : }
     143              : 
     144              : 
     145              : /* Define macros for size of basic C types.  */
     146              : static void
     147       215159 : define_builtin_macros_for_type_sizes (cpp_reader *pfile)
     148              : {
     149              : #define define_type_sizeof(NAME, TYPE)                             \
     150              :     cpp_define_formatted (pfile, NAME"=" HOST_WIDE_INT_PRINT_DEC,   \
     151              :                           tree_to_uhwi (TYPE_SIZE_UNIT (TYPE)))
     152              : 
     153       215159 :   define_type_sizeof ("__SIZEOF_INT__", integer_type_node);
     154       215159 :   define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node);
     155       215159 :   define_type_sizeof ("__SIZEOF_LONG_LONG__", long_long_integer_type_node);
     156       215159 :   define_type_sizeof ("__SIZEOF_SHORT__", short_integer_type_node);
     157       215159 :   define_type_sizeof ("__SIZEOF_FLOAT__", float_type_node);
     158       215159 :   define_type_sizeof ("__SIZEOF_DOUBLE__", double_type_node);
     159       215159 :   define_type_sizeof ("__SIZEOF_LONG_DOUBLE__", long_double_type_node);
     160       215159 :   define_type_sizeof ("__SIZEOF_SIZE_T__", size_type_node);
     161              : 
     162              : #undef define_type_sizeof
     163              : 
     164       430318 :   cpp_define_formatted (pfile, "__CHAR_BIT__=%u",
     165       215159 :                         TYPE_PRECISION (char_type_node));
     166       215159 :   cpp_define_formatted (pfile, "__BIGGEST_ALIGNMENT__=%d",
     167       215159 :                         BIGGEST_ALIGNMENT / BITS_PER_UNIT);
     168              : 
     169              :   /* Define constants useful for implementing endian.h.  */
     170       215159 :   cpp_define (pfile, "__ORDER_LITTLE_ENDIAN__=1234");
     171       215159 :   cpp_define (pfile, "__ORDER_BIG_ENDIAN__=4321");
     172       215159 :   cpp_define (pfile, "__ORDER_PDP_ENDIAN__=3412");
     173              : 
     174       215159 :   if (WORDS_BIG_ENDIAN == BYTES_BIG_ENDIAN)
     175       215159 :     cpp_define_formatted (pfile, "__BYTE_ORDER__=%s",
     176              :                           (WORDS_BIG_ENDIAN
     177              :                            ? "__ORDER_BIG_ENDIAN__"
     178              :                            : "__ORDER_LITTLE_ENDIAN__"));
     179              :   else
     180              :     {
     181              :       /* Assert that we're only dealing with the PDP11 case.  */
     182              :       gcc_assert (!BYTES_BIG_ENDIAN);
     183              :       gcc_assert (WORDS_BIG_ENDIAN);
     184              : 
     185              :       cpp_define (pfile, "__BYTE_ORDER__=__ORDER_PDP_ENDIAN__");
     186              :     }
     187              : 
     188       430318 :   cpp_define_formatted (pfile, "__FLOAT_WORD_ORDER__=%s",
     189       215159 :                         (targetm.float_words_big_endian ()
     190              :                          ? "__ORDER_BIG_ENDIAN__"
     191              :                          : "__ORDER_LITTLE_ENDIAN__"));
     192              : 
     193              :   /* ptr_type_node can't be used here since ptr_mode is only set when
     194              :      toplev calls backend_init which is not done with -E switch.  */
     195       215159 :   cpp_define_formatted (pfile, "__SIZEOF_POINTER__=%d",
     196       215159 :                         1 << ceil_log2 ((POINTER_SIZE + BITS_PER_UNIT - 1) / BITS_PER_UNIT));
     197       215159 : }
     198              : 
     199              : 
     200              : /* Define macros builtins common to all language performing CPP
     201              :    preprocessing.  */
     202              : void
     203       215159 : define_language_independent_builtin_macros (cpp_reader *pfile)
     204              : {
     205       215159 :   define__GNUC__ (pfile);
     206       215159 :   define_builtin_macros_for_compilation_flags (pfile);
     207       215159 :   define_builtin_macros_for_lp64 (pfile);
     208       215159 :   define_builtin_macros_for_type_sizes (pfile);
     209       215159 : }
        

Generated by: LCOV version 2.5.0-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.