Skip to content

Commit 6a4a78c

Browse files
committed
Merge from 'main' to 'sycl-web' (30 commits)
CONFLICT (content): Merge conflict in llvm/test/CodeGen/NVPTX/bf16-instructions.ll
2 parents 79912c6 + 4263b2e commit 6a4a78c

File tree

110 files changed

+3444
-2652
lines changed

Some content is hidden

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

110 files changed

+3444
-2652
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ Attribute Changes in Clang
306306
to reduce the size of the destroy functions for coroutines which are known to
307307
be destroyed after having reached the final suspend point.
308308

309+
- Clang now introduced ``[[clang::coro_return_type]]`` and ``[[clang::coro_wrapper]]``
310+
attributes. A function returning a type marked with ``[[clang::coro_return_type]]``
311+
should be a coroutine. A non-coroutine function marked with ``[[clang::coro_wrapper]]``
312+
is still allowed to return the such a type. This is helpful for analyzers to recognize coroutines from the function signatures.
313+
309314
Improvements to Clang's diagnostics
310315
-----------------------------------
311316
- Clang constexpr evaluator now prints template arguments when displaying
@@ -444,6 +449,8 @@ Improvements to Clang's diagnostics
444449
- ``-Wzero-as-null-pointer-constant`` diagnostic is no longer emitted when using ``__null``
445450
(or, more commonly, ``NULL`` when the platform defines it as ``__null``) to be more consistent
446451
with GCC.
452+
- Clang will warn on deprecated specializations used in system headers when their instantiation
453+
is caused by user code.
447454

448455
Improvements to Clang's time-trace
449456
----------------------------------

clang/include/clang/Basic/Attr.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,22 @@ def CoroOnlyDestroyWhenComplete : InheritableAttr {
11351135
let SimpleHandler = 1;
11361136
}
11371137

1138+
def CoroReturnType : InheritableAttr {
1139+
let Spellings = [Clang<"coro_return_type">];
1140+
let Subjects = SubjectList<[CXXRecord]>;
1141+
let LangOpts = [CPlusPlus];
1142+
let Documentation = [CoroReturnTypeAndWrapperDoc];
1143+
let SimpleHandler = 1;
1144+
}
1145+
1146+
def CoroWrapper : InheritableAttr {
1147+
let Spellings = [Clang<"coro_wrapper">];
1148+
let Subjects = SubjectList<[Function]>;
1149+
let LangOpts = [CPlusPlus];
1150+
let Documentation = [CoroReturnTypeAndWrapperDoc];
1151+
let SimpleHandler = 1;
1152+
}
1153+
11381154
// OSObject-based attributes.
11391155
def OSConsumed : InheritableParamAttr {
11401156
let Spellings = [Clang<"os_consumed">];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9186,3 +9186,61 @@ generation of the other destruction cases, optimizing the above `foo.destroy` to
91869186

91879187
}];
91889188
}
9189+
9190+
9191+
def CoroReturnTypeAndWrapperDoc : Documentation {
9192+
let Category = DocCatDecl;
9193+
let Content = [{
9194+
The ``[[clang::coro_return_type]]`` attribute is used to help static analyzers to recognize
9195+
coroutines from the function signatures.
9196+
9197+
The ``coro_return_type`` attribute should be marked on a C++ class to mark it as
9198+
a **coroutine return type (CRT)**.
9199+
9200+
A function ``R func(P1, .., PN)`` has a coroutine return type (CRT) ``R`` if ``R``
9201+
is marked by ``[[clang::coro_return_type]]`` and ``R`` has a promise type associated to it
9202+
(i.e., std​::​coroutine_traits<R, P1, .., PN>​::​promise_type is a valid promise type).
9203+
9204+
If the return type of a function is a ``CRT`` then the function must be a coroutine.
9205+
Otherwise the program is invalid. It is allowed for a non-coroutine to return a ``CRT``
9206+
if the function is marked with ``[[clang::coro_wrapper]]``.
9207+
9208+
The ``[[clang::coro_wrapper]]`` attribute should be marked on a C++ function to mark it as
9209+
a **coroutine wrapper**. A coroutine wrapper is a function which returns a ``CRT``,
9210+
is not a coroutine itself and is marked with ``[[clang::coro_wrapper]]``.
9211+
9212+
Clang will enforce that all functions that return a ``CRT`` are either coroutines or marked
9213+
with ``[[clang::coro_wrapper]]``. Clang will enforce this with an error.
9214+
9215+
From a language perspective, it is not possible to differentiate between a coroutine and a
9216+
function returning a CRT by merely looking at the function signature.
9217+
9218+
Coroutine wrappers, in particular, are susceptible to capturing
9219+
references to temporaries and other lifetime issues. This allows to avoid such lifetime
9220+
issues with coroutine wrappers.
9221+
9222+
For example,
9223+
9224+
.. code-block:: c++
9225+
9226+
// This is a CRT.
9227+
template <typename T> struct [[clang::coro_return_type]] Task {
9228+
using promise_type = some_promise_type;
9229+
};
9230+
9231+
Task<int> increment(int a) { co_return a + 1; } // Fine. This is a coroutine.
9232+
Task<int> foo() { return increment(1); } // Error. foo is not a coroutine.
9233+
9234+
// Fine for a coroutine wrapper to return a CRT.
9235+
Task<int> [[clang::coro_wrapper]] foo() { return increment(1); }
9236+
9237+
void bar() {
9238+
// Invalid. This intantiates a function which returns a CRT but is not marked as
9239+
// a coroutine wrapper.
9240+
std::function<Task<int>(int)> f = increment;
9241+
}
9242+
9243+
Note: ``a_promise_type::get_return_object`` is exempted from this analysis as it is a necessary
9244+
implementation detail of any coroutine library.
9245+
}];
9246+
}

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11673,6 +11673,10 @@ def err_conflicting_aligned_options : Error <
1167311673
def err_coro_invalid_addr_of_label : Error<
1167411674
"the GNU address of label extension is not allowed in coroutines."
1167511675
>;
11676+
def err_coroutine_return_type : Error<
11677+
"function returns a type %0 makred with [[clang::coro_return_type]] but is neither a coroutine nor a coroutine wrapper; "
11678+
"non-coroutines should be marked with [[clang::coro_wrapper]] to allow returning coroutine return type"
11679+
>;
1167611680
} // end of coroutines issue category
1167711681

