forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged main:23f8fac745bdde70ed4f9c585d19c4913734f1b8 into amd-gfx:f0d…
…aa1f61373 Local branch amd-gfx f0daa1f Merged main:89a080cb79972abae240c226090af9a3094e2269 into amd-gfx:93971a479db3 Remote branch main 23f8fac Revert "Repply#2 "[RemoveDIs] Load into new debug info format by default in LLVM (llvm#89799)""
- Loading branch information
Showing
225 changed files
with
12,835 additions
and
5,665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: PR Request Release Note | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
|
||
jobs: | ||
request-release-note: | ||
if: >- | ||
github.repository_owner == 'llvm' && | ||
startsWith(github.ref, 'refs/heads/release') | ||
runs-on: ubuntu-latest | ||
steps: | ||
# We need to pull the script from the main branch, so that we ensure | ||
# we get the latest version of this script. | ||
- name: Checkout Scripts | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
with: | ||
sparse-checkout: | | ||
llvm/utils/git/requirements.txt | ||
llvm/utils/git/github-automation.py | ||
sparse-checkout-cone-mode: false | ||
|
||
- name: Install Dependencies | ||
run: | | ||
pip install -r llvm/utils/git/requirements.txt | ||
- name: Request Release Note | ||
env: | ||
# We need to use an llvmbot token here, because we are mentioning a user. | ||
GITHUB_TOKEN: ${{ github.token }} | ||
run: | | ||
python3 llvm/utils/git/github-automation.py \ | ||
--repo "$GITHUB_REPOSITORY" \ | ||
--token "$GITHUB_TOKEN" \ | ||
request-release-note \ | ||
--pr-number ${{ github.event.pull_request.number}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
B 800154 401050 20 0 | ||
F 800159 800193 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
//===--- UseStdFormatCheck.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 "UseStdFormatCheck.h" | ||
#include "../utils/FormatStringConverter.h" | ||
#include "../utils/Matchers.h" | ||
#include "../utils/OptionsUtils.h" | ||
#include "clang/ASTMatchers/ASTMatchFinder.h" | ||
#include "clang/Lex/Lexer.h" | ||
#include "clang/Tooling/FixIt.h" | ||
|
||
using namespace clang::ast_matchers; | ||
|
||
namespace clang::tidy::modernize { | ||
|
||
namespace { | ||
AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); } | ||
} // namespace | ||
|
||
UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context) | ||
: ClangTidyCheck(Name, Context), | ||
StrictMode(Options.getLocalOrGlobal("StrictMode", false)), | ||
StrFormatLikeFunctions(utils::options::parseStringList( | ||
Options.get("StrFormatLikeFunctions", ""))), | ||
ReplacementFormatFunction( | ||
Options.get("ReplacementFormatFunction", "std::format")), | ||
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", | ||
utils::IncludeSorter::IS_LLVM), | ||
areDiagsSelfContained()), | ||
MaybeHeaderToInclude(Options.get("FormatHeader")) { | ||
if (StrFormatLikeFunctions.empty()) | ||
StrFormatLikeFunctions.push_back("absl::StrFormat"); | ||
|
||
if (!MaybeHeaderToInclude && ReplacementFormatFunction == "std::format") | ||
MaybeHeaderToInclude = "<format>"; | ||
} | ||
|
||
void UseStdFormatCheck::registerPPCallbacks(const SourceManager &SM, | ||
Preprocessor *PP, | ||
Preprocessor *ModuleExpanderPP) { | ||
IncludeInserter.registerPreprocessor(PP); | ||
} | ||
|
||
void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) { | ||
Finder->addMatcher( | ||
callExpr(argumentCountAtLeast(1), | ||
hasArgument(0, stringLiteral(isOrdinary())), | ||
callee(functionDecl(unless(cxxMethodDecl()), | ||
matchers::matchesAnyListedName( | ||
StrFormatLikeFunctions)) | ||
.bind("func_decl"))) | ||
.bind("strformat"), | ||
this); | ||
} | ||
|
||
void UseStdFormatCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { | ||
using utils::options::serializeStringList; | ||
Options.store(Opts, "StrictMode", StrictMode); | ||
Options.store(Opts, "StrFormatLikeFunctions", | ||
serializeStringList(StrFormatLikeFunctions)); | ||
Options.store(Opts, "ReplacementFormatFunction", ReplacementFormatFunction); | ||
Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); | ||
if (MaybeHeaderToInclude) | ||
Options.store(Opts, "FormatHeader", *MaybeHeaderToInclude); | ||
} | ||
|
||
void UseStdFormatCheck::check(const MatchFinder::MatchResult &Result) { | ||
const unsigned FormatArgOffset = 0; | ||
const auto *OldFunction = Result.Nodes.getNodeAs<FunctionDecl>("func_decl"); | ||
const auto *StrFormat = Result.Nodes.getNodeAs<CallExpr>("strformat"); | ||
|
||
utils::FormatStringConverter::Configuration ConverterConfig; | ||
ConverterConfig.StrictMode = StrictMode; | ||
utils::FormatStringConverter Converter(Result.Context, StrFormat, | ||
FormatArgOffset, ConverterConfig, | ||
getLangOpts()); | ||
const Expr *StrFormatCall = StrFormat->getCallee(); | ||
if (!Converter.canApply()) { | ||
diag(StrFormat->getBeginLoc(), | ||
"unable to use '%0' instead of %1 because %2") | ||
<< StrFormatCall->getSourceRange() << ReplacementFormatFunction | ||
<< OldFunction->getIdentifier() | ||
<< Converter.conversionNotPossibleReason(); | ||
return; | ||
} | ||
|
||
DiagnosticBuilder Diag = | ||
diag(StrFormatCall->getBeginLoc(), "use '%0' instead of %1") | ||
<< ReplacementFormatFunction << OldFunction->getIdentifier(); | ||
Diag << FixItHint::CreateReplacement( | ||
CharSourceRange::getTokenRange(StrFormatCall->getSourceRange()), | ||
ReplacementFormatFunction); | ||
Converter.applyFixes(Diag, *Result.SourceManager); | ||
|
||
if (MaybeHeaderToInclude) | ||
Diag << IncludeInserter.createIncludeInsertion( | ||
Result.Context->getSourceManager().getFileID( | ||
StrFormatCall->getBeginLoc()), | ||
*MaybeHeaderToInclude); | ||
} | ||
|
||
} // namespace clang::tidy::modernize |
51 changes: 51 additions & 0 deletions
51
clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//===--- UseStdFormatCheck.h - clang-tidy -----------------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H | ||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H | ||
|
||
#include "../ClangTidyCheck.h" | ||
#include "../utils/IncludeInserter.h" | ||
|
||
namespace clang::tidy::modernize { | ||
|
||
/// Converts calls to absl::StrFormat, or other functions via configuration | ||
/// options, to C++20's std::format, or another function via a configuration | ||
/// option, modifying the format string appropriately and removing | ||
/// now-unnecessary calls to std::string::c_str() and std::string::data(). | ||
/// | ||
/// For the user-facing documentation see: | ||
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-format.html | ||
class UseStdFormatCheck : public ClangTidyCheck { | ||
public: | ||
UseStdFormatCheck(StringRef Name, ClangTidyContext *Context); | ||
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { | ||
if (ReplacementFormatFunction == "std::format") | ||
return LangOpts.CPlusPlus20; | ||
return LangOpts.CPlusPlus; | ||
} | ||
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, | ||
Preprocessor *ModuleExpanderPP) override; | ||
void storeOptions(ClangTidyOptions::OptionMap &Opts) override; | ||
void registerMatchers(ast_matchers::MatchFinder *Finder) override; | ||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override; | ||
std::optional<TraversalKind> getCheckTraversalKind() const override { | ||
return TK_IgnoreUnlessSpelledInSource; | ||
} | ||
|
||
private: | ||
bool StrictMode; | ||
std::vector<StringRef> StrFormatLikeFunctions; | ||
StringRef ReplacementFormatFunction; | ||
utils::IncludeInserter IncludeInserter; | ||
std::optional<StringRef> MaybeHeaderToInclude; | ||
}; | ||
|
||
} // namespace clang::tidy::modernize | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.