=?utf-8?q?Balázs_Kéri?= <[email protected]>, =?utf-8?q?Balázs_Kéri?= <[email protected]>, =?utf-8?q?Balázs_Kéri?= <[email protected]>, =?utf-8?q?Balázs_Kéri?= <[email protected]>, =?utf-8?q?Balázs_Kéri?= <[email protected]>, =?utf-8?q?Balázs_Kéri?= <[email protected]>, =?utf-8?q?Balázs_Kéri?= <[email protected]>, =?utf-8?q?Balázs_Kéri?= <[email protected]> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>
================ @@ -0,0 +1,355 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "StaticInitializationCycleCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DynamicRecursiveASTVisitor.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Analysis/CallGraph.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SCCIterator.h" + +using namespace clang; +using namespace clang::ast_matchers; + +// Compute (for the purpose of this check) if the value of a DeclRefExpr is used +// (at runtime). +// The value is not used if it appears at LHS of an assignment or it appears +// inside a compile-time constant expression (like 'sizeof'). +static bool isUnusedValue(const DeclRefExpr *DRE, ASTContext &ACtx) { + ParentMapContext &PMC = ACtx.getParentMapContext(); + DynTypedNodeList Parents = PMC.getParents(*DRE); + const BinaryOperator *ParentBO = nullptr; + while (!Parents.empty()) { + if (const Expr *E = Parents[0].get<Expr>()) { + if (E->isIntegerConstantExpr(ACtx)) + return true; + if ((ParentBO = dyn_cast<BinaryOperator>(E))) + break; + } + Parents = PMC.getParents(Parents[0]); + } ---------------- vbvictor wrote: Could we stop traversing up when some condition is met, e.g. when we hit `CompountStmt`. Walking up to `TranslationUnitDecl` for each `DeclRefExpr` seems like a very expensive operation. https://github.com/llvm/llvm-project/pull/175342 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
