[PATCH] Fix an logic error in the clang driver preventing crtfastmath.o from linking when -Ofast is used without -ffast-math

Benjamin Kramer benny.kra at gmail.com
Thu Mar 20 04:36:45 PDT 2014

  First of all, thanks for finding this. No idea how nobody noticed; the impact of crtfastmath.o is particularly large on some synthetic microbenchmarks that people use to compare flags all the time :)

  The logic in the patch looks sane. Just some minor nits below.

Comment at: lib/Driver/ToolChain.cpp:346-347
@@ +345,4 @@
+  // (to keep the linker options consistent with gcc and clang itself).
+  // TODO: reuse the code from the Tools.cpp::isOptimizationLevelFast()
+  if(!Args.hasFlag(options::OPT_Ofast, options::OPT_O_Group, false)) {
+    // Check if -ffast-math or -funsafe-math.
Can we do this refactoring now instead putting it on the TODO list. As you can see the crtfastmath.o code has bitrotted before, don't want to have that happen again.

Driver.cpp is probably the right place for this kind of flag check. Can be used from both Tools.cpp and ToolChain.cpp.

There is also some suboptimal whitespace in this patch, can you run clang-format over it?


More information about the cfe-commits mailing list