Skip to content

Commit bcf59b0

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:139e0aa68dc23d2aeec05de1ae05ebf2aa5fa11e into amd-gfx:e8d3cc99a1c9
Local branch amd-gfx e8d3cc9 Merged main:96568f3539d8a72432a03257a7a8ed2f36014b59 into amd-gfx:112cc7959e1b Remote branch main 139e0aa Revert "[AArch64] Add intrinsics for multi-vector to ZA array vector accumulators" (llvm#91597)
2 parents e8d3cc9 + 139e0aa commit bcf59b0

File tree

265 files changed

+8558
-7625
lines changed

Some content is hidden

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

265 files changed

+8558
-7625
lines changed

bolt/include/bolt/Passes/IndirectCallPromotion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class IndirectCallPromotion : public BinaryFunctionPass {
104104
struct Location {
105105
MCSymbol *Sym{nullptr};
106106
uint64_t Addr{0};
107-
bool isValid() const { return Sym || (!Sym && Addr != 0); }
107+
bool isValid() const { return Sym || Addr != 0; }
108108
Location() {}
109109
explicit Location(MCSymbol *Sym) : Sym(Sym) {}
110110
explicit Location(uint64_t Addr) : Addr(Addr) {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.globl main
2+
.type main, %function
3+
main:
4+
.cfi_startproc
5+
cmpq $0x3, %rdi
6+
jae .L4
7+
cmpq $0x1, %rdi
8+
jne .L4
9+
mov .Ljt_pic+8(%rip), %rax
10+
lea .Ljt_pic(%rip), %rdx
11+
add %rdx, %rax
12+
jmpq *%rax
13+
.L1:
14+
movq $0x1, %rax
15+
jmp .L5
16+
.L2:
17+
movq $0x0, %rax
18+
jmp .L5
19+
.L3:
20+
movq $0x2, %rax
21+
jmp .L5
22+
.L4:
23+
mov $0x3, %rax
24+
.L5:
25+
retq
26+
.cfi_endproc
27+
28+
.section .rodata
29+
.align 16
30+
.Ljt_pic:
31+
.long .L1 - .Ljt_pic
32+
.long .L2 - .Ljt_pic
33+
.long .L3 - .Ljt_pic
34+
.long .L4 - .Ljt_pic
35+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Verify that BOLT detects fixed destination of indirect jump for PIC
2+
# case.
3+
4+
XFAIL: *
5+
6+
RUN: %clang %cflags -no-pie %S/Inputs/jump-table-fixed-ref-pic.s -Wl,-q -o %t
7+
RUN: llvm-bolt %t --relocs -o %t.null 2>&1 | FileCheck %s
8+
9+
CHECK: BOLT-INFO: fixed indirect branch detected in main

clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,43 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "StringCompareCheck.h"
10-
#include "../utils/FixItHintUtils.h"
10+
#include "../utils/OptionsUtils.h"
1111
#include "clang/AST/ASTContext.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
1314
#include "clang/Tooling/FixIt.h"
15+
#include "llvm/ADT/StringRef.h"
1416

1517
using namespace clang::ast_matchers;
18+
namespace optutils = clang::tidy::utils::options;
1619

1720
namespace clang::tidy::readability {
1821

1922
static const StringRef CompareMessage = "do not use 'compare' to test equality "
2023
"of strings; use the string equality "
2124
"operator instead";
2225

26+
static const StringRef DefaultStringLikeClasses = "::std::basic_string;"
27+
"::std::basic_string_view";
28+
29+
StringCompareCheck::StringCompareCheck(StringRef Name,
30+
ClangTidyContext *Context)
31+
: ClangTidyCheck(Name, Context),
32+
StringLikeClasses(optutils::parseStringList(
33+
Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
34+
35+
void StringCompareCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
36+
Options.store(Opts, "StringLikeClasses",
37+
optutils::serializeStringList(StringLikeClasses));
38+
}
39+
2340
void StringCompareCheck::registerMatchers(MatchFinder *Finder) {
41+
if (StringLikeClasses.empty()) {
42+
return;
43+
}
2444
const auto StrCompare = cxxMemberCallExpr(
25-
callee(cxxMethodDecl(hasName("compare"),
26-
ofClass(classTemplateSpecializationDecl(
27-
hasName("::std::basic_string"))))),
45+
callee(cxxMethodDecl(hasName("compare"), ofClass(cxxRecordDecl(hasAnyName(
46+
StringLikeClasses))))),
2847
hasArgument(0, expr().bind("str2")), argumentCountIs(1),
2948
callee(memberExpr().bind("str1")));
3049

clang-tools-extra/clang-tidy/readability/StringCompareCheck.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STRINGCOMPARECHECK_H
1111

1212
#include "../ClangTidyCheck.h"
13+
#include <vector>
1314

1415
namespace clang::tidy::readability {
1516

@@ -20,13 +21,18 @@ namespace clang::tidy::readability {
2021
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/string-compare.html
2122
class StringCompareCheck : public ClangTidyCheck {
2223
public:
23-
StringCompareCheck(StringRef Name, ClangTidyContext *Context)
24-
: ClangTidyCheck(Name, Context) {}
24+
StringCompareCheck(StringRef Name, ClangTidyContext *Context);
25+
2526
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2627
return LangOpts.CPlusPlus;
2728
}
29+
2830
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2931
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
33+
34+
private:
35+
const std::vector<StringRef> StringLikeClasses;
3036
};
3137

3238
} // namespace clang::tidy::readability

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ Changes in existing checks
362362
check by resolving fix-it overlaps in template code by disregarding implicit
363363
instances.
364364

365+
- Improved :doc:`readability-string-compare
366+
<clang-tidy/checks/readability/string-compare>` check to also detect
367+
usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
368+
to detect usages of ``compare`` method in custom string-like classes.
369+
365370
Removed checks
366371
^^^^^^^^^^^^^^
367372

clang-tools-extra/docs/clang-tidy/checks/readability/string-compare.rst

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ recommended to avoid the risk of incorrect interpretation of the return value
1414
and to simplify the code. The string equality and inequality operators can
1515
also be faster than the ``compare`` method due to early termination.
1616

17-
Examples:
17+
Example
18+
-------
1819

1920
.. code-block:: c++
2021

22+
// The same rules apply to std::string_view.
2123
std::string str1{"a"};
2224
std::string str2{"b"};
2325

@@ -50,5 +52,36 @@ Examples:
5052
}
5153

5254
The above code examples show the list of if-statements that this check will
53-
give a warning for. All of them uses ``compare`` to check if equality or
55+
give a warning for. All of them use ``compare`` to check equality or
5456
inequality of two strings instead of using the correct operators.
57+
58+
Options
59+
-------
60+
61+
.. option:: StringLikeClasses
62+
63+
A string containing semicolon-separated names of string-like classes.
64+
By default contains only ``::std::basic_string``
65+
and ``::std::basic_string_view``. If a class from this list has
66+
a ``compare`` method similar to that of ``std::string``, it will be checked
67+
in the same way.
68+
69+
Example
70+
^^^^^^^
71+
72+
.. code-block:: c++
73+
74+
struct CustomString {
75+
public:
76+
int compare (const CustomString& other) const;
77+
}
78+
79+
CustomString str1;
80+
CustomString str2;
81+
82+
// use str1 != str2 instead.
83+
if (str1.compare(str2)) {
84+
}
85+
86+
If `StringLikeClasses` contains ``CustomString``, the check will suggest
87+
replacing ``compare`` with equality operator.

clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ struct basic_string_view {
108108
constexpr bool starts_with(C ch) const noexcept;
109109
constexpr bool starts_with(const C* s) const;
110110

111+
constexpr int compare(basic_string_view sv) const noexcept;
112+
111113
static constexpr size_t npos = -1;
112114
};
113115

@@ -132,6 +134,14 @@ bool operator==(const std::wstring&, const std::wstring&);
132134
bool operator==(const std::wstring&, const wchar_t*);
133135
bool operator==(const wchar_t*, const std::wstring&);
134136

137+
bool operator==(const std::string_view&, const std::string_view&);
138+
bool operator==(const std::string_view&, const char*);
139+
bool operator==(const char*, const std::string_view&);
140+
141+
bool operator!=(const std::string_view&, const std::string_view&);
142+
bool operator!=(const std::string_view&, const char*);
143+
bool operator!=(const char*, const std::string_view&);
144+
135145
size_t strlen(const char* str);
136146
}
137147

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %check_clang_tidy %s readability-string-compare %t -- -config='{CheckOptions: {readability-string-compare.StringLikeClasses: "CustomStringTemplateBase;CustomStringNonTemplateBase"}}' -- -isystem %clang_tidy_headers
2+
#include <string>
3+
4+
struct CustomStringNonTemplateBase {
5+
int compare(const CustomStringNonTemplateBase& Other) const {
6+
return 123; // value is not important for check
7+
}
8+
};
9+
10+
template <typename T>
11+
struct CustomStringTemplateBase {
12+
int compare(const CustomStringTemplateBase& Other) const {
13+
return 123;
14+
}
15+
};
16+
17+
struct CustomString1 : CustomStringNonTemplateBase {};
18+
struct CustomString2 : CustomStringTemplateBase<char> {};
19+
20+
void CustomStringClasses() {
21+
std::string_view sv1("a");
22+
std::string_view sv2("b");
23+
if (sv1.compare(sv2)) { // No warning - if a std class is not listed in StringLikeClasses, it won't be checked.
24+
}
25+
26+
CustomString1 custom1;
27+
if (custom1.compare(custom1)) {
28+
}
29+
// CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
30+
31+
CustomString2 custom2;
32+
if (custom2.compare(custom2)) {
33+
}
34+
// CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
35+
}

clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,27 @@ void Test() {
6767
if (str1.compare(comp())) {
6868
}
6969
// CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
70+
71+
std::string_view sv1("a");
72+
std::string_view sv2("b");
73+
if (sv1.compare(sv2)) {
74+
}
75+
// CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
76+
}
77+
78+
struct DerivedFromStdString : std::string {};
79+
80+
void TestDerivedClass() {
81+
DerivedFromStdString derived;
82+
if (derived.compare(derived)) {
83+
}
84+
// CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
7085
}
7186

7287
void Valid() {
7388
std::string str1("a", 1);
7489
std::string str2("b", 1);
90+
7591
if (str1 == str2) {
7692
}
7793
if (str1 != str2) {
@@ -96,4 +112,11 @@ void Valid() {
96112
}
97113
if (str1.compare(str2) == -1) {
98114
}
115+
116+
std::string_view sv1("a");
117+
std::string_view sv2("b");
118+
if (sv1 == sv2) {
119+
}
120+
if (sv1.compare(sv2) > 0) {
121+
}
99122
}

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ Bug Fixes to C++ Support
699699
performed incorrectly when checking constraints. Fixes (#GH90349).
700700
- Clang now allows constrained member functions to be explicitly specialized for an implicit instantiation
701701
of a class template.
702+
- Fix a C++23 bug in implementation of P2564R3 which evaluates immediate invocations in place
703+
within initializers for variables that are usable in constant expressions or are constant
704+
initialized, rather than evaluating them as a part of the larger manifestly constant evaluated
705+
expression.
702706

703707
Bug Fixes to AST Handling
704708
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/OpenACCClause.h

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class OpenACCClause {
2626
protected:
2727
OpenACCClause(OpenACCClauseKind K, SourceLocation BeginLoc,
2828
SourceLocation EndLoc)
29-
: Kind(K), Location(BeginLoc, EndLoc) {}
29+
: Kind(K), Location(BeginLoc, EndLoc) {
30+
assert(!BeginLoc.isInvalid() && !EndLoc.isInvalid() &&
31+
"Begin and end location must be valid for OpenACCClause");
32+
}
3033

3134
public:
3235
OpenACCClauseKind getClauseKind() const { return Kind; }
@@ -189,6 +192,46 @@ class OpenACCClauseWithExprs : public OpenACCClauseWithParams {
189192
}
190193
};
191194

195+
// Represents the 'devnum' and expressions lists for the 'wait' clause.
196+
class OpenACCWaitClause final
197+
: public OpenACCClauseWithExprs,
198+
public llvm::TrailingObjects<OpenACCWaitClause, Expr *> {
199+
SourceLocation QueuesLoc;
200+
OpenACCWaitClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
201+
Expr *DevNumExpr, SourceLocation QueuesLoc,
202+
ArrayRef<Expr *> QueueIdExprs, SourceLocation EndLoc)
203+
: OpenACCClauseWithExprs(OpenACCClauseKind::Wait, BeginLoc, LParenLoc,
204+
EndLoc),
205+
QueuesLoc(QueuesLoc) {
206+
// The first element of the trailing storage is always the devnum expr,
207+
// whether it is used or not.
208+
std::uninitialized_copy(&DevNumExpr, &DevNumExpr + 1,
209+
getTrailingObjects<Expr *>());
210+
std::uninitialized_copy(QueueIdExprs.begin(), QueueIdExprs.end(),
211+
getTrailingObjects<Expr *>() + 1);
212+
setExprs(
213+
MutableArrayRef(getTrailingObjects<Expr *>(), QueueIdExprs.size() + 1));
214+
}
215+
216+
public:
217+
static OpenACCWaitClause *Create(const ASTContext &C, SourceLocation BeginLoc,
218+
SourceLocation LParenLoc, Expr *DevNumExpr,
219+
SourceLocation QueuesLoc,
220+
ArrayRef<Expr *> QueueIdExprs,
221+
SourceLocation EndLoc);
222+
223+
bool hasQueuesTag() const { return !QueuesLoc.isInvalid(); }
224+
SourceLocation getQueuesLoc() const { return QueuesLoc; }
225+
bool hasDevNumExpr() const { return getExprs()[0]; }
226+
Expr *getDevNumExpr() const { return getExprs()[0]; }
227+
llvm::ArrayRef<Expr *> getQueueIdExprs() {
228+
return OpenACCClauseWithExprs::getExprs().drop_front();
229+
}
230+
llvm::ArrayRef<Expr *> getQueueIdExprs() const {
231+
return OpenACCClauseWithExprs::getExprs().drop_front();
232+
}
233+
};
234+
192235
class OpenACCNumGangsClause final
193236
: public OpenACCClauseWithExprs,
194237
public llvm::TrailingObjects<OpenACCNumGangsClause, Expr *> {

clang/include/clang/Basic/Features.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
103103
FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
104104
FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
105105
FEATURE(ptrauth_intrinsics, LangOpts.PointerAuthIntrinsics)
106+
FEATURE(ptrauth_calls, LangOpts.PointerAuthCalls)
107+
FEATURE(ptrauth_returns, LangOpts.PointerAuthReturns)
108+
FEATURE(ptrauth_vtable_pointer_address_discrimination, LangOpts.PointerAuthVTPtrAddressDiscrimination)
109+
FEATURE(ptrauth_vtable_pointer_type_discrimination, LangOpts.PointerAuthVTPtrTypeDiscrimination)
110+
FEATURE(ptrauth_member_function_pointer_type_discrimination, LangOpts.PointerAuthCalls)
111+
FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
106112
EXTENSION(swiftcc,
107113
PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
108114
clang::TargetInfo::CCCR_OK)

clang/include/clang/Basic/LangOptions.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ LANGOPT(RelaxedTemplateTemplateArgs, 1, 1, "C++17 relaxed matching of template t
162162
LANGOPT(ExperimentalLibrary, 1, 0, "enable unstable and experimental library features")
163163

164164
LANGOPT(PointerAuthIntrinsics, 1, 0, "pointer authentication intrinsics")
165+
LANGOPT(PointerAuthCalls , 1, 0, "function pointer authentication")
166+
LANGOPT(PointerAuthReturns, 1, 0, "return pointer authentication")
167+
LANGOPT(PointerAuthAuthTraps, 1, 0, "pointer authentication failure traps")
168+
LANGOPT(PointerAuthVTPtrAddressDiscrimination, 1, 0, "incorporate address discrimination in authenticated vtable pointers")
169+
LANGOPT(PointerAuthVTPtrTypeDiscrimination, 1, 0, "incorporate type discrimination in authenticated vtable pointers")
170+
LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers in init/fini arrays")
165171

166172
LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes")
167173
LANGOPT(ExperimentalLateParseAttributes, 1, 0, "experimental late parsing of attributes")

clang/include/clang/Basic/OpenACCClauses.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ VISIT_CLAUSE(Present)
4646
VISIT_CLAUSE(Private)
4747
VISIT_CLAUSE(Self)
4848
VISIT_CLAUSE(VectorLength)
49+
VISIT_CLAUSE(Wait)
4950

5051
#undef VISIT_CLAUSE
5152
#undef CLAUSE_ALIAS

0 commit comments

Comments
 (0)