Skip to content

Commit 2dee476

Browse files
authored
merge main into amd-staging (#579)
2 parents c5593b7 + 316ccf2 commit 2dee476

File tree

124 files changed

+4181
-1549
lines changed

Some content is hidden

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

124 files changed

+4181
-1549
lines changed

clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
7373
RAIITypesList(utils::options::parseStringList(
7474
Options.get("RAIITypesList", "std::lock_guard;std::scoped_lock"))),
7575
AllowedAwaitablesList(utils::options::parseStringList(
76-
Options.get("AllowedAwaitablesList", ""))) {}
76+
Options.get("AllowedAwaitablesList", ""))),
77+
AllowedCallees(
78+
utils::options::parseStringList(Options.get("AllowedCallees", ""))) {}
7779

7880
void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
7981
// A suspension happens with co_await or co_yield.
8082
auto ScopedLockable = varDecl(hasType(hasCanonicalType(hasDeclaration(
8183
hasAttr(attr::Kind::ScopedLockable)))))
8284
.bind("scoped-lockable");
8385
auto OtherRAII = varDecl(typeWithNameIn(RAIITypesList)).bind("raii");
84-
auto AllowedSuspend = awaitable(typeWithNameIn(AllowedAwaitablesList));
86+
auto AllowedSuspend = awaitable(
87+
anyOf(typeWithNameIn(AllowedAwaitablesList),
88+
callExpr(callee(functionDecl(hasAnyName(AllowedCallees))))));
8589
Finder->addMatcher(
8690
expr(anyOf(coawaitExpr(unless(AllowedSuspend)), coyieldExpr()),
8791
forEachPrevStmt(
@@ -111,5 +115,7 @@ void CoroutineHostileRAIICheck::storeOptions(
111115
utils::options::serializeStringList(RAIITypesList));
112116
Options.store(Opts, "SafeAwaitableList",
113117
utils::options::serializeStringList(AllowedAwaitablesList));
118+
Options.store(Opts, "SafeCallees",
119+
utils::options::serializeStringList(AllowedCallees));
114120
}
115121
} // namespace clang::tidy::misc

clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class CoroutineHostileRAIICheck : public ClangTidyCheck {
4646
// List of fully qualified awaitable types which are considered safe to
4747
// co_await.
4848
std::vector<StringRef> AllowedAwaitablesList;
49+
// List of callees whose return values are considered safe to directly
50+
// co_await.
51+
std::vector<StringRef> AllowedCallees;
4952
};
5053

5154
} // namespace clang::tidy::misc

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ Changes in existing checks
423423
positives on return of non-const pointer and fix false positives on
424424
pointer-to-member operator.
425425

426+
- Improved :doc:`misc-coroutine-hostile-raii
427+
<clang-tidy/checks/misc/coroutine-hostile-raii>` check by adding the option
428+
`AllowedCallees`, that allows exempting safely awaitable callees from the
429+
check.
430+
426431
- Improved :doc:`misc-header-include-cycle
427432
<clang-tidy/checks/misc/header-include-cycle>` check performance.
428433

clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,23 @@ Options
8181
Eg: `my::safe::awaitable;other::awaitable`
8282
Default is an empty string.
8383

84+
.. option:: AllowedCallees
85+
86+
A semicolon-separated list of callee function names which can
87+
be safely awaited while having hostile RAII objects in scope.
88+
Example usage:
89+
90+
.. code-block:: c++
91+
92+
// Consider option AllowedCallees = "noop"
93+
task noop() { co_return; }
94+
95+
task coro() {
96+
// This persists across the co_await but is not flagged
97+
// because the awaitable is considered safe to await on.
98+
const std::lock_guard l(&mu_);
99+
co_await noop();
100+
}
101+
102+
Eg: `my::safe::await;other::await`
103+
Default is an empty string.

clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %check_clang_tidy -std=c++20 %s misc-coroutine-hostile-raii %t \
22
// RUN: -config="{CheckOptions: {\
33
// RUN: misc-coroutine-hostile-raii.RAIITypesList: 'my::Mutex; ::my::other::Mutex', \
4-
// RUN: misc-coroutine-hostile-raii.AllowedAwaitablesList: 'safe::awaitable; ::transformable::awaitable' \
4+
// RUN: misc-coroutine-hostile-raii.AllowedAwaitablesList: 'safe::awaitable; ::transformable::awaitable', \
5+
// RUN: misc-coroutine-hostile-raii.AllowedCallees: 'safe::AwaitFunc; ::safe::Obj::AwaitMethod' \
56
// RUN: }}"
67

78
namespace std {
@@ -145,12 +146,18 @@ namespace safe {
145146
void await_suspend(std::coroutine_handle<>) noexcept {}
146147
void await_resume() noexcept {}
147148
};
149+
std::suspend_always AwaitFunc();
150+
struct Obj {
151+
std::suspend_always AwaitMethod();
152+
};
148153
} // namespace safe
149154
ReturnObject RAIISafeSuspendTest() {
150155
absl::Mutex a;
151156
co_await safe::awaitable{};
152157
using other = safe::awaitable;
153158
co_await other{};
159+
co_await safe::AwaitFunc();
160+
co_await safe::Obj().AwaitMethod();
154161
}
155162

