[cfe-commits] r156826 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaChecking.cpp test/Analysis/array-struct-region.c test/CXX/expr/expr.unary/expr.unary.op/p6.cpp test/CXX/temp/temp.spec/p5.cpp test/PCH/exprs.h test/Sem
Nico Weber
thakis at chromium.org
Tue May 15 10:39:59 PDT 2012
Hi David,
as mentioned on the thread for this warning, with this change clang warns on
#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
: NULL)
// ...
if ( ! YY_CURRENT_BUFFER ) {
// ...
}
with this message:
./pp_lex.cpp:784:10: error: implicit conversion of NULL constant to 'bool'
[-Werror,-Wnull-conversion]
if ( ! YY_CURRENT_BUFFER ) {
^~~~~~~~~~~~~~~~~
./pp_lex.cpp:295:29: note: expanded from macro 'YY_CURRENT_BUFFER'
: NULL)
^
This looks like valid code to me.
Nico
On Tue, May 15, 2012 at 9:56 AM, David Blaikie <dblaikie at gmail.com> wrote:
> Author: dblaikie
> Date: Tue May 15 11:56:36 2012
> New Revision: 156826
>
> URL: http://llvm.org/viewvc/llvm-project?rev=156826&view=rev
> Log:
> Improve some of the conversion warnings to fire on conversion to bool.
>
> Moves the bool bail-out down a little in SemaChecking - so now
> -Wnull-conversion and -Wliteral-conversion can fire when the target type is
> bool.
>
> Also improve the wording/details in the -Wliteral-conversion warning to
> match
> the -Wconstant-conversion.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/Analysis/array-struct-region.c
> cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
> cfe/trunk/test/CXX/temp/temp.spec/p5.cpp
> cfe/trunk/test/PCH/exprs.h
> cfe/trunk/test/Sema/array-init.c
> cfe/trunk/test/Sema/knr-def-call.c
> cfe/trunk/test/SemaCXX/bool.cpp
> cfe/trunk/test/SemaCXX/conversion.cpp
> cfe/trunk/test/SemaCXX/expressions.cpp
> cfe/trunk/test/SemaCXX/overload-call.cpp
> cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp
> cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 15
> 11:56:36 2012
> @@ -1781,8 +1781,7 @@
> "implicit truncation from %2 to bitfield changes value from %0 to %1">,
> InGroup<ConstantConversion>;
> def warn_impcast_literal_float_to_integer : Warning<
> - "implicit conversion turns literal floating-point number into integer: "
> - "%0 to %1">,
> + "implicit conversion from %0 to %1 changes value from %2 to %3">,
> InGroup<LiteralConversion>;
> def warn_impcast_string_literal_to_bool : Warning<
> "implicit conversion turns string literal into bool: %0 to %1">,
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue May 15 11:56:36 2012
> @@ -22,6 +22,7 @@
> #include "clang/AST/CharUnits.h"
> #include "clang/AST/DeclCXX.h"
> #include "clang/AST/DeclObjC.h"
> +#include "clang/AST/Expr.h"
> #include "clang/AST/ExprCXX.h"
> #include "clang/AST/ExprObjC.h"
> #include "clang/AST/EvaluatedExprVisitor.h"
> @@ -4081,8 +4082,17 @@
> == llvm::APFloat::opOK && isExact)
> return;
>
> + SmallString<16> PrettySourceValue;
> + Value.toString(PrettySourceValue);
> + std::string PrettyTargetValue;
> + if (T->isSpecificBuiltinType(BuiltinType::Bool))
> + PrettyTargetValue = IntegerValue == 0 ? "false" : "true";
> + else
> + PrettyTargetValue = IntegerValue.toString(10);
> +
> S.Diag(FL->getExprLoc(), diag::warn_impcast_literal_float_to_integer)
> - << FL->getType() << T << FL->getSourceRange() <<
> SourceRange(CContext);
> + << FL->getType() << T.getUnqualifiedType() << PrettySourceValue
> + << PrettyTargetValue << FL->getSourceRange() << SourceRange(CContext);
> }
>
> std::string PrettyPrintInRange(const llvm::APSInt &Value, IntRange Range)
> {
> @@ -4149,7 +4159,6 @@
> }
> }
> }
> - return; // Other casts to bool are not checked.
> }
>
> // Strip vector types.
> @@ -4213,7 +4222,7 @@
> }
>
> // If the target is integral, always warn.
> - if ((TargetBT && TargetBT->isInteger())) {
> + if (TargetBT && TargetBT->isInteger()) {
> if (S.SourceMgr.isInSystemMacro(CC))
> return;
>
> @@ -4247,6 +4256,11 @@
> return;
> }
>
> + // TODO: remove this early return once the false positives for
> constant->bool
> + // in templates, macros, etc, are reduced or removed.
> + if (Target->isSpecificBuiltinType(BuiltinType::Bool))
> + return;
> +
> IntRange SourceRange = GetExprRange(S.Context, E);
> IntRange TargetRange = IntRange::forTargetOfCanonicalType(S.Context,
> Target);
>
>
> Modified: cfe/trunk/test/Analysis/array-struct-region.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/array-struct-region.c?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Analysis/array-struct-region.c (original)
> +++ cfe/trunk/test/Analysis/array-struct-region.c Tue May 15 11:56:36 2012
> @@ -25,8 +25,8 @@
> }
>
> void nested_compound_literals(int rad) {
> - int vec[6][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, //
> expected-warning 6 {{implicit conversion turns literal floating-point
> number into integer}}
> - {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; //
> expected-warning 6 {{implicit conversion turns literal floating-point
> number into integer}}
> + int vec[6][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, //
> expected-warning 6 {{implicit conversion from 'double' to 'int' changes
> value from}}
> + {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; //
> expected-warning 6 {{implicit conversion from 'double' to 'int' changes
> value from}}
> int a;
>
> for (a = 0; a < 6; ++a) {
>
> Modified: cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp (original)
> +++ cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp Tue May 15
> 11:56:36 2012
> @@ -4,7 +4,7 @@
>
> bool b = !0;
>
> -bool b2 = !1.2;
> +bool b2 = !1.2; //expected-warning{{implicit conversion from 'double' to
> 'bool' changes value from 1.2 to true}}
>
> bool b3 = !4;
>
>
> Modified: cfe/trunk/test/CXX/temp/temp.spec/p5.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/p5.cpp?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CXX/temp/temp.spec/p5.cpp (original)
> +++ cfe/trunk/test/CXX/temp/temp.spec/p5.cpp Tue May 15 11:56:36 2012
> @@ -14,7 +14,7 @@
> };
>
> template<typename T>
> -T X0<T>::value = 3.14; // expected-warning{{implicit conversion turns
> literal floating-point number into integer}}
> +T X0<T>::value = 3.14; // expected-warning{{implicit conversion from
> 'double' to 'int' changes value from 3.14 to 3}}
>
> template struct X0<int>; // expected-note{{previous explicit
> instantiation}} \
> expected-note{{requested here}}
>
> Modified: cfe/trunk/test/PCH/exprs.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.h?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/PCH/exprs.h (original)
> +++ cfe/trunk/test/PCH/exprs.h Tue May 15 11:56:36 2012
> @@ -87,7 +87,7 @@
> int x;
> float y;
> } designated_inits[3] = { [0].y = 17,
> - [2].x = 12.3, // expected-warning {{implicit
> conversion turns literal floating-point number into integer}}
> + [2].x = 12.3, // expected-warning {{implicit
> conversion from 'double' to 'int' changes value from 12.3 to 12}}
> 3.5 };
>
> // TypesCompatibleExpr
>
> Modified: cfe/trunk/test/Sema/array-init.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Sema/array-init.c (original)
> +++ cfe/trunk/test/Sema/array-init.c Tue May 15 11:56:36 2012
> @@ -50,7 +50,7 @@
>
> static long x2[3] = { 1.0,
> "abc", // expected-warning{{incompatible pointer
> to integer conversion initializing 'long' with an expression of type 'char
> [4]'}}
> - 5.8 }; // expected-warning {{implicit conversion
> turns literal floating-point number into integer}}
> + 5.8 }; // expected-warning {{implicit conversion
> from 'double' to 'long' changes value from 5.8 to 5}}
> }
>
> void test() {
>
> Modified: cfe/trunk/test/Sema/knr-def-call.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/knr-def-call.c?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Sema/knr-def-call.c (original)
> +++ cfe/trunk/test/Sema/knr-def-call.c Tue May 15 11:56:36 2012
> @@ -36,6 +36,6 @@
> }
>
> void use_proto() {
> - proto(42.1); // expected-warning{{implicit conversion turns literal
> floating-point number into integer}}
> - (&proto)(42.1); // expected-warning{{implicit conversion turns literal
> floating-point number into integer}}
> + proto(42.1); // expected-warning{{implicit conversion from 'double' to
> 'int' changes value from 42.1 to 42}}
> + (&proto)(42.1); // expected-warning{{implicit conversion from 'double'
> to 'int' changes value from 42.1 to 42}}
> }
>
> Modified: cfe/trunk/test/SemaCXX/bool.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/bool.cpp?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/bool.cpp (original)
> +++ cfe/trunk/test/SemaCXX/bool.cpp Tue May 15 11:56:36 2012
> @@ -1,4 +1,4 @@
> -// RUN: %clang_cc1 -fsyntax-only -verify %s
> +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion %s
>
> // Bool literals can be enum values.
> enum {
>
> Modified: cfe/trunk/test/SemaCXX/conversion.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conversion.cpp?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/conversion.cpp (original)
> +++ cfe/trunk/test/SemaCXX/conversion.cpp Tue May 15 11:56:36 2012
> @@ -65,7 +65,7 @@
> int c = ((((NULL)))); // expected-warning {{implicit conversion of NULL
> constant to 'int'}}
> int d;
> d = ((((NULL)))); // expected-warning {{implicit conversion of NULL
> constant to 'int'}}
> - bool bl = NULL; // FIXME: this should warn but we currently suppress a
> bunch of conversion-to-bool warnings including this one
> + bool bl = NULL; // expected-warning {{implicit conversion of NULL
> constant to 'bool'}}
> char ch = NULL; // expected-warning {{implicit conversion of NULL
> constant to 'char'}}
> unsigned char uch = NULL; // expected-warning {{implicit conversion of
> NULL constant to 'unsigned char'}}
> short sh = NULL; // expected-warning {{implicit conversion of NULL
> constant to 'short'}}
> @@ -104,3 +104,12 @@
> tmpl2<int*>();
> }
> }
> +
> +namespace test5 {
> + template<int I>
> + void func() {
> + bool b = I;
> + }
> +
> + template void func<3>();
> +}
>
> Modified: cfe/trunk/test/SemaCXX/expressions.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/expressions.cpp?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/expressions.cpp (original)
> +++ cfe/trunk/test/SemaCXX/expressions.cpp Tue May 15 11:56:36 2012
> @@ -1,4 +1,4 @@
> -// RUN: %clang_cc1 -fsyntax-only -verify %s
> +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion %s
>
> void choice(int);
> int choice(bool);
>
> Modified: cfe/trunk/test/SemaCXX/overload-call.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-call.cpp?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/overload-call.cpp (original)
> +++ cfe/trunk/test/SemaCXX/overload-call.cpp Tue May 15 11:56:36 2012
> @@ -233,7 +233,7 @@
>
> void intref_test() {
> float* ir1 = intref(5);
> - float* ir2 = intref(5.5); // expected-warning{{implicit conversion
> turns literal floating-point number into integer}}
> + float* ir2 = intref(5.5); // expected-warning{{implicit conversion from
> 'double' to 'int' changes value from 5.5 to 5}}
> }
>
> void derived5(C&); // expected-note{{candidate function not viable:
> cannot bind base class object of type 'A' to derived class reference 'C &'
> for 1st argument}}
>
> Modified: cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp (original)
> +++ cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp Tue May 15 11:56:36
> 2012
> @@ -5,29 +5,29 @@
> // Warn when a literal float or double is assigned or bound to an integer.
> void test0() {
> // Float
> - int y0 = 1.2222F; // expected-warning {{implicit conversion turns
> literal floating-point number into integer}}
> - int y1 = (1.2222F); // expected-warning {{implicit conversion turns
> literal floating-point number into integer}}
> - int y2 = (((1.2222F))); // expected-warning {{implicit conversion turns
> literal floating-point number into integer}}
> - int y3 = 12E-1F; // expected-warning {{implicit conversion turns
> literal floating-point number into integer}}
> - int y4 = 1.23E1F; // expected-warning {{implicit conversion turns
> literal floating-point number into integer}}
> + int y0 = 1.2222F; // expected-warning {{implicit conversion from
> 'float' to 'int' changes value from 1.2222 to 1}}
> + int y1 = (1.2222F); // expected-warning {{implicit conversion from
> 'float' to 'int' changes value from 1.2222 to 1}}
> + int y2 = (((1.2222F))); // expected-warning {{implicit conversion from
> 'float' to 'int' changes value from 1.2222 to 1}}
> + int y3 = 12E-1F; // expected-warning {{implicit conversion from 'float'
> to 'int' changes value from 1.2 to 1}}
> + int y4 = 1.23E1F; // expected-warning {{implicit conversion from
> 'float' to 'int' changes value from 12.3 to 12}}
> // Double
> - int y5 = 1.2222; // expected-warning {{implicit conversion turns
> literal floating-point number into integer}}
> - int y6 = 12E-1; // expected-warning {{implicit conversion turns literal
> floating-point number into integer}}
> - int y7 = 1.23E1; // expected-warning {{implicit conversion turns
> literal floating-point number into integer}}
> - int y8 = (1.23E1); // expected-warning {{implicit conversion turns
> literal floating-point number into integer}}
> + int y5 = 1.2222; // expected-warning {{implicit conversion from
> 'double' to 'int' changes value from 1.2222 to 1}}
> + int y6 = 12E-1; // expected-warning {{implicit conversion from 'double'
> to 'int' changes value from 1.2 to 1}}
> + int y7 = 1.23E1; // expected-warning {{implicit conversion from
> 'double' to 'int' changes value from 12.3 to 12}}
> + int y8 = (1.23E1); // expected-warning {{implicit conversion from
> 'double' to 'int' changes value from 12.3 to 12}}
>
> // Test assignment to an existing variable.
> - y8 = 2.22F; // expected-warning {{implicit conversion turns literal
> floating-point number into integer}}
> + y8 = 2.22F; // expected-warning {{implicit conversion from 'float' to
> 'int' changes value from 2.22 to 2}}
>
> // Test direct initialization.
> - int y9(1.23F); // expected-warning {{implicit conversion turns literal
> floating-point number into integer}}
> + int y9(1.23F); // expected-warning {{implicit conversion from 'float'
> to 'int' changes value from 1.23 to 1}}
>
> // Test passing a literal floating-point value to a function that takes
> an integer.
> - foo(1.2F); // expected-warning {{implicit conversion turns literal
> floating-point number into integer}}
> + foo(1.2F); // expected-warning {{implicit conversion from 'float' to
> 'int' changes value from 1.2 to 1}}
>
> - int y10 = -1.2F; // expected-warning {{implicit conversion turns
> literal floating-point number into integer}}
> + int y10 = -1.2F; // expected-warning {{implicit conversion from
> 'float' to 'int' changes value from 1.2 to 1}}
>
> - // -Wconversion-literal does NOT catch const values.
> + // -Wliteral-conversion does NOT catch const values.
> // (-Wconversion DOES catch them.)
> static const float sales_tax_rate = .095F;
> int z = sales_tax_rate;
>
> Modified: cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp?rev=156826&r1=156825&r2=156826&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp (original)
> +++ cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp Tue May 15
> 11:56:36 2012
> @@ -60,7 +60,7 @@
>
> void test_X1(X1 x1) {
> float *fp1 = x1.f1<>(17);
> - float *fp2 = x1.f1<int>(3.14); // expected-warning {{implicit
> conversion turns literal floating-point number into integer}}
> + float *fp2 = x1.f1<int>(3.14); // expected-warning {{implicit
> conversion from 'double' to 'int' changes value from 3.14 to 3}}
> int *ip1 = x1.f1(17);
> float *ip2 = x1.f1(3.14);
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120515/c2998c1b/attachment.html>
More information about the cfe-commits
mailing list