Skip to content

Commit

Permalink
Merge "merge main into amd-staging" into amd-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
ronlieb committed Jul 16, 2024
2 parents e1fc3a5 + 703e6cc commit 7f31070
Show file tree
Hide file tree
Showing 389 changed files with 51,001 additions and 15,009 deletions.
3 changes: 2 additions & 1 deletion bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,8 @@ class MCPlusBuilder {
/// Returns a function body that contains only a return instruction. An
/// example usage is a workaround for the '__bolt_fini_trampoline' of
// Instrumentation.
virtual InstructionListType createDummyReturnFunction(MCContext *Ctx) const {
virtual InstructionListType
createReturnInstructionList(MCContext *Ctx) const {
InstructionListType Insts(1);
createReturn(Insts[0]);
return Insts;
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Passes/Instrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ void Instrumentation::createAuxiliaryFunctions(BinaryContext &BC) {
// with unknown symbol in runtime library. E.g. for static PIE
// executable
createSimpleFunction("__bolt_fini_trampoline",
BC.MIB->createDummyReturnFunction(BC.Ctx.get()));
BC.MIB->createReturnInstructionList(BC.Ctx.get()));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/test/X86/match-functions-with-calls-as-anchors.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Tests blocks matching by called function names in inferStaleProfile.

# REQUIRES: system-linux
# REQUIRES: system-linux, asserts
# RUN: split-file %s %t
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
Expand Down
15 changes: 9 additions & 6 deletions clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,15 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {

UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context)
: utils::UseRangesCheck(Name, Context),
IncludeBoostSystem(Options.get("IncludeBoostSystem", true)) {}
IncludeBoostSystem(Options.get("IncludeBoostSystem", true)),
UseReversePipe(Options.get("UseReversePipe", false)) {}

void UseRangesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
utils::UseRangesCheck::storeOptions(Opts);
Options.store(Opts, "IncludeBoostSystem", IncludeBoostSystem);
Options.store(Opts, "UseReversePipe", UseReversePipe);
}

DiagnosticBuilder UseRangesCheck::createDiag(const CallExpr &Call) {
DiagnosticBuilder D =
diag(Call.getBeginLoc(), "use a %0 version of this algorithm");
Expand All @@ -362,10 +365,10 @@ UseRangesCheck::getReverseDescriptor() const {
{"::boost::rbegin", "::boost::rend"},
{"::boost::const_rbegin", "::boost::const_rend"},
};
return ReverseIteratorDescriptor{"boost::adaptors::reverse",
IncludeBoostSystem
? "<boost/range/adaptor/reversed.hpp>"
: "boost/range/adaptor/reversed.hpp",
Refs};
return ReverseIteratorDescriptor{
UseReversePipe ? "boost::adaptors::reversed" : "boost::adaptors::reverse",
IncludeBoostSystem ? "<boost/range/adaptor/reversed.hpp>"
: "boost/range/adaptor/reversed.hpp",
Refs, UseReversePipe};
}
} // namespace clang::tidy::boost
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/boost/UseRangesCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class UseRangesCheck : public utils::UseRangesCheck {

private:
bool IncludeBoostSystem;
bool UseReversePipe;
};

} // namespace clang::tidy::boost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static bool haveSameNamespaceOrTranslationUnit(const CXXRecordDecl *Decl1,
"ParentDecl2 declaration must be a namespace");
auto *Ns1 = NamespaceDecl::castFromDeclContext(ParentDecl1);
auto *Ns2 = NamespaceDecl::castFromDeclContext(ParentDecl2);
return Ns1->getOriginalNamespace() == Ns2->getOriginalNamespace();
return Ns1->getFirstDecl() == Ns2->getFirstDecl();
}

static std::string getNameOfNamespace(const CXXRecordDecl *Decl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ImplicitWideningOfMultiplicationResultCheck::
UseCXXStaticCastsInCppSources(
Options.get("UseCXXStaticCastsInCppSources", true)),
UseCXXHeadersInCppSources(Options.get("UseCXXHeadersInCppSources", true)),
IgnoreConstantIntExpr(Options.get("IgnoreConstantIntExpr", false)),
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
utils::IncludeSorter::IS_LLVM),
areDiagsSelfContained()) {}
Expand All @@ -56,6 +57,7 @@ void ImplicitWideningOfMultiplicationResultCheck::storeOptions(
Options.store(Opts, "UseCXXStaticCastsInCppSources",
UseCXXStaticCastsInCppSources);
Options.store(Opts, "UseCXXHeadersInCppSources", UseCXXHeadersInCppSources);
Options.store(Opts, "IgnoreConstantIntExpr", IgnoreConstantIntExpr);
Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
}

Expand Down Expand Up @@ -84,6 +86,19 @@ void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
if (TgtWidth <= SrcWidth)
return;

