Skip to content

Commit 7e84b2c

Browse files
author
iclsrc
committed
Merge from 'main' to 'sycl-web' (52 commits)
CONFLICT (content): Merge conflict in libclc/cmake/modules/AddLibclc.cmake
2 parents ea631ee + 295d548 commit 7e84b2c

File tree

177 files changed

+14371
-2712
lines changed

Some content is hidden

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

177 files changed

+14371
-2712
lines changed

clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using namespace clang::ast_matchers;
1515

1616
namespace clang::tidy::readability {
17+
1718
void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
1819
const auto Literal0 = integerLiteral(equals(0));
1920
const auto Literal1 = integerLiteral(equals(1));
@@ -47,57 +48,36 @@ void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
4748
const auto StringNpos = anyOf(declRefExpr(to(varDecl(hasName("npos")))),
4849
memberExpr(member(hasName("npos"))));
4950

50-
auto AddSimpleMatcher = [&](const auto &Matcher) {
51-
Finder->addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, Matcher), this);
52-
};
53-
54-
// Find membership tests which use `count()`.
55-
Finder->addMatcher(implicitCastExpr(hasImplicitDestinationType(booleanType()),
56-
hasSourceExpression(CountCall))
57-
.bind("positiveComparison"),
58-
this);
59-
AddSimpleMatcher(
60-
binaryOperation(hasOperatorName("!="), hasOperands(CountCall, Literal0))
61-
.bind("positiveComparison"));
62-
AddSimpleMatcher(
63-
binaryOperation(hasLHS(CountCall), hasOperatorName(">"), hasRHS(Literal0))
64-
.bind("positiveComparison"));
65-
AddSimpleMatcher(
66-
binaryOperation(hasLHS(Literal0), hasOperatorName("<"), hasRHS(CountCall))
67-
.bind("positiveComparison"));
68-
AddSimpleMatcher(binaryOperation(hasLHS(CountCall), hasOperatorName(">="),
69-
hasRHS(Literal1))
70-
.bind("positiveComparison"));
71-
AddSimpleMatcher(binaryOperation(hasLHS(Literal1), hasOperatorName("<="),
72-
hasRHS(CountCall))
73-
.bind("positiveComparison"));
74-
75-
// Find inverted membership tests which use `count()`.
76-
AddSimpleMatcher(
77-
binaryOperation(hasOperatorName("=="), hasOperands(CountCall, Literal0))
78-
.bind("negativeComparison"));
79-
AddSimpleMatcher(binaryOperation(hasLHS(CountCall), hasOperatorName("<="),
80-
hasRHS(Literal0))
81-
.bind("negativeComparison"));
82-
AddSimpleMatcher(binaryOperation(hasLHS(Literal0), hasOperatorName(">="),
83-
hasRHS(CountCall))
84-
.bind("negativeComparison"));
85-
AddSimpleMatcher(
86-
binaryOperation(hasLHS(CountCall), hasOperatorName("<"), hasRHS(Literal1))
87-
.bind("negativeComparison"));
88-
AddSimpleMatcher(
89-
binaryOperation(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
90-
.bind("negativeComparison"));
91-
92-
// Find membership tests based on `find() == end()` or `find() == npos`.
93-
AddSimpleMatcher(
94-
binaryOperation(hasOperatorName("!="),
95-
hasOperands(FindCall, anyOf(EndCall, StringNpos)))
96-
.bind("positiveComparison"));
97-
AddSimpleMatcher(
98-
binaryOperation(hasOperatorName("=="),
99-
hasOperands(FindCall, anyOf(EndCall, StringNpos)))
100-
.bind("negativeComparison"));
51+
Finder->addMatcher(
52+
traverse(TK_AsIs,
53+
implicitCastExpr(hasImplicitDestinationType(booleanType()),
54+
hasSourceExpression(CountCall))
55+
.bind("positiveComparison")),
56+
this);
57+
58+
const auto PositiveComparison =
59+
anyOf(allOf(hasOperatorName("!="), hasOperands(CountCall, Literal0)),
60+
allOf(hasLHS(CountCall), hasOperatorName(">"), hasRHS(Literal0)),
61+
allOf(hasLHS(Literal0), hasOperatorName("<"), hasRHS(CountCall)),
62+
allOf(hasLHS(CountCall), hasOperatorName(">="), hasRHS(Literal1)),
63+
allOf(hasLHS(Literal1), hasOperatorName("<="), hasRHS(CountCall)),
64+
allOf(hasOperatorName("!="),
65+
hasOperands(FindCall, anyOf(EndCall, StringNpos))));
66+
67+
const auto NegativeComparison =
68+
anyOf(allOf(hasOperatorName("=="), hasOperands(CountCall, Literal0)),
69+
allOf(hasLHS(CountCall), hasOperatorName("<="), hasRHS(Literal0)),
70+
allOf(hasLHS(Literal0), hasOperatorName(">="), hasRHS(CountCall)),
71+
allOf(hasLHS(CountCall), hasOperatorName("<"), hasRHS(Literal1)),
72+
allOf(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall)),
73+
allOf(hasOperatorName("=="),
74+
hasOperands(FindCall, anyOf(EndCall, StringNpos))));
75+
76+
Finder->addMatcher(
77+
binaryOperation(
78+
anyOf(allOf(PositiveComparison, expr().bind("positiveComparison")),
79+
allOf(NegativeComparison, expr().bind("negativeComparison")))),
80+
this);
10181
}
10282

