| 3672 | } |
| 3673 | |
| 3674 | bool isGlobalData(const Token *expr) |
| 3675 | { |
| 3676 | // function call that returns reference => assume global data |
| 3677 | if (expr && expr->str() == "(" && expr->valueType() && expr->valueType()->reference != Reference::None) { |
| 3678 | if (expr->isBinaryOp()) |
| 3679 | return true; |
| 3680 | if (expr->astOperand1() && precedes(expr->astOperand1(), expr)) |
| 3681 | return true; |
| 3682 | } |
| 3683 | |
| 3684 | bool globalData = false; |
| 3685 | bool var = false; |
| 3686 | visitAstNodes(expr, |
| 3687 | [expr, &globalData, &var](const Token *tok) { |
| 3688 | if (tok->varId()) |
| 3689 | var = true; |
| 3690 | if (tok->varId() && !tok->variable()) { |
| 3691 | // Bailout, this is probably global |
| 3692 | globalData = true; |
| 3693 | return ChildrenToVisit::none; |
| 3694 | } |
| 3695 | if (tok->originalName() == "->") { |
| 3696 | // TODO check if pointer points at local data |
| 3697 | globalData = true; |
| 3698 | return ChildrenToVisit::none; |
| 3699 | } |
| 3700 | if (Token::Match(tok, "[*[]") && tok->astOperand1()) { |
| 3701 | // TODO check if pointer points at local data |
| 3702 | const Token *lhs = tok->astOperand1(); |
| 3703 | if (lhs->isCast()) { |
| 3704 | lhs = lhs->astOperand2() ? lhs->astOperand2() : lhs->astOperand1(); |
| 3705 | } |
| 3706 | if (lhs && lhs->variable()) { |
| 3707 | const Variable *lhsvar = lhs->variable(); |
| 3708 | const ValueType *lhstype = lhs->valueType(); |
| 3709 | if (lhsvar->isPointer() || !lhstype || lhstype->type == ValueType::Type::ITERATOR) { |
| 3710 | globalData = true; |
| 3711 | return ChildrenToVisit::none; |
| 3712 | } |
| 3713 | if (lhsvar->isArgument() && lhsvar->isArray()) { |
| 3714 | globalData = true; |
| 3715 | return ChildrenToVisit::none; |
| 3716 | } |
| 3717 | if (lhsvar->isArgument() && lhstype->type <= ValueType::Type::VOID && !lhstype->container) { |
| 3718 | globalData = true; |
| 3719 | return ChildrenToVisit::none; |
| 3720 | } |
| 3721 | } |
| 3722 | } |
| 3723 | if (tok->varId() == 0 && tok->isName() && tok->strAt(-1) != ".") { |
| 3724 | globalData = true; |
| 3725 | return ChildrenToVisit::none; |
| 3726 | } |
| 3727 | if (tok->variable()) { |
| 3728 | // TODO : Check references |
| 3729 | if (tok->variable()->isReference() && tok != tok->variable()->nameToken()) { |
| 3730 | globalData = true; |
| 3731 | return ChildrenToVisit::none; |
no test coverage detected