// Is the expression a compile-time constexpr that we know can fit in the
// source type?
if (IgnoreConstantIntExpr && ETy->isIntegerType() &&
!ETy->isUnsignedIntegerType()) {
if (const auto ConstExprResult = E->getIntegerConstantExpr(*Context)) {
const auto TypeSize = Context->getTypeSize(ETy);
llvm::APSInt WidenedResult = ConstExprResult->extOrTrunc(TypeSize);
if (WidenedResult <= llvm::APSInt::getMaxValue(TypeSize, false) &&
WidenedResult >= llvm::APSInt::getMinValue(TypeSize, false))
return;
}
}

// Does the index expression look like it might be unintentionally computed
// in a narrower-than-wanted type?
const Expr *LHS = getLHSOfMulBinOp(E);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ImplicitWideningOfMultiplicationResultCheck : public ClangTidyCheck {
private:
const bool UseCXXStaticCastsInCppSources;
const bool UseCXXHeadersInCppSources;
const bool IgnoreConstantIntExpr;
utils::IncludeInserter IncludeInserter;
};

Expand Down
13 changes: 12 additions & 1 deletion clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
return Result;
}

UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context)
: utils::UseRangesCheck(Name, Context),
UseReversePipe(Options.get("UseReversePipe", false)) {}

void UseRangesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
utils::UseRangesCheck::storeOptions(Opts);
Options.store(Opts, "UseReversePipe", UseReversePipe);
}

bool UseRangesCheck::isLanguageVersionSupported(
const LangOptions &LangOpts) const {
return LangOpts.CPlusPlus20;
Expand All @@ -180,6 +189,8 @@ std::optional<UseRangesCheck::ReverseIteratorDescriptor>
UseRangesCheck::getReverseDescriptor() const {
static const std::pair<StringRef, StringRef> Refs[] = {
{"::std::rbegin", "::std::rend"}, {"::std::crbegin", "::std::crend"}};
return ReverseIteratorDescriptor{"std::views::reverse", "<ranges>", Refs};
return ReverseIteratorDescriptor{UseReversePipe ? "std::views::reverse"
: "std::ranges::reverse_view",
"<ranges>", Refs, UseReversePipe};
}
} // namespace clang::tidy::modernize
7 changes: 6 additions & 1 deletion clang-tools-extra/clang-tidy/modernize/UseRangesCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace clang::tidy::modernize {
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-ranges.html
class UseRangesCheck : public utils::UseRangesCheck {
public:
using utils::UseRangesCheck::UseRangesCheck;
UseRangesCheck(StringRef CheckName, ClangTidyContext *Context);

void storeOptions(ClangTidyOptions::OptionMap &Options) override;

ReplacerMap getReplacerMap() const override;

Expand All @@ -31,6 +33,9 @@ class UseRangesCheck : public utils::UseRangesCheck {
getReverseDescriptor() const override;

bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;

private:
bool UseReversePipe;
};

} // namespace clang::tidy::modernize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void UnnecessaryValueParamCheck::registerMatchers(MatchFinder *Finder) {
functionDecl(hasBody(stmt()), isDefinition(), unless(isImplicit()),
unless(cxxMethodDecl(anyOf(isOverride(), isFinal()))),
has(typeLoc(forEach(ExpensiveValueParamDecl))),
unless(isInstantiated()), decl().bind("functionDecl"))),
decl().bind("functionDecl"))),
this);
}

Expand Down Expand Up @@ -133,12 +133,11 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) {
// 2. the function is virtual as it might break overrides
// 3. the function is referenced outside of a call expression within the
// compilation unit as the signature change could introduce build errors.
// 4. the function is a primary template or an explicit template
// specialization.
// 4. the function is an explicit template/ specialization.
const auto *Method = llvm::dyn_cast<CXXMethodDecl>(Function);
if (Param->getBeginLoc().isMacroID() || (Method && Method->isVirtual()) ||
isReferencedOutsideOfCallExpr(*Function, *Result.Context) ||
(Function->getTemplatedKind() != FunctionDecl::TK_NonTemplate))
Function->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
return;
for (const auto *FunctionDecl = Function; FunctionDecl != nullptr;
FunctionDecl = FunctionDecl->getPreviousDecl()) {
Expand Down
18 changes: 11 additions & 7 deletions clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,20 @@ void UseRangesCheck::check(const MatchFinder::MatchResult &Result) {
Diag << Inserter.createIncludeInsertion(
Result.SourceManager->getFileID(Call->getBeginLoc()),
*ReverseDescriptor->ReverseHeader);
StringRef ArgText = Lexer::getSourceText(
CharSourceRange::getTokenRange(ArgExpr->getSourceRange()),
Result.Context->getSourceManager(), Result.Context->getLangOpts());
SmallString<128> ReplaceText;
if (ReverseDescriptor->IsPipeSyntax)
ReplaceText.assign(
{ArgText, " | ", ReverseDescriptor->ReverseAdaptorName});
else
ReplaceText.assign(
{ReverseDescriptor->ReverseAdaptorName, "(", ArgText, ")"});
Diag << FixItHint::CreateReplacement(
Call->getArg(Replace == Indexes::Second ? Second : First)
->getSourceRange(),
SmallString<128>{
ReverseDescriptor->ReverseAdaptorName, "(",
Lexer::getSourceText(
CharSourceRange::getTokenRange(ArgExpr->getSourceRange()),
Result.Context->getSourceManager(),
Result.Context->getLangOpts()),
")"});
ReplaceText);
}
ToRemove.push_back(Replace == Indexes::Second ? First : Second);
}
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/utils/UseRangesCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class UseRangesCheck : public ClangTidyCheck {
StringRef ReverseAdaptorName;
std::optional<StringRef> ReverseHeader;
ArrayRef<std::pair<StringRef, StringRef>> FreeReverseNames;
bool IsPipeSyntax = false;
};

