summaryrefslogtreecommitdiff
path: root/compilerplugins/clang
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-11-30 13:25:01 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-12-02 11:46:39 +0100
commit93e0622d0097c90effc8bec5f31cf0c12a20d88b (patch)
treebe13a48682db64a222c0bb53643064058acbb5b1 /compilerplugins/clang
parent48d1df74036386ce19cfabd64d90afcd1532d5c9 (diff)
loplugin:intvsfloat get this working reliably
Change-Id: Ifdf1a152f6bc2e2f6edae97a5191120f630f7e49 Reviewed-on: https://gerrit.libreoffice.org/64374 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r--compilerplugins/clang/intvsfloat.cxx (renamed from compilerplugins/clang/store/intvsfloat.cxx)6
-rw-r--r--compilerplugins/clang/test/intvsfloat.cxx43
2 files changed, 21 insertions, 28 deletions
diff --git a/compilerplugins/clang/store/intvsfloat.cxx b/compilerplugins/clang/intvsfloat.cxx
index 3189d982d9c0..e9ee3fa9b306 100644
--- a/compilerplugins/clang/store/intvsfloat.cxx
+++ b/compilerplugins/clang/intvsfloat.cxx
@@ -16,9 +16,7 @@
TODO multiplying/otherop on a combination of a float and int, and then truncating to int. like this:
float getRotation() {}
- int moRotation;
- moRotation = -F_PI180 * 90 * getRotation();
-
+ int moRotation = -F_PI180 * 90 * getRotation();
*/
namespace
{
@@ -90,6 +88,8 @@ llvm::Optional<double> IntVsFloat::getExprValue(Expr const* expr)
// Of the available clang Evaluate* APIs, this is the __only__ one that produces useful output
// (as of 17 Aug 2018 checkout of clang, ie. towards clang 7)
+ if (expr->isValueDependent())
+ return llvm::Optional<double>();
Expr::EvalResult evalResult;
if (!expr->EvaluateAsRValue(evalResult, compiler.getASTContext()))
return llvm::Optional<double>();
diff --git a/compilerplugins/clang/test/intvsfloat.cxx b/compilerplugins/clang/test/intvsfloat.cxx
index 7c753c3667ab..4746873e7bba 100644
--- a/compilerplugins/clang/test/intvsfloat.cxx
+++ b/compilerplugins/clang/test/intvsfloat.cxx
@@ -18,26 +18,22 @@ struct Class1
void func1(Class1 const& class1)
{
- if (1
- == PI) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ if (1 == PI)
return;
- if (1
- == class1
- .PI) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ if (1 == class1.PI)
return;
- if (true
- == class1
- .PI) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ if (true == class1.PI)
return;
if (1 == class1.getInt()) // no warning expected
return;
- if (1
- == class1
- .E()) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ if (1 == class1.E())
return;
- if (true
- == class1
- .E()) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
+ if (true == class1.E())
return;
if (1 == class1.getFloat()) // no warning expected
return;
@@ -45,24 +41,21 @@ void func1(Class1 const& class1)
void func2(Class1 const& class1)
{
- int i0
- = PI; // expected-error {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
+ // expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
+ int i0 = PI;
(void)i0;
- int i1
- = class1
- .PI; // expected-error {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
+ // expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
+ int i1 = class1.PI;
(void)i1;
- int i2
- = class1
- .E(); // expected-error {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
+ // expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
+ int i2 = class1.E();
(void)i2;
int i3 = class1.getFloat(); // no warning expected
(void)i3;
int i4 = class1.getInt(); // no warning expected
(void)i4;
- bool b1
- = class1
- .E(); // expected-error {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
+ // expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
+ bool b1 = class1.E();
(void)b1;
}