Skip to content

Commit 1b459c6

Browse files
committed
merge main 679e594 into amd-staging
Change-Id: I529c94cf931933d67d65a0f8abdf335affcd3b28
2 parents 5979207 + 679e594 commit 1b459c6

File tree

909 files changed

+32695
-8359
lines changed

Some content is hidden

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

909 files changed

+32695
-8359
lines changed

.github/workflows/llvm-tests.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
BASELINE_REF: ${{ steps.vars.outputs.BASELINE_REF }}
4343
ABI_HEADERS: ${{ steps.vars.outputs.ABI_HEADERS }}
4444
BASELINE_VERSION_MAJOR: ${{ steps.vars.outputs.BASELINE_VERSION_MAJOR }}
45+
BASELINE_VERSION_MINOR: ${{ steps.vars.outputs.BASELINE_VERSION_MINOR }}
4546
LLVM_VERSION_MAJOR: ${{ steps.version.outputs.LLVM_VERSION_MAJOR }}
4647
LLVM_VERSION_MINOR: ${{ steps.version.outputs.LLVM_VERSION_MINOR }}
4748
LLVM_VERSION_PATCH: ${{ steps.version.outputs.LLVM_VERSION_PATCH }}
@@ -58,7 +59,14 @@ jobs:
5859
- name: Setup Variables
5960
id: vars
6061
run: |
61-
if [ ${{ steps.version.outputs.LLVM_VERSION_MINOR }} -ne 0 ] || [ ${{ steps.version.outputs.LLVM_VERSION_PATCH }} -eq 0 ]; then
62+
# C++ ABI:
63+
# 18.1.0 we aren't doing ABI checks.
64+
# 18.1.1 We want to check 18.1.0.
65+
# C ABI:
66+
# 18.1.0 We want to check 17.0.x
67+
# 18.1.1 We want to check 18.1.0
68+
echo "BASELINE_VERSION_MINOR=1" >> "$GITHUB_OUTPUT"
69+
if [ ${{ steps.version.outputs.LLVM_VERSION_PATCH }} -eq 0 ]; then
6270
{
6371
echo "BASELINE_VERSION_MAJOR=$(( ${{ steps.version.outputs.LLVM_VERSION_MAJOR }} - 1))"
6472
echo "ABI_HEADERS=llvm-c"
@@ -82,7 +90,7 @@ jobs:
8290
include:
8391
- name: build-baseline
8492
llvm_version_major: ${{ needs.abi-dump-setup.outputs.BASELINE_VERSION_MAJOR }}
85-
ref: llvmorg-${{ needs.abi-dump-setup.outputs.BASELINE_VERSION_MAJOR }}.0.0
93+
ref: llvmorg-${{ needs.abi-dump-setup.outputs.BASELINE_VERSION_MAJOR }}.${{ needs.abi-dump-setup.outputs.BASELINE_VERSION_MINOR }}.0
8694
repo: llvm/llvm-project
8795
- name: build-latest
8896
llvm_version_major: ${{ needs.abi-dump-setup.outputs.LLVM_VERSION_MAJOR }}

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,9 @@ class DIEStreamer : public DwarfStreamer {
283283
DIEStreamer(DIEBuilder *DIEBldr, DWARFRewriter &Rewriter,
284284
DWARFLinkerBase::OutputFileType OutFileType,
285285
raw_pwrite_stream &OutFile,
286-
std::function<StringRef(StringRef Input)> Translator,
287286
DWARFLinkerBase::MessageHandlerTy Warning)
288-
: DwarfStreamer(OutFileType, OutFile, Translator, Warning),
289-
DIEBldr(DIEBldr), Rewriter(Rewriter){};
287+
: DwarfStreamer(OutFileType, OutFile, Warning), DIEBldr(DIEBldr),
288+
Rewriter(Rewriter){};
290289

291290
using DwarfStreamer::emitCompileUnitHeader;
292291

@@ -469,7 +468,6 @@ createDIEStreamer(const Triple &TheTriple, raw_pwrite_stream &OutFile,
469468

470469
std::unique_ptr<DIEStreamer> Streamer = std::make_unique<DIEStreamer>(
471470
&DIEBldr, Rewriter, DWARFLinkerBase::OutputFileType::Object, OutFile,
472-
[](StringRef Input) -> StringRef { return Input; },
473471
[&](const Twine &Warning, StringRef Context, const DWARFDie *) {});
474472
Error Err = Streamer->init(TheTriple, Swift5ReflectionSegmentName);
475473
if (Err)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "SuspiciousReallocUsageCheck.h"
7474
#include "SuspiciousSemicolonCheck.h"
7575
#include "SuspiciousStringCompareCheck.h"
76+
#include "SuspiciousStringviewDataUsageCheck.h"
7677
#include "SwappedArgumentsCheck.h"
7778
#include "SwitchMissingDefaultCaseCheck.h"
7879
#include "TerminatingContinueCheck.h"
@@ -218,6 +219,8 @@ class BugproneModule : public ClangTidyModule {
218219
"bugprone-suspicious-semicolon");
219220
CheckFactories.registerCheck<SuspiciousStringCompareCheck>(
220221
"bugprone-suspicious-string-compare");
222+
CheckFactories.registerCheck<SuspiciousStringviewDataUsageCheck>(
223+
"bugprone-suspicious-stringview-data-usage");
221224
CheckFactories.registerCheck<SwappedArgumentsCheck>(
222225
"bugprone-swapped-arguments");
223226
CheckFactories.registerCheck<TerminatingContinueCheck>(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
2626
ImplicitWideningOfMultiplicationResultCheck.cpp
2727
InaccurateEraseCheck.cpp
2828
IncorrectEnableIfCheck.cpp
29+
SuspiciousStringviewDataUsageCheck.cpp
2930
SwitchMissingDefaultCaseCheck.cpp
3031
IncDecInConditionsCheck.cpp
3132
IncorrectRoundingsCheck.cpp
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//===--- SuspiciousStringviewDataUsageCheck.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 "SuspiciousStringviewDataUsageCheck.h"
10+
#include "../utils/Matchers.h"
11+
#include "../utils/OptionsUtils.h"
12+
#include "clang/AST/ASTContext.h"
13+
#include "clang/ASTMatchers/ASTMatchFinder.h"
14+
15+
using namespace clang::ast_matchers;
16+
17+
namespace clang::tidy::bugprone {
18+
19+
SuspiciousStringviewDataUsageCheck::SuspiciousStringviewDataUsageCheck(
20+
StringRef Name, ClangTidyContext *Context)
21+
: ClangTidyCheck(Name, Context),
22+
StringViewTypes(utils::options::parseStringList(Options.get(
23+
"StringViewTypes", "::std::basic_string_view;::llvm::StringRef"))),
24+
AllowedCallees(
25+
utils::options::parseStringList(Options.get("AllowedCallees", ""))) {}
26+
27+
void SuspiciousStringviewDataUsageCheck::storeOptions(
28+
ClangTidyOptions::OptionMap &Opts) {
29+
Options.store(Opts, "StringViewTypes",
30+
utils::options::serializeStringList(StringViewTypes));
31+
Options.store(Opts, "AllowedCallees",
32+
utils::options::serializeStringList(AllowedCallees));
33+
}
34+
35+
bool SuspiciousStringviewDataUsageCheck::isLanguageVersionSupported(
36+
const LangOptions &LangOpts) const {
37+
return LangOpts.CPlusPlus;
38+
}
39+
40+
std::optional<TraversalKind>
41+
SuspiciousStringviewDataUsageCheck::getCheckTraversalKind() const {
42+
return TK_AsIs;
43+
}
44+
45+
void SuspiciousStringviewDataUsageCheck::registerMatchers(MatchFinder *Finder) {
46+
47+
auto AncestorCall = anyOf(
48+
cxxConstructExpr(), callExpr(unless(cxxOperatorCallExpr())), lambdaExpr(),
49+
initListExpr(
50+
hasType(qualType(hasCanonicalType(hasDeclaration(recordDecl()))))));
51+
52+
auto DataMethod =
53+
cxxMethodDecl(hasName("data"),
54+
ofClass(matchers::matchesAnyListedName(StringViewTypes)));
55+
56+
auto SizeCall = cxxMemberCallExpr(
57+
callee(cxxMethodDecl(hasAnyName("size", "length"))),
58+
on(ignoringParenImpCasts(
59+
matchers::isStatementIdenticalToBoundNode("self"))));
60+
61+
auto DescendantSizeCall = expr(hasDescendant(
62+
expr(SizeCall, hasAncestor(expr(AncestorCall).bind("ancestor-size")),
63+
hasAncestor(expr(equalsBoundNode("parent"),
64+
equalsBoundNode("ancestor-size"))))));
65+
66+
Finder->addMatcher(
67+
cxxMemberCallExpr(
68+
on(ignoringParenImpCasts(expr().bind("self"))), callee(DataMethod),
69+
expr().bind("data-call"),
70+
hasParent(expr(anyOf(
71+
invocation(
72+
expr().bind("parent"), unless(cxxOperatorCallExpr()),
73+
hasAnyArgument(
74+
ignoringParenImpCasts(equalsBoundNode("data-call"))),
75+
unless(hasAnyArgument(ignoringParenImpCasts(SizeCall))),
76+
unless(hasAnyArgument(DescendantSizeCall)),
77+
hasDeclaration(namedDecl(
78+
unless(matchers::matchesAnyListedName(AllowedCallees))))),
79+
initListExpr(expr().bind("parent"),
80+
hasType(qualType(hasCanonicalType(hasDeclaration(
81+
recordDecl(unless(matchers::matchesAnyListedName(
82+
AllowedCallees))))))),
83+
unless(DescendantSizeCall)))))),
84+
this);
85+
}
86+
87+
void SuspiciousStringviewDataUsageCheck::check(
88+
const MatchFinder::MatchResult &Result) {
89+
const auto *DataCallExpr =
90+
Result.Nodes.getNodeAs<CXXMemberCallExpr>("data-call");
91+
diag(DataCallExpr->getExprLoc(),
92+
"result of a `data()` call may not be null terminated, provide size "
93+
"information to the callee to prevent potential issues")
94+
<< DataCallExpr->getCallee()->getSourceRange();
95+
}
96+
97+
} // namespace clang::tidy::bugprone
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===--- SuspiciousStringviewDataUsageCheck.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_SUSPICIOUSSTRINGVIEWDATAUSAGECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSSTRINGVIEWDATAUSAGECHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::bugprone {
15+
16+
/// Identifies suspicious usages of std::string_view::data() that could lead to
17+
/// reading out-of-bounds data due to inadequate or incorrect string null
18+
/// termination.
19+
///
20+
/// For the user-facing documentation see:
21+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/suspicious-stringview-data-usage.html
22+
class SuspiciousStringviewDataUsageCheck : public ClangTidyCheck {
23+
public:
24+
SuspiciousStringviewDataUsageCheck(StringRef Name, ClangTidyContext *Context);
25+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
26+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
27+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
28+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
29+
std::optional<TraversalKind> getCheckTraversalKind() const override;
30+
31+
private:
32+
std::vector<llvm::StringRef> StringViewTypes;
33+
std::vector<llvm::StringRef> AllowedCallees;
34+
};
35+
36+
} // namespace clang::tidy::bugprone
37+
38+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSSTRINGVIEWDATAUSAGECHECK_H

clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ using namespace clang::ast_matchers::internal;
1919

2020
namespace clang::tidy::cppcoreguidelines {
2121

22+
namespace {
23+
AST_MATCHER_P(LambdaExpr, hasCallOperator, Matcher<CXXMethodDecl>,
24+
InnerMatcher) {
25+
return InnerMatcher.matches(*Node.getCallOperator(), Finder, Builder);
26+
}
27+
28+
AST_MATCHER_P(LambdaExpr, hasLambdaBody, Matcher<Stmt>, InnerMatcher) {
29+
return InnerMatcher.matches(*Node.getBody(), Finder, Builder);
30+
}
31+
} // namespace
32+
2233
void OwningMemoryCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2334
Options.store(Opts, "LegacyResourceProducers", LegacyResourceProducers);
2435
Options.store(Opts, "LegacyResourceConsumers", LegacyResourceConsumers);
@@ -55,6 +66,8 @@ void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) {
5566
CreatesLegacyOwner, LegacyOwnerCast);
5667

5768
const auto ConsideredOwner = eachOf(IsOwnerType, CreatesOwner);
69+
const auto ScopeDeclaration = anyOf(translationUnitDecl(), namespaceDecl(),
70+
recordDecl(), functionDecl());
5871

5972
// Find delete expressions that delete non-owners.
6073
Finder->addMatcher(
@@ -144,13 +157,51 @@ void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) {
144157
.bind("bad_owner_creation_parameter"))),
145158
this);
146159

160+
auto IsNotInSubLambda = stmt(
161+
hasAncestor(
162+
stmt(anyOf(equalsBoundNode("body"), lambdaExpr())).bind("scope")),
163+
hasAncestor(stmt(equalsBoundNode("scope"), equalsBoundNode("body"))));
164+
147165
// Matching on functions, that return an owner/resource, but don't declare
148166
// their return type as owner.
149167
Finder->addMatcher(
150-
functionDecl(hasDescendant(returnStmt(hasReturnValue(ConsideredOwner))
151-
.bind("bad_owner_return")),
152-
unless(returns(qualType(hasDeclaration(OwnerDecl)))))
153-
.bind("function_decl"),
168+
functionDecl(
169+
decl().bind("function_decl"),
170+
hasBody(
171+
stmt(stmt().bind("body"),
172+
hasDescendant(
173+
returnStmt(hasReturnValue(ConsideredOwner),
174+
// Ignore sub-lambda expressions
175+
IsNotInSubLambda,
176+
// Ignore sub-functions
177+
hasAncestor(functionDecl().bind("context")),
178+
hasAncestor(functionDecl(
179+
equalsBoundNode("context"),
180+
equalsBoundNode("function_decl"))))
181+
.bind("bad_owner_return")))),
182+
returns(qualType(unless(hasDeclaration(OwnerDecl))).bind("result"))),
183+
this);
184+
185+
// Matching on lambdas, that return an owner/resource, but don't declare
186+
// their return type as owner.
187+
Finder->addMatcher(
188+
lambdaExpr(
189+
hasAncestor(decl(ScopeDeclaration).bind("scope-decl")),
190+
hasLambdaBody(
191+
stmt(stmt().bind("body"),
192+
hasDescendant(
193+
returnStmt(
194+
hasReturnValue(ConsideredOwner),
195+
// Ignore sub-lambdas
196+
IsNotInSubLambda,
197+
// Ignore sub-functions
198+
hasAncestor(decl(ScopeDeclaration).bind("context")),
199+
hasAncestor(decl(equalsBoundNode("context"),
200+
equalsBoundNode("scope-decl"))))
201+
.bind("bad_owner_return")))),
202+
hasCallOperator(returns(
203+
qualType(unless(hasDeclaration(OwnerDecl))).bind("result"))))
204+
.bind("lambda"),
154205
this);
155206

156207
// Match on classes that have an owner as member, but don't declare a
@@ -329,7 +380,7 @@ bool OwningMemoryCheck::handleReturnValues(const BoundNodes &Nodes) {
329380
// Function return statements, that are owners/resources, but the function
330381
// declaration does not declare its return value as owner.
331382
const auto *BadReturnType = Nodes.getNodeAs<ReturnStmt>("bad_owner_return");
332-
const auto *Function = Nodes.getNodeAs<FunctionDecl>("function_decl");
383+
const auto *ResultType = Nodes.getNodeAs<QualType>("result");
333384

334385
// Function return values, that should be owners but aren't.
335386
if (BadReturnType) {
@@ -338,8 +389,9 @@ bool OwningMemoryCheck::handleReturnValues(const BoundNodes &Nodes) {
338389
diag(BadReturnType->getBeginLoc(),
339390
"returning a newly created resource of "
340391
"type %0 or 'gsl::owner<>' from a "
341-
"function whose return type is not 'gsl::owner<>'")
342-
<< Function->getReturnType() << BadReturnType->getSourceRange();
392+
"%select{function|lambda}1 whose return type is not 'gsl::owner<>'")
393+
<< *ResultType << (Nodes.getNodeAs<Expr>("lambda") != nullptr)
394+
<< BadReturnType->getSourceRange();
343395

344396
// FIXME: Rewrite the return type as 'gsl::owner<OriginalType>'
345397
return true;

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ struct CodeCompletionBuilder {
619619
}
620620
// 'CompletionItemKind::Interface' matches template type aliases.
621621
if (Completion.Kind == CompletionItemKind::Interface ||
622-
Completion.Kind == CompletionItemKind::Class) {
622+
Completion.Kind == CompletionItemKind::Class ||
623+
Completion.Kind == CompletionItemKind::Variable) {
623624
if (Snippet->front() != '<')
624625
return *Snippet; // Not an arg snippet?
625626

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2648,12 +2648,15 @@ TEST(CompletionTest, CompletionFunctionArgsDisabled) {
26482648
class foo_class{};
26492649
template <class T>
26502650
using foo_alias = T**;
2651+
template <class T>
2652+
T foo_var = T{};
26512653
void f() { foo_^ })cpp",
26522654
{}, Opts);
26532655
EXPECT_THAT(
26542656
Results.Completions,
26552657
UnorderedElementsAre(AllOf(named("foo_class"), snippetSuffix("<$0>")),
2656-
AllOf(named("foo_alias"), snippetSuffix("<$0>"))));
2658+
AllOf(named("foo_alias"), snippetSuffix("<$0>")),
2659+
AllOf(named("foo_var"), snippetSuffix("<$0>"))));
26572660
}
26582661
{
26592662
auto Results = completions(

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ New checks
110110
Detects error-prone Curiously Recurring Template Pattern usage, when the CRTP
111111
can be constructed outside itself and the derived class.
112112

113+
- New :doc:`bugprone-suspicious-stringview-data-usage
114+
<clang-tidy/checks/bugprone/suspicious-stringview-data-usage>` check.
115+
116+
Identifies suspicious usages of ``std::string_view::data()`` that could lead
117+
to reading out-of-bounds data due to inadequate or incorrect string null
118+
termination.
119+
113120
- New :doc:`modernize-use-designated-initializers
114121
<clang-tidy/checks/modernize/use-designated-initializers>` check.
115122

@@ -165,6 +172,10 @@ Changes in existing checks
165172
giving false positives for deleted functions and fix false negative when some
166173
parameters are forwarded, but other aren't.
167174

175+
- Improved :doc:`cppcoreguidelines-owning-memory
176+
<clang-tidy/checks/cppcoreguidelines/owning-memory>` check to properly handle
177+
return type in lambdas and in nested functions.
178+
168179
- Cleaned up :doc:`cppcoreguidelines-prefer-member-initializer
169180
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>`
170181
by removing enforcement of rule `C.48

0 commit comments

Comments
 (0)