1167811682
let CategoryName = "Documentation Issue" in {

clang/include/clang/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3532,7 +3532,7 @@ class Parser : public CodeCompletionHandler {
35323532
/// Placeholder for now, should just ignore the directives after emitting a
35333533
/// diagnostic. Eventually will be split into a few functions to parse
35343534
/// different situations.
3535-
DeclGroupPtrTy ParseOpenACCDirective();
3535+
DeclGroupPtrTy ParseOpenACCDirectiveDecl();
35363536
StmtResult ParseOpenACCDirectiveStmt();
35373537

35383538
private:

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8743,6 +8743,8 @@ class Sema final {
87438743
ArrayRef<TemplateArgument> SugaredConverted,
87448744
ArrayRef<TemplateArgument> CanonicalConverted, bool &HasDefaultArg);
87458745

8746+
SourceLocation getTopMostPointOfInstantiation(const NamedDecl *) const;
8747+
87468748
/// Specifies the context in which a particular template
87478749
/// argument is being checked.
87488750
enum CheckTemplateArgumentKind {
@@ -11611,6 +11613,12 @@ class Sema final {
1161111613
bool buildCoroutineParameterMoves(SourceLocation Loc);
1161211614
VarDecl *buildCoroutinePromise(SourceLocation Loc);
1161311615
void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body);
11616+
11617+
// As a clang extension, enforces that a non-coroutine function must be marked
11618+
// with [[clang::coro_wrapper]] if it returns a type marked with
11619+
// [[clang::coro_return_type]].
11620+
// Expects that FD is not a coroutine.
11621+
void CheckCoroutineWrapper(FunctionDecl *FD);
1161411622
/// Lookup 'coroutine_traits' in std namespace and std::experimental
1161511623
/// namespace. The namespace found is recorded in Namespace.
1161611624
ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc,

clang/lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4026,8 +4026,8 @@ QualType ASTContext::getVectorType(QualType vecType, unsigned NumElts,
40264026
assert(vecType->isBuiltinType() ||
40274027
(vecType->isBitIntType() &&
40284028
// Only support _BitInt elements with byte-sized power of 2 NumBits.
4029-
llvm::isPowerOf2_32(vecType->getAs<BitIntType>()->getNumBits()) &&
4030-
vecType->getAs<BitIntType>()->getNumBits() >= 8));
4029+
llvm::isPowerOf2_32(vecType->castAs<BitIntType>()->getNumBits()) &&
4030+
vecType->castAs<BitIntType>()->getNumBits() >= 8));
40314031

40324032
// Check if we've already instantiated a vector of this type.
40334033
llvm::FoldingSetNodeID ID;

clang/lib/AST/ExprConstShared.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//===--- ExprConstShared.h - Shared consetxpr functionality ----*- 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+
// Shared functionality between the new constant expression
10+
// interpreter (AST/Interp/) and the current one (ExprConstant.cpp).
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
15+
#define LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
16+
17+
namespace clang {
18+
class QualType;
19+
class LangOptions;
20+
} // namespace clang
21+
using namespace clang;
22+
/// Values returned by __builtin_classify_type, chosen to match the values
23+
/// produced by GCC's builtin.
24+
enum class GCCTypeClass {
25+
None = -1,
26+
Void = 0,
27+
Integer = 1,
28+
// GCC reserves 2 for character types, but instead classifies them as
29+
// integers.
30+
Enum = 3,
31+
Bool = 4,
32+
Pointer = 5,
33+
// GCC reserves 6 for references, but appears to never use it (because
34+
// expressions never have reference type, presumably).
35+
PointerToDataMember = 7,
36+
RealFloat = 8,
37+
Complex = 9,
38+
// GCC reserves 10 for functions, but does not use it since GCC version 6 due
39+
// to decay to pointer. (Prior to version 6 it was only used in C++ mode).
40+
// GCC claims to reserve 11 for pointers to member functions, but *actually*
41+
// uses 12 for that purpose, same as for a class or struct. Maybe it
42+
// internally implements a pointer to member as a struct? Who knows.
43+
PointerToMemberFunction = 12, // Not a bug, see above.
44+
ClassOrStruct = 12,
45+
Union = 13,
46+
// GCC reserves 14 for arrays, but does not use it since GCC version 6 due to
47+
// decay to pointer. (Prior to version 6 it was only used in C++ mode).
48+
// GCC reserves 15 for strings, but actually uses 5 (pointer) for string
49+
// literals.
50+
// Lang = 16,
51+
// OpaqueType = 17,
52+
BitInt = 18
53+
};
54+
55+
GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
56+
const LangOptions &LangOpts);
57+
58+
#endif

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
//
3333
//===----------------------------------------------------------------------===//
3434

35+
#include "ExprConstShared.h"
3536
#include "Interp/Context.h"
3637
#include "Interp/Frame.h"
3738
#include "Interp/State.h"
@@ -11517,43 +11518,10 @@ bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) {
1151711518
return false;
1151811519
}
1151911520

