================ @@ -0,0 +1,50 @@ +//===--- DonotreturnzerocheckCheck.cpp - clang-tidy -----------------------===// +// +// 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 "DonotreturnzerocheckCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { +bool isCPlusPlusOrC99(const LangOptions &LangOpts) { + return LangOpts.CPlusPlus || LangOpts.C99; +} + +void DonotreturnzerocheckCheck::registerMatchers(MatchFinder *Finder) { + // FIXME: Add matchers. + Finder->addMatcher( + functionDecl(isMain(), returns(asString("int"))).bind("main"), this); +} + +void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult &Result) { + // FIXME: Add callback implementation. + const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("main"); + if (isCPlusPlusOrC99(Result.Context->getLangOpts())) { + SourceLocation ReturnLoc; + if (MatchedDecl->hasBody()) { + const CompoundStmt *Body = dyn_cast<CompoundStmt>(MatchedDecl->getBody()); + if (Body && !Body->body_empty()) { + const Stmt *LastStmt = Body->body_back(); + if (const auto *Return = dyn_cast<ReturnStmt>(LastStmt)) { + ReturnLoc = Return->getReturnLoc(); + } ---------------- HerrCai0907 wrote:
redundant brace https://github.com/llvm/llvm-project/pull/77586 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits