public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] builtins: Guard builtins.cc against HUGE_VAL and NAN definitions
@ 2022-11-02  9:13 Rainer Orth
  2022-11-02  9:27 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Rainer Orth @ 2022-11-02  9:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 1321 bytes --]

trunk bootstrap recently broke on Solaris like this:

/vol/gcc/src/hg/master/local/gcc/builtins.cc:2104:8: error: pasting "CFN_BUILT_IN_" and "(" does not give a valid preprocessing token
 2104 |   case CFN_BUILT_IN_##MATHFN:   \
      |        ^~~~~~~~~~~~~
/vol/gcc/src/hg/master/local/gcc/builtins.cc:2112:3: note: in expansion of macro 'CASE_MATHFN'
 2112 |   CASE_MATHFN(MATHFN)    \
      |   ^~~~~~~~~~~
/vol/gcc/src/hg/master/local/gcc/builtins.cc:1967:5: note: in expansion of macro 'CASE_MATHFN_FLOATN'
 1967 |     CASE_MATHFN_FLOATN (HUGE_VAL)  \

and similarly for NAN.

It turns out this happens because <math.h> is included at some point,
which (in <iso/math_c99.h>) defines

#define	HUGE_VAL	(__builtin_huge_val())
#define	NAN		(__builtin_nanf(""))

While this only happpens on Solaris right now, the same issue would be
present on other targets when <math.h> gets included somehow.

To avoid this, this patch #undef's both macros.

Bootstrapped without regressions on i386-pc-solaris2.11 and
sparc-sun-solaris2.11.

Ok for trunk?

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2022-11-01  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gcc:
	* builtins.cc (mathfn_built_in_2): #undef HUGE_VAL, NAN.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sol2-builtins-math.h.patch --]
[-- Type: text/x-patch, Size: 581 bytes --]

# HG changeset patch
# Parent  3e5ba66da20edf52cdfe371ea2244c91d770f64a
builtins: Guard builtins.cc against HUGE_VAL and NAN definitions

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -1931,6 +1931,11 @@ mathfn_built_in_2 (tree type, combined_f
   built_in_function fcodef64x = END_BUILTINS;
   built_in_function fcodef128x = END_BUILTINS;
 
+  /* If <math.h> has been included somehow, HUGE_VAL and NAN definitions
+     break the uses below.  */
+#undef HUGE_VAL
+#undef NAN
+
   switch (fn)
     {
 #define SEQ_OF_CASE_MATHFN			\

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] builtins: Guard builtins.cc against HUGE_VAL and NAN definitions
  2022-11-02  9:13 [PATCH] builtins: Guard builtins.cc against HUGE_VAL and NAN definitions Rainer Orth
@ 2022-11-02  9:27 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2022-11-02  9:27 UTC (permalink / raw)
  To: Rainer Orth; +Cc: gcc-patches

On Wed, Nov 02, 2022 at 10:13:44AM +0100, Rainer Orth wrote:
> trunk bootstrap recently broke on Solaris like this:
> 
> /vol/gcc/src/hg/master/local/gcc/builtins.cc:2104:8: error: pasting "CFN_BUILT_IN_" and "(" does not give a valid preprocessing token
>  2104 |   case CFN_BUILT_IN_##MATHFN:   \
>       |        ^~~~~~~~~~~~~
> /vol/gcc/src/hg/master/local/gcc/builtins.cc:2112:3: note: in expansion of macro 'CASE_MATHFN'
>  2112 |   CASE_MATHFN(MATHFN)    \
>       |   ^~~~~~~~~~~
> /vol/gcc/src/hg/master/local/gcc/builtins.cc:1967:5: note: in expansion of macro 'CASE_MATHFN_FLOATN'
>  1967 |     CASE_MATHFN_FLOATN (HUGE_VAL)  \
> 
> and similarly for NAN.
> 
> It turns out this happens because <math.h> is included at some point,
> which (in <iso/math_c99.h>) defines
> 
> #define	HUGE_VAL	(__builtin_huge_val())
> #define	NAN		(__builtin_nanf(""))
> 
> While this only happpens on Solaris right now, the same issue would be
> present on other targets when <math.h> gets included somehow.
> 
> To avoid this, this patch #undef's both macros.
> 
> Bootstrapped without regressions on i386-pc-solaris2.11 and
> sparc-sun-solaris2.11.
> 
> Ok for trunk?
> 
> 	Rainer
> 
> -- 
> -----------------------------------------------------------------------------
> Rainer Orth, Center for Biotechnology, Bielefeld University
> 
> 
> 2022-11-01  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
> 
> 	gcc:
> 	* builtins.cc (mathfn_built_in_2): #undef HUGE_VAL, NAN.

LGTM, thanks.

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-02  9:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-02  9:13 [PATCH] builtins: Guard builtins.cc against HUGE_VAL and NAN definitions Rainer Orth
2022-11-02  9:27 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).