class Replacer : public llvm::RefCountedBase<Replacer> {
Expand Down
11 changes: 11 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ Changes in existing checks
<clang-tidy/checks/bugprone/forwarding-reference-overload>`
check to ignore deleted constructors which won't hide other overloads.

- Improved :doc:`bugprone-implicit-widening-of-multiplication-result
<clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result>` check
by adding an option to ignore constant expressions of signed integer types
that fit in the source expression type.

- Improved :doc:`bugprone-inc-dec-in-conditions
<clang-tidy/checks/bugprone/inc-dec-in-conditions>` check to ignore code
within unevaluated contexts, such as ``decltype``.
Expand Down Expand Up @@ -437,6 +442,12 @@ Changes in existing checks
Calls to mutable function where there exists a `const` overload are also
handled. Fix crash in the case of a non-member operator call.

- Improved :doc:`performance-unnecessary-value-param
<clang-tidy/checks/performance/unnecessary-value-param>` check
detecting more cases for template functions including lambdas with ``auto``.
E.g., ``std::sort(a.begin(), a.end(), [](auto x, auto y) { return a > b; });``
will be detected for expensive to copy types.

- Improved :doc:`readability-avoid-return-with-void-value
<clang-tidy/checks/readability/avoid-return-with-void-value>` check by adding
fix-its.
Expand Down
19 changes: 17 additions & 2 deletions clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ Transforms to:

.. code-block:: c++

auto AreSame = std::equal(boost::adaptors::reverse(Items1),
boost::adaptors::reverse(Items2));
auto AreSame = boost::range::equal(boost::adaptors::reverse(Items1),
boost::adaptors::reverse(Items2));

Options
-------
Expand All @@ -170,3 +170,18 @@ Options
If `true` (default value) the boost headers are included as system headers
with angle brackets (`#include <boost.hpp>`), otherwise quotes are used
(`#include "boost.hpp"`).

.. option:: UseReversePipe

When `true` (default `false`), fixes which involve reverse ranges will use the
pipe adaptor syntax instead of the function syntax.

.. code-block:: c++

std::find(Items.rbegin(), Items.rend(), 0);

Transforms to:

.. code-block:: c++

boost::range::find(Items | boost::adaptors::reversed, 0);
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Options
should ``<cstddef>`` header be suggested, or ``<stddef.h>``.
Defaults to ``true``.

.. option:: IgnoreConstantIntExpr

If the multiplication operands are compile-time constants (like literals or
are ``constexpr``) and fit within the source expression type, do not emit a
diagnostic or suggested fix. Only considers expressions where the source
expression is a signed integer type. Defaults to ``false``.

Examples:

Expand Down
18 changes: 16 additions & 2 deletions clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ Transforms to:

.. code-block:: c++

auto AreSame = std::equal(std::views::reverse(Items1),
std::views::reverse(Items2));
auto AreSame = std::ranges::equal(std::ranges::reverse_view(Items1),
std::ranges::reverse_view(Items2));

Options
-------
Expand All @@ -127,3 +127,17 @@ Options
A string specifying which include-style is used, `llvm` or `google`. Default
is `llvm`.

.. option:: UseReversePipe

When `true` (default `false`), fixes which involve reverse ranges will use the
pipe adaptor syntax instead of the function syntax.

.. code-block:: c++

std::find(Items.rbegin(), Items.rend(), 0);

Transforms to:

.. code-block:: c++

std::ranges::find(Items | std::views::reverse, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef USE_RANGES_FAKE_BOOST_H
#define USE_RANGES_FAKE_BOOST_H

namespace boost {
namespace range_adl_barrier {

template <typename T> void *begin(T &);
template <typename T> void *end(T &);
template <typename T> void *const_begin(const T &);
template <typename T> void *const_end(const T &);
} // namespace range_adl_barrier

using namespace range_adl_barrier;

template <typename T> void *rbegin(T &);
template <typename T> void *rend(T &);

template <typename T> void *const_rbegin(T &);
template <typename T> void *const_rend(T &);
namespace algorithm {

template <class InputIterator, class T, class BinaryOperation>
T reduce(InputIterator first, InputIterator last, T init, BinaryOperation bOp) {
return init;
}
} // namespace algorithm
} // namespace boost

#endif // USE_RANGES_FAKE_BOOST_H
Loading

0 comments on commit 7f31070

Please sign in to comment.