[cfe-commits] r44053 - in /cfe/trunk: Driver/clang.cpp test/Sema/floating-point-compare.c

Ted Kremenek kremenek at apple.com
Tue Nov 13 10:37:02 PST 2007


Author: kremenek
Date: Tue Nov 13 12:37:02 2007
New Revision: 44053

URL: http://llvm.org/viewvc/llvm-project?rev=44053&view=rev
Log:
Added -Wfloat-equal option to the driver.  This makes warnings about
floating point comparisons using == or != an opt-in rather than a default
warning.

Updated test case to use -Wfloat-equal.

Modified:
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/test/Sema/floating-point-compare.c

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=44053&r1=44052&r2=44053&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Tue Nov 13 12:37:02 2007
@@ -356,6 +356,10 @@
 WarnUnusedMacros("Wunused_macros",
          llvm::cl::desc("Warn for unused macros in the main translation unit"));
 
+static llvm::cl::opt<bool>
+WarnFloatEqual("Wfloat-equal",
+   llvm::cl::desc("Warn about equality comparisons of floating point values."));
+
 /// InitializeDiagnostics - Initialize the diagnostic object, based on the
 /// current command line option settings.
 static void InitializeDiagnostics(Diagnostic &Diags) {
@@ -366,6 +370,10 @@
   // Silence the "macro is not used" warning unless requested.
   if (!WarnUnusedMacros)
     Diags.setDiagnosticMapping(diag::pp_macro_not_used, diag::MAP_IGNORE);
+               
+  // Silence "floating point comparison" warnings unless requested.
+  if (!WarnFloatEqual)
+    Diags.setDiagnosticMapping(diag::warn_floatingpoint_eq, diag::MAP_IGNORE);
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/test/Sema/floating-point-compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/floating-point-compare.c?rev=44053&r1=44052&r2=44053&view=diff

==============================================================================
--- cfe/trunk/test/Sema/floating-point-compare.c (original)
+++ cfe/trunk/test/Sema/floating-point-compare.c Tue Nov 13 12:37:02 2007
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -Wfloat-equal -verify %s
 
 int foo(float x, float y) {
   return x == y; // expected-warning {{comparing floating point with ==}}





More information about the cfe-commits mailing list