Skip to content

Commit 6bd8582

Browse files
Merge branch 'llvm:main' into cfi-show
2 parents 01f2118 + 77028d6 commit 6bd8582

File tree

299 files changed

+6211
-2764
lines changed

Some content is hidden

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

299 files changed

+6211
-2764
lines changed

clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp

Lines changed: 30 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,17 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include <array>
910
#include <cmath>
1011
#include <optional>
1112

1213
#include "DurationRewriter.h"
1314
#include "clang/Tooling/FixIt.h"
14-
#include "llvm/ADT/IndexedMap.h"
1515

1616
using namespace clang::ast_matchers;
1717

1818
namespace clang::tidy::abseil {
1919

20-
struct DurationScale2IndexFunctor {
21-
using argument_type = DurationScale;
22-
unsigned operator()(DurationScale Scale) const {
23-
return static_cast<unsigned>(Scale);
24-
}
25-
};
26-
2720
/// Returns an integer if the fractional part of a `FloatingLiteral` is `0`.
2821
static std::optional<llvm::APSInt>
2922
truncateIfIntegral(const FloatingLiteral &FloatLiteral) {
@@ -39,31 +32,17 @@ truncateIfIntegral(const FloatingLiteral &FloatLiteral) {
3932

4033
const std::pair<llvm::StringRef, llvm::StringRef> &
4134
getDurationInverseForScale(DurationScale Scale) {
42-
static const llvm::IndexedMap<std::pair<llvm::StringRef, llvm::StringRef>,
43-
DurationScale2IndexFunctor>
44-
InverseMap = []() {
45-
// TODO: Revisit the immediately invoked lambda technique when
46-
// IndexedMap gets an initializer list constructor.
47-
llvm::IndexedMap<std::pair<llvm::StringRef, llvm::StringRef>,
48-
DurationScale2IndexFunctor>
49-
InverseMap;
50-
InverseMap.resize(6);
51-
InverseMap[DurationScale::Hours] =
52-
std::make_pair("::absl::ToDoubleHours", "::absl::ToInt64Hours");
53-
InverseMap[DurationScale::Minutes] =
54-
std::make_pair("::absl::ToDoubleMinutes", "::absl::ToInt64Minutes");
55-
InverseMap[DurationScale::Seconds] =
56-
std::make_pair("::absl::ToDoubleSeconds", "::absl::ToInt64Seconds");
57-
InverseMap[DurationScale::Milliseconds] = std::make_pair(
58-
"::absl::ToDoubleMilliseconds", "::absl::ToInt64Milliseconds");
59-
InverseMap[DurationScale::Microseconds] = std::make_pair(
60-
"::absl::ToDoubleMicroseconds", "::absl::ToInt64Microseconds");
61-
InverseMap[DurationScale::Nanoseconds] = std::make_pair(
62-
"::absl::ToDoubleNanoseconds", "::absl::ToInt64Nanoseconds");
63-
return InverseMap;
64-
}();
65-
66-
return InverseMap[Scale];
35+
static constexpr std::array<std::pair<llvm::StringRef, llvm::StringRef>, 6>
36+
InverseMap = {{
37+
{"::absl::ToDoubleHours", "::absl::ToInt64Hours"},
38+
{"::absl::ToDoubleMinutes", "::absl::ToInt64Minutes"},
39+
{"::absl::ToDoubleSeconds", "::absl::ToInt64Seconds"},
40+
{"::absl::ToDoubleMilliseconds", "::absl::ToInt64Milliseconds"},
41+
{"::absl::ToDoubleMicroseconds", "::absl::ToInt64Microseconds"},
42+
{"::absl::ToDoubleNanoseconds", "::absl::ToInt64Nanoseconds"},
43+
}};
44+
45+
return InverseMap[llvm::to_underlying(Scale)];
6746
}
6847

6948
/// If `Node` is a call to the inverse of `Scale`, return that inverse's
@@ -103,58 +82,31 @@ rewriteInverseTimeCall(const MatchFinder::MatchResult &Result,
10382

10483
/// Returns the factory function name for a given `Scale`.
10584
llvm::StringRef getDurationFactoryForScale(DurationScale Scale) {
106-
switch (Scale) {
107-
case DurationScale::Hours:
108-
return "absl::Hours";
109-
case DurationScale::Minutes:
110-
return "absl::Minutes";
111-
case DurationScale::Seconds:
112-
return "absl::Seconds";
113-
case DurationScale::Milliseconds:
114-
return "absl::Milliseconds";
115-
case DurationScale::Microseconds:
116-
return "absl::Microseconds";
117-
case DurationScale::Nanoseconds:
118-
return "absl::Nanoseconds";
119-
}
120-
llvm_unreachable("unknown scaling factor");
85+
static constexpr std::array<llvm::StringRef, 6> FactoryMap = {
86+
"absl::Hours", "absl::Minutes", "absl::Seconds",
87+
"absl::Milliseconds", "absl::Microseconds", "absl::Nanoseconds",
88+
};
89+
90+
return FactoryMap[llvm::to_underlying(Scale)];
12191
}
12292

12393
llvm::StringRef getTimeFactoryForScale(DurationScale Scale) {
124-
switch (Scale) {
125-
case DurationScale::Hours:
126-
return "absl::FromUnixHours";
127-
case DurationScale::Minutes:
128-
return "absl::FromUnixMinutes";
129-
case DurationScale::Seconds:
130-
return "absl::FromUnixSeconds";
131-
case DurationScale::Milliseconds:
132-
return "absl::FromUnixMillis";
133-
case DurationScale::Microseconds:
134-
return "absl::FromUnixMicros";
135-
case DurationScale::Nanoseconds:
136-
return "absl::FromUnixNanos";
137-
}
138-
llvm_unreachable("unknown scaling factor");
94+
static constexpr std::array<llvm::StringRef, 6> FactoryMap = {
95+
"absl::FromUnixHours", "absl::FromUnixMinutes", "absl::FromUnixSeconds",
96+
"absl::FromUnixMillis", "absl::FromUnixMicros", "absl::FromUnixNanos",
97+
};
98+
99+
return FactoryMap[llvm::to_underlying(Scale)];
139100
}
140101

141102
/// Returns the Time factory function name for a given `Scale`.
142103
llvm::StringRef getTimeInverseForScale(DurationScale Scale) {
143-
switch (Scale) {
144-
case DurationScale::Hours:
145-
return "absl::ToUnixHours";
146-
case DurationScale::Minutes:
147-
return "absl::ToUnixMinutes";
148-
case DurationScale::Seconds:
149-
return "absl::ToUnixSeconds";
150-
case DurationScale::Milliseconds:
151-
return "absl::ToUnixMillis";
152-
case DurationScale::Microseconds:
153-
return "absl::ToUnixMicros";
154-
case DurationScale::Nanoseconds:
155-
return "absl::ToUnixNanos";
156-
}
157-
llvm_unreachable("unknown scaling factor");
104+
static constexpr std::array<llvm::StringRef, 6> InverseMap = {
105+
"absl::ToUnixHours", "absl::ToUnixMinutes", "absl::ToUnixSeconds",
106+
"absl::ToUnixMillis", "absl::ToUnixMicros", "absl::ToUnixNanos",
107+
};
108+
109+
return InverseMap[llvm::to_underlying(Scale)];
158110
}
159111

160112
/// Returns `true` if `Node` is a value which evaluates to a literal `0`.

clang/docs/OpenMPSupport.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ implementation.
153153
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
154154
| device | clause: extended device | :good:`done` | |
155155
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
156-
| device | clause: uses_allocators clause | :good:`done` | |
156+
| device | clause: uses_allocators clause | :good:`done` | https://github.com/llvm/llvm-project/pull/157025 |
157157
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
158158
| device | clause: in_reduction | :part:`worked on` | r308768 |
159159
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
@@ -578,6 +578,7 @@ implementation.
578578
| | | | |
579579
| | | | Flang parser: https://github.com/llvm/llvm-project/pull/153807 |
580580
| | | | Flang sema: https://github.com/llvm/llvm-project/pull/154779 |
581+
| | | | Clang parse/sema: https://github.com/llvm/llvm-project/pull/158134 |
581582
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
582583
| variable-category on default clause | :good:`done` | :none:`unclaimed` | |
583584
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,11 @@ OpenMP Support
562562
- Allow array length to be omitted in array section subscript expression.
563563
- Fixed non-contiguous strided update in the ``omp target update`` directive with the ``from`` clause.
564564
- Properly handle array section/assumed-size array privatization in C/C++.
565+
- Added support to handle new syntax of the ``uses_allocators`` clause.
565566
- Added support for ``variable-category`` modifier in ``default clause``.
566567
- Added support for ``defaultmap`` directive implicit-behavior ``storage``.
567568
- Added support for ``defaultmap`` directive implicit-behavior ``private``.
569+
- Added parsing and semantic analysis support for ``groupprivate`` directive.
568570

569571
Improvements
570572
^^^^^^^^^^^^

clang/include/clang/AST/ASTMutationListener.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ class ASTMutationListener {
125125
/// \param D the declaration marked OpenMP threadprivate.
126126
virtual void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) {}
127127

128+
/// A declaration is marked as OpenMP groupprivate which was not
129+
/// previously marked as groupprivate.
130+
///
131+
/// \param D the declaration marked OpenMP groupprivate.
132+
virtual void DeclarationMarkedOpenMPGroupPrivate(const Decl *D) {}
133+
128134
/// A declaration is marked as OpenMP declaretarget which was not
129135
/// previously marked as declaretarget.
130136
///

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ class ASTNodeTraverser
620620
Visit(E);
621621
}
622622

623+
void VisitOMPGroupPrivateDecl(const OMPGroupPrivateDecl *D) {
624+
for (const auto *E : D->varlist())
625+
Visit(E);
626+
}
627+
623628
void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
624629
Visit(D->getCombiner());
625630
if (const auto *Initializer = D->getInitializer())

clang/include/clang/AST/DeclOpenMP.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,68 @@ class OMPThreadPrivateDecl final : public OMPDeclarativeDirective<Decl> {
158158
static bool classofKind(Kind K) { return K == OMPThreadPrivate; }
159159
};
160160

161+
/// This represents '#pragma omp groupprivate ...' directive.
162+
/// For example, in the following, both 'a' and 'A::b' are groupprivate:
163+
///
164+
/// \code
165+
/// int a;
166+
/// #pragma omp groupprivate(a)
167+
/// struct A {
168+
/// static int b;
169+
/// #pragma omp groupprivate(b)
170+
/// };
171+
/// \endcode
172+
///
173+
class OMPGroupPrivateDecl final : public OMPDeclarativeDirective<Decl> {
174+
friend class OMPDeclarativeDirective<Decl>;
175+
176+
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
177+
178+
OMPGroupPrivateDecl(DeclContext *DC = nullptr,
179+
SourceLocation L = SourceLocation())
180+
: OMPDeclarativeDirective<Decl>(OMPGroupPrivate, DC, L) {}
181+
182+
ArrayRef<const Expr *> getVars() const {
183+
auto **Storage = reinterpret_cast<Expr **>(Data->getChildren().data());
184+
return {Storage, Data->getNumChildren()};
185+
}
186+
187+
MutableArrayRef<Expr *> getVars() {
188+
auto **Storage = reinterpret_cast<Expr **>(Data->getChildren().data());
189+
return {Storage, Data->getNumChildren()};
190+
}
191+
192+
void setVars(ArrayRef<Expr *> VL);
193+
194+
public:
195+
static OMPGroupPrivateDecl *Create(ASTContext &C, DeclContext *DC,
196+
SourceLocation L, ArrayRef<Expr *> VL);
197+
static OMPGroupPrivateDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
198+
unsigned N);
199+
200+
typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
201+
typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
202+
typedef llvm::iterator_range<varlist_iterator> varlist_range;
203+
typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
204+
205+
unsigned varlist_size() const { return Data->getNumChildren(); }
206+
bool varlist_empty() const { return Data->getChildren().empty(); }
207+
208+
varlist_range varlist() {
209+
return varlist_range(varlist_begin(), varlist_end());
210+
}
211+
varlist_const_range varlist() const {
212+
return varlist_const_range(varlist_begin(), varlist_end());
213+
}
214+
varlist_iterator varlist_begin() { return getVars().begin(); }
215+
varlist_iterator varlist_end() { return getVars().end(); }
216+
varlist_const_iterator varlist_begin() const { return getVars().begin(); }
217+
varlist_const_iterator varlist_end() const { return getVars().end(); }
218+
219+
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
220+
static bool classofKind(Kind K) { return K == OMPGroupPrivate; }
221+
};
222+
161223
enum class OMPDeclareReductionInitKind {
162224
Call, // Initialized by function call.
163225
Direct, // omp_priv(<expr>)

clang/include/clang/AST/Expr.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ class Expr : public ValueStmt {
634634

635635
EvalStatus() = default;
636636

637-
// hasSideEffects - Return true if the evaluated expression has
638-
// side effects.
637+
/// Return true if the evaluated expression has
638+
/// side effects.
639639
bool hasSideEffects() const {
640640
return HasSideEffects;
641641
}
@@ -646,8 +646,8 @@ class Expr : public ValueStmt {
646646
/// Val - This is the value the expression can be folded to.
647647
APValue Val;
648648

649-
// isGlobalLValue - Return true if the evaluated lvalue expression
650-
// is global.
649+
/// Return true if the evaluated lvalue expression
650+
/// is global.
651651
bool isGlobalLValue() const;
652652
};
653653

@@ -715,9 +715,7 @@ class Expr : public ValueStmt {
715715
/// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
716716
/// integer. This must be called on an expression that constant folds to an
717717
/// integer.
718-
llvm::APSInt EvaluateKnownConstInt(
719-
const ASTContext &Ctx,
720-
SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const;
718+
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const;
721719

722720
llvm::APSInt EvaluateKnownConstIntCheckOverflow(
723721
const ASTContext &Ctx,

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,12 @@ DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
18871887
}
18881888
})
18891889

1890+
DEF_TRAVERSE_DECL(OMPGroupPrivateDecl, {
1891+
for (auto *I : D->varlist()) {
1892+
TRY_TO(TraverseStmt(I));
1893+
}
1894+
})
1895+
18901896
DEF_TRAVERSE_DECL(OMPRequiresDecl, {
18911897
for (auto *C : D->clauselists()) {
18921898
TRY_TO(TraverseOMPClause(C));

clang/include/clang/Basic/Attr.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,6 +4585,12 @@ def OMPThreadPrivateDecl : InheritableAttr {
45854585
let Documentation = [InternalOnly];
45864586
}
45874587

4588+
def OMPGroupPrivateDecl : InheritableAttr {
4589+
let Spellings = [];
4590+
let SemaHandler = 0;
4591+
let Documentation = [InternalOnly];
4592+
}
4593+
45884594
def OMPCaptureNoInit : InheritableAttr {
45894595
// This attribute has no spellings as it is only ever created implicitly.
45904596
let Spellings = [];

clang/include/clang/Basic/DeclNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def OutlinedFunction : DeclNode<Decl>, DeclContext;
106106
def Captured : DeclNode<Decl>, DeclContext;
107107
def Import : DeclNode<Decl>;
108108
def OMPThreadPrivate : DeclNode<Decl>;
109+
def OMPGroupPrivate : DeclNode<Decl>;
109110
def OMPAllocate : DeclNode<Decl>;
110111
def OMPRequires : DeclNode<Decl>;
111112
def Empty : DeclNode<Decl>;

0 commit comments

Comments
 (0)