summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-05-16 16:50:20 +0200
committerStephan Bergmann <sbergman@redhat.com>2018-05-17 08:23:37 +0200
commitae39b1ef2dcc9ef7784ff002dd10318564931c2b (patch)
tree6af49b803cea876aba3e7387494afbc9df98a4b5 /compilerplugins
parent7ab34b51f2d45137191145d31b4b0c7d18f577bf (diff)
Further loplugin:redundantcast improvements for floating-integer conversions
The code in svx/source/customshapes/EnhancedCustomShape2d.cxx started out as > aStart.X() = (sal_Int32)( ( (double)( aStart.X() - aCenter.X() ) / fXScale ) ) + aCenter.X(); > aStart.Y() = (sal_Int32)( ( (double)( aStart.Y() - aCenter.Y() ) / fYScale ) ) + aCenter.Y(); > aEnd.X() = (sal_Int32)( ( (double)( aEnd.X() - aCenter.X() ) / fXScale ) ) + aCenter.X(); > aEnd.Y() = (sal_Int32)( ( (double)( aEnd.Y() - aCenter.Y() ) / fYScale ) ) + aCenter.Y(); in afd1cf255d9cb4c78633e668376a09bd309be7ef "INTEGRATION: CWS sj05", then the floating-point scaling factors got gradually removed first with 101559f88022162ede229fe14366d394700816fe "INTEGRATION: CWS bm3" and then completely with d9f21c90bd61d15fd78a8df9115bf2e9ededbd1b "Fixes Circular arrow distortion, Bug #46272". Change-Id: I337d7893e513738c986d0e85efabcbf7bab912e5 Reviewed-on: https://gerrit.libreoffice.org/54434 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/redundantcast.cxx16
1 files changed, 14 insertions, 2 deletions
diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx
index 66b81941e579..b6db47495a6d 100644
--- a/compilerplugins/clang/redundantcast.cxx
+++ b/compilerplugins/clang/redundantcast.cxx
@@ -65,6 +65,18 @@ char const * printExprValueKind(ExprValueKind k) {
llvm_unreachable("unknown ExprValueKind");
}
+enum class AlgebraicType { None, Integer, FloatingPoint };
+
+AlgebraicType algebraicType(clang::Type const & type) {
+ if (type.isIntegralOrEnumerationType()) {
+ return AlgebraicType::Integer;
+ } else if (type.isRealFloatingType()) {
+ return AlgebraicType::FloatingPoint;
+ } else {
+ return AlgebraicType::None;
+ }
+}
+
class RedundantCast:
public RecursiveASTVisitor<RedundantCast>, public loplugin::RewritePlugin
{
@@ -252,8 +264,8 @@ bool RedundantCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) {
case CK_IntegralToFloating:
if (auto e = dyn_cast<ExplicitCastExpr>(expr->getSubExpr()->IgnoreParenImpCasts())) {
if ((isa<CXXStaticCastExpr>(e) || isa<CXXFunctionalCastExpr>(e))
- && (e->getSubExprAsWritten()->getType().getCanonicalType().getTypePtr()
- == expr->getType().getCanonicalType().getTypePtr()))
+ && (algebraicType(*e->getSubExprAsWritten()->getType())
+ == algebraicType(*expr->getType())))
{
report(
DiagnosticsEngine::Warning,