]> granicus.if.org Git - clang/commitdiff
Define __FINITE_MATH_ONLY__ based on -ffast-math and -ffinite-math-only.
authorBob Wilson <bob.wilson@apple.com>
Thu, 19 Jul 2012 03:52:53 +0000 (03:52 +0000)
committerBob Wilson <bob.wilson@apple.com>
Thu, 19 Jul 2012 03:52:53 +0000 (03:52 +0000)
This macro was being unconditionally set to zero, preceded by a FIXME comment.
This fixes <rdar://problem/11845441>.  Patch by Michael Gottesman!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160491 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.def
include/clang/Driver/Options.td
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Frontend/InitPreprocessor.cpp
test/Preprocessor/predefined-macros.c

index 8f39971c68ffd59f152233bd5f4045c70c9abb6c..6409e33d8cf7831c555c80427fa96342c513a2a8 100644 (file)
@@ -99,6 +99,7 @@ LANGOPT(GNUInline         , 1, 0, "GNU inline semantics")
 LANGOPT(NoInlineDefine    , 1, 0, "__NO_INLINE__ predefined macro")
 LANGOPT(Deprecated        , 1, 0, "__DEPRECATED predefined macro")
 LANGOPT(FastMath          , 1, 0, "__FAST_MATH__ predefined macro")
+LANGOPT(FiniteMathOnly    , 1, 0, "__FINITE_MATH_ONLY__ predefined macro")
 
 BENIGN_LANGOPT(ObjCGCBitmapPrint , 1, 0, "printing of GC's bitmap layout for __weak/__strong ivars")
 
index cf8ef814fc3dad6e9fb2ad9db395bbb177d5d45b..0c4760bbb9de98e447299d8baa9d05eea28fa996 100644 (file)
@@ -400,7 +400,7 @@ def fassociative_math : Flag<"-fassociative-math">, Group<f_Group>;
 def fno_associative_math : Flag<"-fno-associative-math">, Group<f_Group>;
 def freciprocal_math : Flag<"-freciprocal-math">, Group<f_Group>;
 def fno_reciprocal_math : Flag<"-fno-reciprocal-math">, Group<f_Group>;
-def ffinite_math_only : Flag<"-ffinite-math-only">, Group<f_Group>;
+def ffinite_math_only : Flag<"-ffinite-math-only">, Group<f_Group>, Flags<[CC1Option]>;
 def fno_finite_math_only : Flag<"-fno-finite-math-only">, Group<f_Group>;
 def fsigned_zeros : Flag<"-fsigned-zeros">, Group<f_Group>;
 def fno_signed_zeros : Flag<"-fno-signed-zeros">, Group<f_Group>;
index 59196b20e28b4030c68b5b64c3981278221f0618..e07068aea1400f315becf0ac3d73b2375beb6c8c 100644 (file)
@@ -1823,12 +1823,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     }
   }
 
-  // We separately look for the '-ffast-math' flag, and if we find it, tell the
-  // frontend to provide the appropriate preprocessor macros. This is distinct
-  // from enabling any optimizations as it induces a language change which must
-  // survive serialization and deserialization, etc.
+  // We separately look for the '-ffast-math' and '-ffinite-math-only' flags,
+  // and if we find them, tell the frontend to provide the appropriate
+  // preprocessor macros. This is distinct from enabling any optimizations as
+  // these options induce language changes which must survive serialization
+  // and deserialization, etc.
   if (Args.hasArg(options::OPT_ffast_math))
     CmdArgs.push_back("-ffast-math");
+  if (Args.hasArg(options::OPT_ffinite_math_only))
+    CmdArgs.push_back("-ffinite-math-only");
 
   // Decide whether to use verbose asm. Verbose assembly is the default on
   // toolchains which have the integrated assembler on by default.
index 016783b1dc5979202c46b041e01cc7a3b6ee0c39..544c0a270a03acd4b8a10f8f23244fe883053330 100644 (file)
@@ -2100,6 +2100,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   Opts.NoInlineDefine = !Opt || Args.hasArg(OPT_fno_inline);
 
   Opts.FastMath = Args.hasArg(OPT_ffast_math);
+  Opts.FiniteMathOnly = Args.hasArg(OPT_ffinite_math_only);
 
   unsigned SSP = Args.getLastArgIntValue(OPT_stack_protector, 0, Diags);
   switch (SSP) {
index 6120d117e3ce40f36598e25a1e80b24853304a84..3979731ff6f842baeb0ce7cc44ec0af5abc47729 100644 (file)
@@ -527,9 +527,10 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
   if (const char *Prefix = TI.getUserLabelPrefix())
     Builder.defineMacro("__USER_LABEL_PREFIX__", Prefix);
 
-  // Build configuration options.  FIXME: these should be controlled by
-  // command line options or something.
-  Builder.defineMacro("__FINITE_MATH_ONLY__", "0");
+  if (LangOpts.FastMath || LangOpts.FiniteMathOnly)
+    Builder.defineMacro("__FINITE_MATH_ONLY__", "1");
+  else
+    Builder.defineMacro("__FINITE_MATH_ONLY__", "0");
 
   if (LangOpts.GNUInline)
     Builder.defineMacro("__GNUC_GNU_INLINE__");
index 5c11c3b7b2a30c9e1afd65a726e1f5112b938c16..2c193018b5c09b84acec8090e324912eb668f7a1 100644 (file)
 // RUN: %clang_cc1 %s -E -dM -ffast-math -o - \
 // RUN:   | FileCheck %s --check-prefix=CHECK-FAST-MATH
 // CHECK-FAST-MATH: #define __FAST_MATH__
+// CHECK-FAST-MATH: #define __FINITE_MATH_ONLY__ 1
+//
+// RUN: %clang_cc1 %s -E -dM -ffinite-math-only -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK-FINITE-MATH-ONLY
+// CHECK-FINITE-MATH-ONLY: #define __FINITE_MATH_ONLY__ 1
+//
+// RUN: %clang %s -E -dM -fno-finite-math-only -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-FINITE-MATH-ONLY
+// CHECK-NO-FINITE-MATH-ONLY: #define __FINITE_MATH_ONLY__ 0
+//
+// RUN: %clang_cc1 %s -E -dM -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK-FINITE-MATH-FLAG-UNDEFINED
+// CHECK-FINITE-MATH-FLAG-UNDEFINED: #define __FINITE_MATH_ONLY__ 0