11520-
/// Values returned by __builtin_classify_type, chosen to match the values
11521-
/// produced by GCC's builtin.
11522-
enum class GCCTypeClass {
11523-
None = -1,
11524-
Void = 0,
11525-
Integer = 1,
11526-
// GCC reserves 2 for character types, but instead classifies them as
11527-
// integers.
11528-
Enum = 3,
11529-
Bool = 4,
11530-
Pointer = 5,
11531-
// GCC reserves 6 for references, but appears to never use it (because
11532-
// expressions never have reference type, presumably).
11533-
PointerToDataMember = 7,
11534-
RealFloat = 8,
11535-
Complex = 9,
11536-
// GCC reserves 10 for functions, but does not use it since GCC version 6 due
11537-
// to decay to pointer. (Prior to version 6 it was only used in C++ mode).
11538-
// GCC claims to reserve 11 for pointers to member functions, but *actually*
11539-
// uses 12 for that purpose, same as for a class or struct. Maybe it
11540-
// internally implements a pointer to member as a struct? Who knows.
11541-
PointerToMemberFunction = 12, // Not a bug, see above.
11542-
ClassOrStruct = 12,
11543-
Union = 13,
11544-
// GCC reserves 14 for arrays, but does not use it since GCC version 6 due to
11545-
// decay to pointer. (Prior to version 6 it was only used in C++ mode).
11546-
// GCC reserves 15 for strings, but actually uses 5 (pointer) for string
11547-
// literals.
11548-
// Lang = 16,
11549-
// OpaqueType = 17,
11550-
BitInt = 18
11551-
};
11552-
1155311521
/// EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way
1155411522
/// as GCC.
11555-
static GCCTypeClass
11556-
EvaluateBuiltinClassifyType(QualType T, const LangOptions &LangOpts) {
11523+
GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
11524+
const LangOptions &LangOpts) {
1155711525
assert(!T->isDependentType() && "unexpected dependent type");
1155811526

1155911527
QualType CanTy = T.getCanonicalType();

clang/lib/AST/Interp/ByteCodeEmitter.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Program.h"
1515
#include "clang/AST/ASTLambda.h"
1616
#include "clang/AST/DeclCXX.h"
17+
#include "clang/Basic/Builtins.h"
1718
#include <type_traits>
1819

1920
using namespace clang;
@@ -84,10 +85,16 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
8485

8586
// Create a handle over the emitted code.
8687
Function *Func = P.getFunction(FuncDecl);
87-
if (!Func)
88-
Func = P.createFunction(FuncDecl, ParamOffset, std::move(ParamTypes),
89-
std::move(ParamDescriptors),
90-
std::move(ParamOffsets), HasThisPointer, HasRVO);
88+
if (!Func) {
89+
bool IsUnevaluatedBuiltin = false;
90+
if (unsigned BI = FuncDecl->getBuiltinID())
91+
IsUnevaluatedBuiltin = Ctx.getASTContext().BuiltinInfo.isUnevaluated(BI);
92+
93+
Func =
94+
P.createFunction(FuncDecl, ParamOffset, std::move(ParamTypes),
95+
std::move(ParamDescriptors), std::move(ParamOffsets),
96+
HasThisPointer, HasRVO, IsUnevaluatedBuiltin);
97+
}
9198

9299
assert(Func);
93100
// For not-yet-defined functions, we only create a Function instance and

0 commit comments

Comments
 (0)