aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-cppbuiltin.c
diff options
context:
space:
mode:
authorMatthias Kretz <m.kretz@gsi.de>2021-06-30 10:41:33 +0200
committerMatthias Kretz <m.kretz@gsi.de>2021-09-20 15:13:11 +0200
commit1949d7540a0322993bcae2f8893e2dbd29209040 (patch)
treed0c88b42ad3ae57574993673ea95ff691b2f4ecf /gcc/c-family/c-cppbuiltin.c
parent71a4bdada59d2d6d1f17c949eaf9377ebb7a8854 (diff)
downloadgcc-1949d7540a0322993bcae2f8893e2dbd29209040.zip
gcc-1949d7540a0322993bcae2f8893e2dbd29209040.tar.gz
gcc-1949d7540a0322993bcae2f8893e2dbd29209040.tar.bz2
c-family: Add more predefined macros for math flags
Library code, especially in headers, sometimes needs to know how the compiler interprets / optimizes floating-point types and operations. This information can be used for additional optimizations or for ensuring correctness. This change makes -freciprocal-math, -fno-signed-zeros, -fno-trapping-math, -fassociative-math, and -frounding-math report their state via corresponding pre-defined macros. Signed-off-by: Matthias Kretz <m.kretz@gsi.de> gcc/testsuite/ChangeLog: * gcc.dg/associative-math-1.c: New test. * gcc.dg/associative-math-2.c: New test. * gcc.dg/no-signed-zeros-1.c: New test. * gcc.dg/no-signed-zeros-2.c: New test. * gcc.dg/no-trapping-math-1.c: New test. * gcc.dg/no-trapping-math-2.c: New test. * gcc.dg/reciprocal-math-1.c: New test. * gcc.dg/reciprocal-math-2.c: New test. * gcc.dg/rounding-math-1.c: New test. * gcc.dg/rounding-math-2.c: New test. gcc/c-family/ChangeLog: * c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Define or undefine __RECIPROCAL_MATH__, __NO_SIGNED_ZEROS__, __NO_TRAPPING_MATH__, __ASSOCIATIVE_MATH__, and __ROUNDING_MATH__ according to the new optimization flags. gcc/ChangeLog: * cppbuiltin.c (define_builtin_macros_for_compilation_flags): Define __RECIPROCAL_MATH__, __NO_SIGNED_ZEROS__, __NO_TRAPPING_MATH__, __ASSOCIATIVE_MATH__, and __ROUNDING_MATH__ according to their corresponding flags. * doc/cpp.texi: Document __RECIPROCAL_MATH__, __NO_SIGNED_ZEROS__, __NO_TRAPPING_MATH__, __ASSOCIATIVE_MATH__, and __ROUNDING_MATH__.
Diffstat (limited to 'gcc/c-family/c-cppbuiltin.c')
-rw-r--r--gcc/c-family/c-cppbuiltin.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index ce88e70..a299273 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -628,6 +628,31 @@ c_cpp_builtins_optimize_pragma (cpp_reader *pfile, tree prev_tree,
cpp_undef (pfile, "__FINITE_MATH_ONLY__");
cpp_define_unused (pfile, "__FINITE_MATH_ONLY__=0");
}
+
+ if (!prev->x_flag_reciprocal_math && cur->x_flag_reciprocal_math)
+ cpp_define_unused (pfile, "__RECIPROCAL_MATH__");
+ else if (prev->x_flag_reciprocal_math && !cur->x_flag_reciprocal_math)
+ cpp_undef (pfile, "__RECIPROCAL_MATH__");
+
+ if (!prev->x_flag_signed_zeros && cur->x_flag_signed_zeros)
+ cpp_undef (pfile, "__NO_SIGNED_ZEROS__");
+ else if (prev->x_flag_signed_zeros && !cur->x_flag_signed_zeros)
+ cpp_define_unused (pfile, "__NO_SIGNED_ZEROS__");
+
+ if (!prev->x_flag_trapping_math && cur->x_flag_trapping_math)
+ cpp_undef (pfile, "__NO_TRAPPING_MATH__");
+ else if (prev->x_flag_trapping_math && !cur->x_flag_trapping_math)
+ cpp_define_unused (pfile, "__NO_TRAPPING_MATH__");
+
+ if (!prev->x_flag_associative_math && cur->x_flag_associative_math)
+ cpp_define_unused (pfile, "__ASSOCIATIVE_MATH__");
+ else if (prev->x_flag_associative_math && !cur->x_flag_associative_math)
+ cpp_undef (pfile, "__ASSOCIATIVE_MATH__");
+
+ if (!prev->x_flag_rounding_math && cur->x_flag_rounding_math)
+ cpp_define_unused (pfile, "__ROUNDING_MATH__");
+ else if (prev->x_flag_rounding_math && !cur->x_flag_rounding_math)
+ cpp_undef (pfile, "__ROUNDING_MATH__");
}