View | Details | Raw Unified | Return to bug 244850 | Differences between
and this patch

Collapse All | Expand All

(-)compilerplugins/clang/simplifybool.cxx (-5 / +30 lines)
Lines 241-247 Link Here
241
            << expr->getSourceRange();
241
            << expr->getSourceRange();
242
        return true;
242
        return true;
243
    }
243
    }
244
    if (auto binaryOp = dyn_cast<BinaryOperator>(expr->getSubExpr()->IgnoreParenImpCasts())) {
244
    auto sub = expr->getSubExpr()->IgnoreParenImpCasts();
245
    auto reversed = false;
246
#if CLANG_VERSION >= 100000
247
    if (auto const rewritten = dyn_cast<CXXRewrittenBinaryOperator>(sub)) {
248
        if (rewritten->isReversed()) {
249
            if (rewritten->getOperator() == BO_EQ) {
250
                auto const sem = rewritten->getSemanticForm();
251
                bool match;
252
                if (auto const op1 = dyn_cast<BinaryOperator>(sem)) {
253
                    match = op1->getOpcode() == BO_EQ;
254
                } else if (auto const op2 = dyn_cast<CXXOperatorCallExpr>(sem)) {
255
                    match = op2->getOperator() == OO_EqualEqual;
256
                } else {
257
                    match = false;
258
                }
259
                if (match) {
260
                    sub = sem;
261
                    reversed = true;
262
                }
263
            }
264
        }
265
    }
266
#endif
267
    if (auto binaryOp = dyn_cast<BinaryOperator>(sub)) {
245
        // Ignore macros, otherwise
268
        // Ignore macros, otherwise
246
        //    OSL_ENSURE(!b, ...);
269
        //    OSL_ENSURE(!b, ...);
247
        // triggers.
270
        // triggers.
Lines 289-295 Link Here
289
                    << binaryOp->getSourceRange();
312
                    << binaryOp->getSourceRange();
290
        }
313
        }
291
    }
314
    }
292
    if (auto binaryOp = dyn_cast<CXXOperatorCallExpr>(expr->getSubExpr()->IgnoreParenImpCasts())) {
315
    if (auto binaryOp = dyn_cast<CXXOperatorCallExpr>(sub)) {
293
        // Ignore macros, otherwise
316
        // Ignore macros, otherwise
294
        //    OSL_ENSURE(!b, ...);
317
        //    OSL_ENSURE(!b, ...);
295
        // triggers.
318
        // triggers.
Lines 301-308 Link Here
301
        if (!(op == OO_EqualEqual || op == OO_ExclaimEqual))
324
        if (!(op == OO_EqualEqual || op == OO_ExclaimEqual))
302
            return true;
325
            return true;
303
        BinaryOperator::Opcode negatedOpcode = BinaryOperator::negateComparisonOp(BinaryOperator::getOverloadedOpcode(op));
326
        BinaryOperator::Opcode negatedOpcode = BinaryOperator::negateComparisonOp(BinaryOperator::getOverloadedOpcode(op));
304
        auto lhs = binaryOp->getArg(0)->IgnoreImpCasts()->getType()->getUnqualifiedDesugaredType();
327
        auto lhs = binaryOp->getArg(reversed ? 1 : 0)->IgnoreImpCasts()->getType()->getUnqualifiedDesugaredType();
305
        auto rhs = binaryOp->getArg(1)->IgnoreImpCasts()->getType()->getUnqualifiedDesugaredType();
328
        auto rhs = binaryOp->getArg(reversed ? 0 : 1)->IgnoreImpCasts()->getType()->getUnqualifiedDesugaredType();
306
        auto const negOp = findOperator(compiler, negatedOpcode, lhs, rhs);
329
        auto const negOp = findOperator(compiler, negatedOpcode, lhs, rhs);
307
        if (!negOp)
330
        if (!negOp)
308
            return true;
331
            return true;
Lines 323-330 Link Here
323
            << expr->getSourceRange();
346
            << expr->getSourceRange();
324
        if (negOp != ASSUME_OPERATOR_EXISTS)
347
        if (negOp != ASSUME_OPERATOR_EXISTS)
325
            report(
348
            report(
326
                DiagnosticsEngine::Note, "the presumed corresponding negated operator is declared here",
349
                DiagnosticsEngine::Note, "the presumed corresponding negated operator for %0 and %1 is declared here",
327
                negOp->getLocation())
350
                negOp->getLocation())
351
                << binaryOp->getArg(reversed ? 1 : 0)->IgnoreImpCasts()->getType()
352
                << binaryOp->getArg(reversed ? 0 : 1)->IgnoreImpCasts()->getType()
328
                << negOp->getSourceRange();
353
                << negOp->getSourceRange();
329
    }
354
    }
330
    return true;
355
    return true;

Return to bug 244850