| 526 | } |
| 527 | |
| 528 | bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) const |
| 529 | { |
| 530 | if (expr->isUnaryOp("*") && !expr->astOperand1()->isUnaryOp("&")) |
| 531 | return true; |
| 532 | if (Token::simpleMatch(expr, ". *")) |
| 533 | return true; |
| 534 | if (expr->str() == "(" && Token::simpleMatch(expr->astOperand1(), ".")) |
| 535 | return true; |
| 536 | |
| 537 | const bool macro = false; |
| 538 | const bool pure = false; |
| 539 | const bool followVar = false; |
| 540 | for (const Token *tok = startToken; tok; tok = tok->previous()) { |
| 541 | |
| 542 | if (Token::Match(tok, "%name% (") && !Token::Match(tok, "if|while|for")) { |
| 543 | // Is argument passed by reference? |
| 544 | const std::vector<const Token*> args = getArguments(tok); |
| 545 | for (int argnr = 0; argnr < args.size(); ++argnr) { |
| 546 | if (!Token::Match(args[argnr], "%name%|.|::")) |
| 547 | continue; |
| 548 | if (tok->function() && tok->function()->getArgumentVar(argnr) && !tok->function()->getArgumentVar(argnr)->isReference() && !tok->function()->isConst()) |
| 549 | continue; |
| 550 | for (const Token *subexpr = expr; subexpr; subexpr = subexpr->astOperand1()) { |
| 551 | if (isSameExpression(macro, subexpr, args[argnr], mSettings, pure, followVar)) { |
| 552 | const Scope* scope = expr->scope(); // if there is no other variable, assume no aliasing |
| 553 | if (scope->varlist.size() > 1) |
| 554 | return true; |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | continue; |
| 559 | } |
| 560 | |
| 561 | const Token *addrOf = nullptr; |
| 562 | if (Token::Match(tok, "& %name% =")) |
| 563 | addrOf = tok->tokAt(2)->astOperand2(); |
| 564 | else if (tok->isUnaryOp("&")) |
| 565 | addrOf = tok->astOperand1(); |
| 566 | else if (Token::simpleMatch(tok, "std :: ref (")) |
| 567 | addrOf = tok->tokAt(3)->astOperand2(); |
| 568 | else if (tok->valueType() && tok->valueType()->pointer && |
| 569 | (Token::Match(tok, "%var% = %var% ;") || Token::Match(tok, "%var% {|( %var% }|)")) && |
| 570 | Token::Match(expr->previous(), "%varid% [", tok->tokAt(2)->varId())) |
| 571 | addrOf = tok->tokAt(2); |
| 572 | else |
| 573 | continue; |
| 574 | |
| 575 | for (const Token *subexpr = expr; subexpr; subexpr = subexpr->astOperand1()) { |
| 576 | if (subexpr != addrOf && isSameExpression(macro, subexpr, addrOf, mSettings, pure, followVar)) |
| 577 | return true; |
| 578 | } |
| 579 | } |
| 580 | return false; |
| 581 | } |
| 582 | |
| 583 | bool FwdAnalysis::isEscapedAlias(const Token* expr) |
| 584 | { |
nothing calls this directly
no test coverage detected