156163
// ================================================================================

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,15 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
465465
return createCompare(ptr.getLoc(), cir::CmpOpKind::eq, ptr, nullPtr);
466466
}
467467

468+
mlir::Value createAddrSpaceCast(mlir::Location loc, mlir::Value src,
469+
mlir::Type newTy) {
470+
return createCast(loc, cir::CastKind::address_space, src, newTy);
471+
}
472+
473+
mlir::Value createAddrSpaceCast(mlir::Value src, mlir::Type newTy) {
474+
return createAddrSpaceCast(src.getLoc(), src, newTy);
475+
}
476+
468477
//===--------------------------------------------------------------------===//
469478
// Binary Operators
470479
//===--------------------------------------------------------------------===//

clang/include/clang/CIR/Dialect/IR/CIRTypes.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#ifndef CLANG_CIR_DIALECT_IR_CIRTYPES_H
1414
#define CLANG_CIR_DIALECT_IR_CIRTYPES_H
1515

16+
#include "mlir/IR/Attributes.h"
1617
#include "mlir/IR/BuiltinAttributes.h"
18+
#include "mlir/IR/MLIRContext.h"
1719
#include "mlir/IR/Types.h"
1820
#include "mlir/Interfaces/DataLayoutInterfaces.h"
1921
#include "clang/Basic/AddressSpaces.h"
@@ -38,6 +40,15 @@ bool isValidFundamentalIntWidth(unsigned width);
3840
/// void, or abstract types.
3941
bool isSized(mlir::Type ty);
4042

43+
//===----------------------------------------------------------------------===//
44+
// AddressSpace helpers
45+
//===----------------------------------------------------------------------===//
46+
cir::TargetAddressSpaceAttr toCIRTargetAddressSpace(mlir::MLIRContext &context,
47+
clang::LangAS langAS);
48+
49+
bool isMatchingAddressSpace(cir::TargetAddressSpaceAttr cirAS,
50+
clang::LangAS as);
51+
4152
} // namespace cir
4253

4354
//===----------------------------------------------------------------------===//

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ class CompilerInvocationBase {
147147
}
148148
/// @}
149149

150+
/// Visitation.
151+
/// @{
152+
/// Visits paths stored in the invocation. The callback may return true to
153+
/// short-circuit the visitation, or return false to continue visiting.
154+
void visitPaths(llvm::function_ref<bool(StringRef)> Callback) const;
155+
/// @}
156+
150157
/// Command line generation.
151158
/// @{
152159
using StringAllocator = llvm::function_ref<const char *(const Twine &)>;
@@ -181,6 +188,12 @@ class CompilerInvocationBase {
181188
/// This is a (less-efficient) wrapper over generateCC1CommandLine().
182189
std::vector<std::string> getCC1CommandLine() const;
183190

191+
protected:
192+
/// Visits paths stored in the invocation. This is generally unsafe to call
193+
/// directly, and each sub-class need to ensure calling this doesn't violate
194+
/// its invariants.
195+
void visitPathsImpl(llvm::function_ref<bool(std::string &)> Predicate);
196+
184197
private:
185198
/// Generate command line options from DiagnosticOptions.
186199
static void GenerateDiagnosticArgs(const DiagnosticOptions &Opts,

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ class FrontendInputFile {
241241
/// Whether we're dealing with a 'system' input (vs. a 'user' input).
242242
bool IsSystem = false;
243243

244+
friend class CompilerInvocationBase;
245+
244246
public:
245247
FrontendInputFile() = default;
246248
FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ struct UnsafeQualTypeDenseMapInfo {
151151
};
152152

153153
/// An ID number that refers to a macro in an AST file.
154-
using MacroID = uint32_t;
154+
using MacroID = uint64_t;
155155

156156
/// A global ID number that refers to a macro in an AST file.
157-
using GlobalMacroID = uint32_t;
157+
using GlobalMacroID = uint64_t;
158158

159159
/// A local to a module ID number that refers to a macro in an
160160
/// AST file.
161-
using LocalMacroID = uint32_t;
161+
using LocalMacroID = uint64_t;
162162

163163
/// The number of predefined macro IDs.
164164
const unsigned int NUM_PREDEF_MACRO_IDS = 1;
@@ -179,7 +179,7 @@ using CXXCtorInitializersID = uint32_t;
179179

180180
/// An ID number that refers to an entity in the detailed
181181
/// preprocessing record.
182-
using PreprocessedEntityID = uint32_t;
182+
using PreprocessedEntityID = uint64_t;
183183

184184
/// An ID number that refers to a submodule in a module file.
185185
using SubmoduleID = uint32_t;

0 commit comments

Comments
 (0)