From db87bca211deed14f8d5bb9ef25b8e9ee5c8e139 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 13 Nov 2007 18:37:02 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44053 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/clang.cpp | 8 ++++++++ test/Sema/floating-point-compare.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Driver/clang.cpp b/Driver/clang.cpp index f568302444..5897da32a3 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -356,6 +356,10 @@ static llvm::cl::opt WarnUnusedMacros("Wunused_macros", llvm::cl::desc("Warn for unused macros in the main translation unit")); +static llvm::cl::opt +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 @@ static void InitializeDiagnostics(Diagnostic &Diags) { // 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); } //===----------------------------------------------------------------------===// diff --git a/test/Sema/floating-point-compare.c b/test/Sema/floating-point-compare.c index 62388915a2..cc96be0fd3 100644 --- a/test/Sema/floating-point-compare.c +++ b/test/Sema/floating-point-compare.c @@ -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 ==}} -- 2.50.1