Skip to content

Commit 6b82040

Browse files
committed
Manually merged main:a88f4f1962b4 into amd-gfx:bc0af40b24d3
Local branch amd-gfx bc0af40 [AMDGPU] Prepare waterfall support for upstream changes (llvm#876) Remote branch main a88f4f1 AMDGPU: Fix a test typo reading a partially undefined vectorMerge commit 'a88f4f1962b4' into merge-candidate
2 parents bc0af40 + a88f4f1 commit 6b82040

File tree

1,428 files changed

+61292
-30236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,428 files changed

+61292
-30236
lines changed

.github/workflows/release-binaries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
# 2-3 hours to build on macOS, much slower than on Linux.
143143
# The long build time causes the release build to time out on x86_64,
144144
# so we need to disable flang there.
145-
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;bolt;polly;mlir'"
145+
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;polly;mlir'"
146146
fi
147147
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches"
148148
fi

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "bolt/Core/DynoStats.h"
1616
#include "bolt/Core/HashUtilities.h"
1717
#include "bolt/Core/MCPlusBuilder.h"
18+
#include "bolt/Utils/CommandLineOpts.h"
1819
#include "bolt/Utils/NameResolver.h"
1920
#include "bolt/Utils/NameShortener.h"
2021
#include "bolt/Utils/Utils.h"
@@ -1753,8 +1754,8 @@ void BinaryFunction::postProcessEntryPoints() {
17531754
// In non-relocation mode there's potentially an external undetectable
17541755
// reference to the entry point and hence we cannot move this entry
17551756
// point. Optimizing without moving could be difficult.
1756-
// In BAT mode, register any known entry points for CFG construction.
1757-
if (!BC.HasRelocations && !BC.HasBATSection)
1757+
// In aggregation, register any known entry points for CFG construction.
1758+
if (!BC.HasRelocations && !opts::AggregateOnly)
17581759
setSimple(false);
17591760

17601761
const uint32_t Offset = KV.first;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,10 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
831831
ParentFunc = FromFunc;
832832
ParentFunc->SampleCountInBytes += Count * (Second.From - First.To);
833833

834+
const uint64_t FuncAddress = FromFunc->getAddress();
834835
std::optional<BoltAddressTranslation::FallthroughListTy> FTs =
835-
BAT ? BAT->getFallthroughsInTrace(FromFunc->getAddress(), First.To,
836-
Second.From)
836+
BAT && BAT->isBATFunction(FuncAddress)
837+
? BAT->getFallthroughsInTrace(FuncAddress, First.To, Second.From)
837838
: getFallthroughsInTrace(*FromFunc, First, Second, Count);
838839
if (!FTs) {
839840
LLVM_DEBUG(

bolt/test/X86/bolt-address-translation-yaml.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ YAML-BAT-CHECK-NEXT: - bid: 0
6161
YAML-BAT-CHECK-NEXT: insns: 26
6262
YAML-BAT-CHECK-NEXT: hash: 0xA900AE79CFD40000
6363
YAML-BAT-CHECK-NEXT: succ: [ { bid: 3, cnt: 0 }, { bid: 1, cnt: 0 } ]
64+
# Check fallthroughs in non-BAT function
65+
YAML-BAT-CHECK-NEXT: - bid: 27
66+
YAML-BAT-CHECK-NEXT: insns: 3
67+
YAML-BAT-CHECK-NEXT: hash: 0x30A1EBA77A903F0
68+
YAML-BAT-CHECK-NEXT: succ: [ { bid: 28, cnt: 1 } ]
6469
# Calls from no-BAT to BAT function
6570
YAML-BAT-CHECK: - bid: 28
6671
YAML-BAT-CHECK-NEXT: insns: 13

bolt/test/X86/entry-point-fallthru.s

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Checks that fallthroughs spanning entry points are accepted in aggregation
2+
## mode.
3+
4+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
5+
# RUN: ld.lld %t.o -o %t
6+
# RUN: link_fdata %s %t %t.preagg PREAGG
7+
# RUN: perf2bolt %t -p %t.preagg --pa -o %t.fdata | FileCheck %s
8+
# CHECK: traces mismatching disassembled function contents: 0
9+
10+
.globl main
11+
main:
12+
.cfi_startproc
13+
vmovaps %zmm31,%zmm3
14+
15+
next:
16+
add $0x4,%r9
17+
add $0x40,%r10
18+
dec %r14
19+
Ljmp:
20+
jne main
21+
# PREAGG: T #Ljmp# #main# #Ljmp# 1
22+
ret
23+
.cfi_endproc
24+
.size main,.-main

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#include "UndelegatedConstructorCheck.h"
9191
#include "UnhandledExceptionAtNewCheck.h"
9292
#include "UnhandledSelfAssignmentCheck.h"
93+
#include "UnintendedCharOstreamOutputCheck.h"
9394
#include "UniquePtrArrayMismatchCheck.h"
9495
#include "UnsafeFunctionsCheck.h"
9596
#include "UnusedLocalNonTrivialVariableCheck.h"
@@ -147,6 +148,8 @@ class BugproneModule : public ClangTidyModule {
147148
"bugprone-incorrect-enable-if");
148149
CheckFactories.registerCheck<IncorrectEnableSharedFromThisCheck>(
149150
"bugprone-incorrect-enable-shared-from-this");
151+
CheckFactories.registerCheck<UnintendedCharOstreamOutputCheck>(
152+
"bugprone-unintended-char-ostream-output");
150153
CheckFactories.registerCheck<ReturnConstRefFromParameterCheck>(
151154
"bugprone-return-const-ref-from-parameter");
152155
CheckFactories.registerCheck<SwitchMissingDefaultCaseCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_clang_library(clangTidyBugproneModule STATIC
2929
InaccurateEraseCheck.cpp
3030
IncorrectEnableIfCheck.cpp
3131
IncorrectEnableSharedFromThisCheck.cpp
32+
UnintendedCharOstreamOutputCheck.cpp
3233
ReturnConstRefFromParameterCheck.cpp
3334
SuspiciousStringviewDataUsageCheck.cpp
3435
SwitchMissingDefaultCaseCheck.cpp
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===--- UnintendedCharOstreamOutputCheck.cpp - clang-tidy ----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "UnintendedCharOstreamOutputCheck.h"
10+
#include "clang/AST/Type.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/ASTMatchers/ASTMatchers.h"
13+
#include "clang/Basic/Diagnostic.h"
14+
#include "clang/Tooling/FixIt.h"
15+
16+
using namespace clang::ast_matchers;
17+
18+
namespace clang::tidy::bugprone {
19+
20+
namespace {
21+
22+
// check if the type is unsigned char or signed char
23+
AST_MATCHER(Type, isNumericChar) {
24+
return Node.isSpecificBuiltinType(BuiltinType::SChar) ||
25+
Node.isSpecificBuiltinType(BuiltinType::UChar);
26+
}
27+
28+
// check if the type is char
29+
AST_MATCHER(Type, isChar) {
30+
return Node.isSpecificBuiltinType(BuiltinType::Char_S) ||
31+
Node.isSpecificBuiltinType(BuiltinType::Char_U);
32+
}
33+
34+
} // namespace
35+
36+
UnintendedCharOstreamOutputCheck::UnintendedCharOstreamOutputCheck(
37+
StringRef Name, ClangTidyContext *Context)
38+
: ClangTidyCheck(Name, Context), CastTypeName(Options.get("CastTypeName")) {
39+
}
40+
void UnintendedCharOstreamOutputCheck::storeOptions(
41+
ClangTidyOptions::OptionMap &Opts) {
42+
if (CastTypeName.has_value())
43+
Options.store(Opts, "CastTypeName", CastTypeName.value());
44+
}
45+
46+
void UnintendedCharOstreamOutputCheck::registerMatchers(MatchFinder *Finder) {
47+
auto BasicOstream =
48+
cxxRecordDecl(hasName("::std::basic_ostream"),
49+
// only basic_ostream<char, Traits> has overload operator<<
50+
// with char / unsigned char / signed char
51+
classTemplateSpecializationDecl(
52+
hasTemplateArgument(0, refersToType(isChar()))));
53+
Finder->addMatcher(
54+
cxxOperatorCallExpr(
55+
hasOverloadedOperatorName("<<"),
56+
hasLHS(hasType(hasUnqualifiedDesugaredType(
57+
recordType(hasDeclaration(cxxRecordDecl(
58+
anyOf(BasicOstream, isDerivedFrom(BasicOstream)))))))),
59+
hasRHS(hasType(hasUnqualifiedDesugaredType(isNumericChar()))))
60+
.bind("x"),
61+
this);
62+
}
63+
64+
void UnintendedCharOstreamOutputCheck::check(
65+
const MatchFinder::MatchResult &Result) {
66+
const auto *Call = Result.Nodes.getNodeAs<CXXOperatorCallExpr>("x");
67+
const Expr *Value = Call->getArg(1);
68+
const SourceRange SourceRange = Value->getSourceRange();
69+
70+
DiagnosticBuilder Builder =
71+
diag(Call->getOperatorLoc(),
72+
"%0 passed to 'operator<<' outputs as character instead of integer. "
73+
"cast to 'unsigned int' to print numeric value or cast to 'char' to "
74+
"print as character")
75+
<< Value->getType() << SourceRange;
76+
77+
QualType T = Value->getType();
78+
const Type *UnqualifiedDesugaredType = T->getUnqualifiedDesugaredType();
79+
80+
llvm::StringRef CastType = CastTypeName.value_or(
81+
UnqualifiedDesugaredType->isSpecificBuiltinType(BuiltinType::SChar)
82+
? "int"
83+
: "unsigned int");
84+
85+
Builder << FixItHint::CreateReplacement(
86+
SourceRange, ("static_cast<" + CastType + ">(" +
87+
tooling::fixit::getText(*Value, *Result.Context) + ")")
88+
.str());
89+
}
90+
91+
} // namespace clang::tidy::bugprone
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===--- UnintendedCharOstreamOutputCheck.h - clang-tidy --------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNINTENDEDCHAROSTREAMOUTPUTCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNINTENDEDCHAROSTREAMOUTPUTCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
#include <optional>
14+
15+
namespace clang::tidy::bugprone {
16+
17+
/// Finds unintended character output from `unsigned char` and `signed char` to
18+
/// an ostream.
19+
///
20+
/// For the user-facing documentation see:
21+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/unintended-char-ostream-output.html
22+
class UnintendedCharOstreamOutputCheck : public ClangTidyCheck {
23+
public:
24+
UnintendedCharOstreamOutputCheck(StringRef Name, ClangTidyContext *Context);
25+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
26+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
27+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
28+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
29+
return LangOpts.CPlusPlus;
30+
}
31+
32+
private:
33+
const std::optional<StringRef> CastTypeName;
34+
};
35+
36+
} // namespace clang::tidy::bugprone
37+
38+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNINTENDEDCHAROSTREAMOUTPUTCHECK_H

clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) {
4444
unless(isInTemplateInstantiation()))
4545
.bind("call-move");
4646

47+
// Match ternary expressions where either branch contains std::move
48+
auto TernaryWithMoveMatcher =
49+
conditionalOperator(hasDescendant(MoveCallMatcher));
50+
4751
Finder->addMatcher(
4852
expr(anyOf(
4953
castExpr(hasSourceExpression(MoveCallMatcher)),
@@ -58,13 +62,15 @@ void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) {
5862
qualType(rValueReferenceType()).bind("invocation-parm-type");
5963
// Matches respective ParmVarDecl for a CallExpr or CXXConstructExpr.
6064
auto ArgumentWithParamMatcher = forEachArgumentWithParam(
61-
MoveCallMatcher, parmVarDecl(anyOf(hasType(ConstTypeParmMatcher),
62-
hasType(RValueTypeParmMatcher)))
63-
.bind("invocation-parm"));
65+
anyOf(MoveCallMatcher, TernaryWithMoveMatcher),
66+
parmVarDecl(
67+
anyOf(hasType(ConstTypeParmMatcher), hasType(RValueTypeParmMatcher)))
68+
.bind("invocation-parm"));
6469
// Matches respective types of arguments for a CallExpr or CXXConstructExpr
6570
// and it works on calls through function pointers as well.
6671
auto ArgumentWithParamTypeMatcher = forEachArgumentWithParamType(
67-
MoveCallMatcher, anyOf(ConstTypeParmMatcher, RValueTypeParmMatcher));
72+
anyOf(MoveCallMatcher, TernaryWithMoveMatcher),
73+
anyOf(ConstTypeParmMatcher, RValueTypeParmMatcher));
6874

6975
Finder->addMatcher(
7076
invocation(anyOf(ArgumentWithParamMatcher, ArgumentWithParamTypeMatcher))

0 commit comments

Comments
 (0)