Skip to content

Commit 33f8f54

Browse files
committed
Merge from 'main' to 'sycl-web' (133 commits)
CONFLICT (content): Merge conflict in lldb/tools/lldb-dap/package-lock.json
2 parents 8030684 + 082d1d9 commit 33f8f54

File tree

781 files changed

+19871
-12461
lines changed

Some content is hidden

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

781 files changed

+19871
-12461
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-tools-extra/clangd/AST.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ std::string getQualification(ASTContext &Context,
147147
if (auto *TD = llvm::dyn_cast<TagDecl>(CurD)) {
148148
QualType T;
149149
if (const auto *RD = dyn_cast<CXXRecordDecl>(TD);
150-
ClassTemplateDecl *CTD = RD->getDescribedClassTemplate()) {
150+
ClassTemplateDecl *CTD =
151+
RD ? RD->getDescribedClassTemplate() : nullptr) {
151152
ArrayRef<TemplateArgument> Args;
152153
if (const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
153154
Args = SD->getTemplateArgs().asArray();

clang/bindings/python/clang/cindex.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ def is_unexposed(self):
708708
"""Test if this is an unexposed kind."""
709709
return conf.lib.clang_isUnexposed(self) # type: ignore [no-any-return]
710710

711-
712711
###
713712
# Declaration Kinds
714713

@@ -835,7 +834,6 @@ def is_unexposed(self):
835834
# A C++ access specifier decl.
836835
CXX_ACCESS_SPEC_DECL = 39
837836

838-
839837
###
840838
# Reference Kinds
841839

@@ -1436,12 +1434,60 @@ def is_unexposed(self):
14361434
# OpenMP scope directive.
14371435
OMP_SCOPE_DIRECTIVE = 306
14381436

1437+
# OpenMP reverse directive.
1438+
OMPReverseDirective = 307
1439+
1440+
# OpenMP interchange directive.
1441+
OMPInterchangeDirective = 308
1442+
1443+
# OpenMP assume directive.
1444+
OMPAssumeDirective = 309
1445+
14391446
# OpenMP stripe directive.
14401447
OMP_STRIPE_DIRECTIVE = 310
14411448

14421449
# OpenACC Compute Construct.
14431450
OPEN_ACC_COMPUTE_DIRECTIVE = 320
14441451

1452+
# OpenACC Loop Construct.
1453+
OpenACCLoopConstruct = 321
1454+
1455+
# OpenACC Combined Constructs.
1456+
OpenACCCombinedConstruct = 322
1457+
1458+
# OpenACC data Construct.
1459+
OpenACCDataConstruct = 323
1460+
1461+
# OpenACC enter data Construct.
1462+
OpenACCEnterDataConstruct = 324
1463+
1464+
# OpenACC exit data Construct.
1465+
OpenACCExitDataConstruct = 325
1466+
1467+
# OpenACC host_data Construct.
1468+
OpenACCHostDataConstruct = 326
1469+
1470+
# OpenACC wait Construct.
1471+
OpenACCWaitConstruct = 327
1472+
1473+
# OpenACC init Construct.
1474+
OpenACCInitConstruct = 328
1475+
1476+
# OpenACC shutdown Construct.
1477+
OpenACCShutdownConstruct = 329
1478+
1479+
# OpenACC set Construct.
1480+
OpenACCSetConstruct = 330
1481+
1482+
# OpenACC update Construct.
1483+
OpenACCUpdateConstruct = 331
1484+
1485+
# OpenACC atomic Construct.
1486+
OpenACCAtomicConstruct = 332
1487+
1488+
# OpenACC cache Construct.
1489+
OpenACCCacheConstruct = 333
1490+
14451491
###
14461492
# Other Kinds
14471493

@@ -1560,6 +1606,7 @@ class ExceptionSpecificationKind(BaseEnumeration):
15601606
UNEVALUATED = 6
15611607
UNINSTANTIATED = 7
15621608
UNPARSED = 8
1609+
NOTHROW = 9
15631610

15641611
### Cursors ###
15651612

@@ -2444,7 +2491,6 @@ class AccessSpecifier(BaseEnumeration):
24442491
PUBLIC = 1
24452492
PROTECTED = 2
24462493
PRIVATE = 3
2447-
NONE = 4
24482494

24492495
### Type Kinds ###
24502496

@@ -2492,7 +2538,16 @@ def spelling(self):
24922538
FLOAT128 = 30
24932539
HALF = 31
24942540
FLOAT16 = 32
2541+
SHORTACCUM = 33
2542+
ACCUM = 34
2543+
LONGACCUM = 35
2544+
USHORTACCUM = 36
2545+
UACCUM = 37
2546+
ULONGACCUM = 38
2547+
BFLOAT16 = 39
24952548
IBM128 = 40
2549+
FIRSTBUILTIN = VOID
2550+
LASTBUILTIN = IBM128
24962551
COMPLEX = 100
24972552
POINTER = 101
24982553
BLOCKPOINTER = 102
@@ -2576,6 +2631,10 @@ def spelling(self):
25762631
ATOMIC = 177
25772632
BTFTAGATTRIBUTED = 178
25782633

2634+
HLSLRESOURCE = 179
2635+
HLSLATTRIBUTEDRESOURCE = 180
2636+
HLSLINLINESPIRV = 181
2637+
25792638
class RefQualifierKind(BaseEnumeration):
25802639
"""Describes a specific ref-qualifier of a type."""
25812640

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from pathlib import Path
23

34
from clang.cindex import (
45
AccessSpecifier,
@@ -13,26 +14,15 @@
1314
TemplateArgumentKind,
1415
TLSKind,
1516
TokenKind,
17+
TranslationUnit,
1618
TypeKind,
19+
PrintingPolicyProperty,
20+
BaseEnumeration,
1721
)
1822

1923

2024
class TestEnums(unittest.TestCase):
21-
enums = [
22-
TokenKind,
23-
CursorKind,
24-
TemplateArgumentKind,
25-
ExceptionSpecificationKind,
26-
AvailabilityKind,
27-
AccessSpecifier,
28-
TypeKind,
29-
RefQualifierKind,
30-
LanguageKind,
31-
LinkageKind,
32-
TLSKind,
33-
StorageClass,
34-
BinaryOperator,
35-
]
25+
enums = BaseEnumeration.__subclasses__()
3626

3727
def test_from_id(self):
3828
"""Check that kinds can be constructed from valid IDs"""
@@ -44,10 +34,70 @@ def test_from_id(self):
4434
with self.assertRaises(ValueError):
4535
enum.from_id(-1)
4636

47-
def test_duplicate_ids(self):
48-
"""Check that no two kinds have the same id"""
49-
# for enum in self.enums:
37+
def test_all_variants(self):
38+
"""Check that all libclang enum values are also defined in cindex.py"""
39+
cenum_to_pythonenum = {
40+
"CX_CXXAccessSpecifier": AccessSpecifier,
41+
"CX_StorageClass": StorageClass,
42+
"CXAvailabilityKind": AvailabilityKind,
43+
"CXBinaryOperatorKind": BinaryOperator,
44+
"CXCursorKind": CursorKind,
45+
"CXCursor_ExceptionSpecificationKind": ExceptionSpecificationKind,
46+
"CXLanguageKind": LanguageKind,
47+
"CXLinkageKind": LinkageKind,
48+
"CXPrintingPolicyProperty": PrintingPolicyProperty,
49+
"CXRefQualifierKind": RefQualifierKind,
50+
"CXTemplateArgumentKind": TemplateArgumentKind,
51+
"CXTLSKind": TLSKind,
52+
"CXTokenKind": TokenKind,
53+
"CXTypeKind": TypeKind,
54+
}
55+
56+
indexheader = (
57+
Path(__file__).parent.parent.parent.parent.parent
58+
/ "include/clang-c/Index.h"
59+
)
60+
# FIXME: Index.h is a C file, but we read it as a C++ file because we
61+
# don't get ENUM_CONSTANT_DECL cursors otherwise, which we need here
62+
# See bug report: https://github.com/llvm/llvm-project/issues/159075
63+
tu = TranslationUnit.from_source(indexheader, ["-x", "c++"])
64+
65+
enum_variant_map = {}
66+
# For all enums in self.enums, extract all enum variants defined in Index.h
67+
for cursor in tu.cursor.walk_preorder():
68+
if cursor.kind == CursorKind.ENUM_CONSTANT_DECL:
69+
python_enum = cenum_to_pythonenum.get(cursor.type.spelling)
70+
if python_enum not in enum_variant_map:
71+
enum_variant_map[python_enum] = dict()
72+
enum_variant_map[python_enum][cursor.enum_value] = cursor.spelling
73+
5074
for enum in self.enums:
51-
num_declared_variants = len(enum._member_map_.keys())
52-
num_unique_variants = len(list(enum))
53-
self.assertEqual(num_declared_variants, num_unique_variants)
75+
with self.subTest(enum):
76+
# This ensures only the custom assert message below is printed
77+
self.longMessage = False
78+
79+
python_kinds = set([kind.value for kind in enum])
80+
num_to_c_kind = enum_variant_map[enum]
81+
c_kinds = set(num_to_c_kind.keys())
82+
# Defined in Index.h but not in cindex.py
83+
missing_python_kinds = c_kinds - python_kinds
84+
missing_names = set(
85+
[num_to_c_kind[kind] for kind in missing_python_kinds]
86+
)
87+
self.assertEqual(
88+
missing_names,
89+
set(),
90+
f"{missing_names} variants are missing. "
91+
f"Please ensure these are defined in {enum} in cindex.py.",
92+
)
93+
# Defined in cindex.py but not in Index.h
94+
superfluous_python_kinds = python_kinds - c_kinds
95+
missing_names = set(
96+
[enum.from_id(kind) for kind in superfluous_python_kinds]
97+
)
98+
self.assertEqual(
99+
missing_names,
100+
set(),
101+
f"{missing_names} variants only exist in the Python bindings. "
102+
f"Please ensure that all {enum} kinds defined in cindex.py have an equivalent in Index.h",
103+
)

0 commit comments

Comments
 (0)