10383
void ContainerContainsCheck::check(const MatchFinder::MatchResult &Result) {

clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ContainerContainsCheck : public ClangTidyCheck {
2929
return LO.CPlusPlus;
3030
}
3131
std::optional<TraversalKind> getCheckTraversalKind() const override {
32-
return TK_AsIs;
32+
return TK_IgnoreUnlessSpelledInSource;
3333
}
3434
};
3535

clang/docs/BoundsSafety.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ Annotations for sentinel-delimited arrays
352352
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
353353

354354
A C string is an array of characters. The null terminator — the first null
355-
character ('\0') element in the array — marks the end of the string.
355+
character (``'\0'``) element in the array — marks the end of the string.
356356
``-fbounds-safety`` provides ``__null_terminated`` to annotate C strings and the
357357
generalized form ``__terminated_by(T)`` to annotate pointers and arrays with an
358358
end marked by a sentinel value. The model prevents dereferencing a
@@ -439,17 +439,17 @@ extension`_ for more details about the toolchain header):
439439

440440
.. code-block:: C
441441
442-
#define __ptrcheck_abi_assume_single() \
443-
_Pragma("clang abi_ptr_attr set(single)")
442+
#define __ptrcheck_abi_assume_single() \
443+
_Pragma("clang abi_ptr_attr set(single)")
444444
445-
#define __ptrcheck_abi_assume_indexable() \
446-
_Pragma("clang abi_ptr_attr set(indexable)")
445+
#define __ptrcheck_abi_assume_indexable() \
446+
_Pragma("clang abi_ptr_attr set(indexable)")
447447
448-
#define __ptrcheck_abi_assume_bidi_indexable() \
449-
_Pragma("clang abi_ptr_attr set(bidi_indexable)")
448+
#define __ptrcheck_abi_assume_bidi_indexable() \
449+
_Pragma("clang abi_ptr_attr set(bidi_indexable)")
450450
451-
#define __ptrcheck_abi_assume_unsafe_indexable() \
452-
_Pragma("clang abi_ptr_attr set(unsafe_indexable)")
451+
#define __ptrcheck_abi_assume_unsafe_indexable() \
452+
_Pragma("clang abi_ptr_attr set(unsafe_indexable)")
453453
454454
455455
ABI implications of default bounds annotations

clang/include/clang/Basic/DarwinSDKInfo.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,21 @@ class DarwinSDKInfo {
181181
using PlatformInfoStorageType = SmallVector<SDKPlatformInfo, 2>;
182182

183183
DarwinSDKInfo(
184-
VersionTuple Version, VersionTuple MaximumDeploymentTarget,
184+
std::string FilePath, VersionTuple Version,
185+
VersionTuple MaximumDeploymentTarget,
185186
PlatformInfoStorageType PlatformInfos,
186187
llvm::DenseMap<OSEnvPair::StorageType,
187188
std::optional<RelatedTargetVersionMapping>>
188189
VersionMappings =
189190
llvm::DenseMap<OSEnvPair::StorageType,
190191
std::optional<RelatedTargetVersionMapping>>())
191-
: Version(Version), MaximumDeploymentTarget(MaximumDeploymentTarget),
192+
: FilePath(FilePath), Version(Version),
193+
MaximumDeploymentTarget(MaximumDeploymentTarget),
192194
PlatformInfos(std::move(PlatformInfos)),
193195
VersionMappings(std::move(VersionMappings)) {}
194196

197+
StringRef getFilePath() const { return FilePath; }
198+
195199
const llvm::VersionTuple &getVersion() const { return Version; }
196200

197201
const SDKPlatformInfo &getCanonicalPlatformInfo() const {
@@ -224,9 +228,11 @@ class DarwinSDKInfo {
224228
}
225229

226230
static std::optional<DarwinSDKInfo>
227-
parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj);
231+
parseDarwinSDKSettingsJSON(std::string FilePath,
232+
const llvm::json::Object *Obj);
228233

229234
private:
235+
std::string FilePath;
230236
VersionTuple Version;
231237
VersionTuple MaximumDeploymentTarget;
232238
PlatformInfoStorageType PlatformInfos;

clang/lib/Basic/DarwinSDKInfo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ static std::optional<VersionTuple> getVersionKey(const llvm::json::Object &Obj,
176176
}
177177

178178
std::optional<DarwinSDKInfo>
179-
DarwinSDKInfo::parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj) {
179+
DarwinSDKInfo::parseDarwinSDKSettingsJSON(std::string FilePath,
180+
const llvm::json::Object *Obj) {
180181
auto Version = getVersionKey(*Obj, "Version");
181182
if (!Version)
182183
return std::nullopt;
@@ -226,7 +227,7 @@ DarwinSDKInfo::parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj) {
226227
}
227228
}
228229

229-
return DarwinSDKInfo(std::move(*Version),
230+
return DarwinSDKInfo(std::move(FilePath), std::move(*Version),
230231
std::move(*MaximumDeploymentVersion),
231232
std::move(PlatformInfos), std::move(VersionMappings));
232233
}
@@ -247,7 +248,8 @@ clang::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath) {
247248
return Result.takeError();
248249

249250
if (const auto *Obj = Result->getAsObject()) {
250-
if (auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON(Obj))
251+
if (auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON(
252+
Filepath.str().str(), Obj))
251253
return std::move(SDKInfo);
252254
}
253255
return llvm::make_error<llvm::StringError>("invalid SDKSettings.json",

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
16461646
case Builtin::BIaddressof:
16471647
case Builtin::BI__addressof:
16481648
case Builtin::BI__builtin_addressof:
1649+
return RValue::get(emitLValue(e->getArg(0)).getPointer());
16491650
case Builtin::BI__builtin_function_start:
16501651
return errorBuiltinNYI(*this, e, builtinID);
16511652
case Builtin::BI__builtin_operator_new:

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ struct DarwinPlatform {
19171917
StringRef PlatformPrefix =
19181918
(Platform == DarwinPlatformKind::DriverKit) ? "/System/DriverKit" : "";
19191919
return DarwinSDKInfo(
1920-
getOSVersion(), /*MaximumDeploymentTarget=*/
1920+
"", getOSVersion(), /*MaximumDeploymentTarget=*/
19211921
VersionTuple(getOSVersion().getMajor(), 0, 99),
19221922
{DarwinSDKInfo::SDKPlatformInfo(llvm::Triple::Apple, OS,
19231923
llvm::Triple::UnknownEnvironment,
@@ -3289,6 +3289,16 @@ void Darwin::addClangTargetOptions(
32893289

32903290
addClangCC1ASTargetOptions(DriverArgs, CC1Args);
32913291

3292+
if (SDKInfo) {
3293+
// Make the SDKSettings.json an explicit dependency for the compiler
3294+
// invocation, in case the compiler needs to read it to remap versions.
3295+
if (!SDKInfo->getFilePath().empty()) {
3296+
SmallString<64> ExtraDepOpt("-fdepfile-entry=");
3297+
ExtraDepOpt += SDKInfo->getFilePath();
3298+
CC1Args.push_back(DriverArgs.MakeArgString(ExtraDepOpt));
3299+
}
3300+
}
3301+
32923302
// Enable compatibility mode for NSItemProviderCompletionHandler in
32933303
// Foundation/NSItemProvider.h.
32943304
CC1Args.push_back("-fcompatibility-qualified-id-block-type-checking");
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4+
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7+
8+
struct Container {
9+
int x;
10+
int y;
11+
};
12+
13+
void builtin_address_of() {
14+
Container a;
15+
Container* b = __builtin_addressof(a);
16+
}
17+
18+
// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_Container, !cir.ptr<!rec_Container>, ["a"]
19+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Container>, !cir.ptr<!cir.ptr<!rec_Container>>, ["b", init]
20+
// CIR: cir.store {{.*}} %[[A_ADDR]], %[[B_ADDR]] : !cir.ptr<!rec_Container>, !cir.ptr<!cir.ptr<!rec_Container>>
21+
22+
// LLVM: %[[A_ADDR:.*]] = alloca %struct.Container, i64 1, align 4
23+
// LLVM: %[[B_ADDR:.*]] = alloca ptr, i64 1, align 8
24+
// LLVM: store ptr %[[A_ADDR]], ptr %[[B_ADDR]], align 8
25+
26+
// OGCG: %[[A_ADDR:.*]] = alloca %struct.Container, align 4
27+
// OGCG: %[[B_ADDR:.*]] = alloca ptr, align 8
28+
// OGCG: store ptr %[[A_ADDR]], ptr %[[B_ADDR]], align 8

0 commit comments

Comments
 (0)