Skip to content

Commit 0b1e61a

Browse files
authored
merge main into amd-staging (llvm#1679)
2 parents d4a3b12 + 9e810ad commit 0b1e61a

File tree

197 files changed

+5220
-1316
lines changed

Some content is hidden

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

197 files changed

+5220
-1316
lines changed

clang-tools-extra/clang-doc/Mapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace clang {
1919
namespace doc {
2020

2121
static llvm::StringSet<> USRVisited;
22-
static llvm::sys::Mutex USRVisitedGuard;
22+
static llvm::sys::SmartMutex<true> USRVisitedGuard;
2323

2424
template <typename T> bool isTypedefAnonRecord(const T *D) {
2525
if (const auto *C = dyn_cast<CXXRecordDecl>(D)) {
@@ -48,7 +48,7 @@ bool MapASTVisitor::mapDecl(const T *D, bool IsDefinition) {
4848
return true;
4949
// Prevent Visiting USR twice
5050
{
51-
std::lock_guard<llvm::sys::Mutex> Guard(USRVisitedGuard);
51+
llvm::sys::SmartScopedLock<true> Guard(USRVisitedGuard);
5252
StringRef Visited = USR.str();
5353
if (USRVisited.count(Visited) && !isTypedefAnonRecord<T>(D))
5454
return true;

clang/docs/ControlFlowIntegrity.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ of undefined behavior that can potentially allow attackers to subvert the
1919
program's control flow. These schemes have been optimized for performance,
2020
allowing developers to enable them in release builds.
2121

22-
To enable Clang's available CFI schemes, use the flag ``-fsanitize=cfi``.
23-
You can also enable a subset of available :ref:`schemes <cfi-schemes>`.
24-
As currently implemented, all schemes rely on link-time optimization (LTO);
25-
so it is required to specify ``-flto``, and the linker used must support LTO,
26-
for example via the `gold plugin`_.
22+
To enable Clang's available CFI schemes, use the flag
23+
``-fsanitize=cfi``. You can also enable a subset of available
24+
:ref:`schemes <cfi-schemes>`. As currently implemented, all schemes
25+
except for ``kcfi`` rely on link-time optimization (LTO); so it is
26+
required to specify ``-flto`` or ``-flto=thin``, and the linker used
27+
must support LTO, for example via the `gold plugin`_.
2728

2829
To allow the checks to be implemented efficiently, the program must
2930
be structured such that certain object files are compiled with CFI
@@ -426,6 +427,6 @@ Publications
426427
`Control-Flow Integrity: Principles, Implementations, and Applications <https://research.microsoft.com/pubs/64250/ccs05.pdf>`_.
427428
Martin Abadi, Mihai Budiu, Úlfar Erlingsson, Jay Ligatti.
428429

429-
`Enforcing Forward-Edge Control-Flow Integrity in GCC & LLVM <http://www.pcc.me.uk/~peter/acad/usenix14.pdf>`_.
430+
`Enforcing Forward-Edge Control-Flow Integrity in GCC & LLVM <https://www.usenix.org/system/files/conference/usenixsecurity14/sec14-paper-tice.pdf>`_.
430431
Caroline Tice, Tom Roeder, Peter Collingbourne, Stephen Checkoway,
431432
Úlfar Erlingsson, Luis Lozano, Geoff Pike.

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ Modified Compiler Flags
217217

218218
- The compiler flag `-fbracket-depth` default value is increased from 256 to 2048. (#GH94728)
219219

220+
- `-Wpadded` option implemented for the `x86_64-windows-msvc` target. Fixes #61702
221+
220222
Removed Compiler Flags
221223
-------------------------
222224

@@ -372,6 +374,8 @@ Improvements to Clang's diagnostics
372374
- Now correctly diagnose a tentative definition of an array with static
373375
storage duration in pedantic mode in C. (#GH50661)
374376

377+
- An error is now emitted when a ``musttail`` call is made to a function marked with the ``not_tail_called`` attribute. (#GH133509).
378+
375379
Improvements to Clang's time-trace
376380
----------------------------------
377381

@@ -446,6 +450,7 @@ Bug Fixes to C++ Support
446450
by template argument deduction.
447451
- Clang is now better at instantiating the function definition after its use inside
448452
of a constexpr lambda. (#GH125747)
453+
- Fixed a local class member function instantiation bug inside dependent lambdas. (#GH59734), (#GH132208)
449454
- Clang no longer crashes when trying to unify the types of arrays with
450455
certain differences in qualifiers (this could happen during template argument
451456
deduction or when building a ternary operator). (#GH97005)

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,6 +3172,8 @@ def note_musttail_mismatch : Note<
31723172
"|has type mismatch at %ordinal3 parameter"
31733173
"%diff{ (expected $ but has $)|}1,2"
31743174
"|has different return type%diff{ ($ expected but has $)|}1,2}0">;
3175+
def note_musttail_disabled_by_not_tail_called : Note<
3176+
"'not_tail_called' attribute prevents being called as a tail call">;
31753177
def err_musttail_callconv_mismatch : Error<
31763178
"cannot perform a tail call to function%select{| %1}0 because it uses an "
31773179
"incompatible calling convention">;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
namespace cir {
2222

23+
namespace detail {
24+
struct RecordTypeStorage;
25+
} // namespace detail
26+
2327
bool isAnyFloatingPointType(mlir::Type t);
2428
bool isFPOrFPVectorTy(mlir::Type);
2529

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

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,122 @@ def VoidPtr : Type<
400400
"cir::VoidType::get($_builder.getContext()))"> {
401401
}
402402

403+
//===----------------------------------------------------------------------===//
404+
// RecordType
405+
//
406+
// The base type for all RecordDecls.
407+
//===----------------------------------------------------------------------===//
408+
409+
def CIR_RecordType : CIR_Type<"Record", "record",
410+
[
411+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
412+
MutableType,
413+
]> {
414+
let summary = "CIR record type";
415+
let description = [{
416+
Each unique clang::RecordDecl is mapped to a `cir.record` and any object in
417+
C/C++ that has a struct or class type will have a `cir.record` in CIR.
418+
419+
There are three possible formats for this type:
420+
421+
- Identified and complete records: unique name and a known body.
422+
- Identified and incomplete records: unique name and unknown body.
423+
- Anonymous records: no name and a known body.
424+
425+
Identified records are uniqued by their name, and anonymous records are
426+
uniqued by their body. This means that two anonymous records with the same
427+
body will be the same type, and two identified records with the same name
428+
will be the same type. Attempting to build a record with an existing name,
429+
but a different body will result in an error.
430+
431+
A few examples:
432+
433+
```mlir
434+
!complete = !cir.record<struct "complete" {!cir.int<u, 8>}>
435+
!incomplete = !cir.record<struct "incomplete" incomplete>
436+
!anonymous = !cir.record<struct {!cir.int<u, 8>}>
437+
```
438+
439+
Incomplete records are mutable, meaning they can be later completed with a
440+
body automatically updating in place every type in the code that uses the
441+
incomplete record. Mutability allows for recursive types to be represented,
442+
meaning the record can have members that refer to itself. This is useful for
443+
representing recursive records and is implemented through a special syntax.
444+
In the example below, the `Node` record has a member that is a pointer to a
445+
`Node` record:
446+
447+
```mlir
448+
!s = !cir.record<struct "Node" {!cir.ptr<!cir.record<struct "Node">>}>
449+
```
450+
}];
451+
452+
let parameters = (ins
453+
OptionalArrayRefParameter<"mlir::Type">:$members,
454+
OptionalParameter<"mlir::StringAttr">:$name,
455+
"bool":$incomplete,
456+
"bool":$packed,
457+
"bool":$padded,
458+
"RecordType::RecordKind":$kind
459+
);
460+
461+
// StorageClass is defined in C++ for mutability.
462+
let storageClass = "RecordTypeStorage";
463+
let genStorageClass = 0;
464+
465+
let skipDefaultBuilders = 1;
466+
let genVerifyDecl = 1;
467+
468+
let builders = [
469+
// Create an identified and incomplete record type.
470+
TypeBuilder<(ins
471+
"mlir::StringAttr":$name,
472+
"RecordKind":$kind
473+
), [{
474+
return $_get($_ctxt, /*members=*/llvm::ArrayRef<Type>{}, name,
475+
/*incomplete=*/true, /*packed=*/false,
476+
/*padded=*/false, kind);
477+
}]>];
478+
479+
let extraClassDeclaration = [{
480+
using Base::verifyInvariants;
481+
482+
enum RecordKind : uint32_t { Struct, Union };
483+
484+
bool isStruct() const { return getKind() == RecordKind::Struct; };
485+
bool isUnion() const { return getKind() == RecordKind::Union; };
486+
bool isComplete() const { return !isIncomplete(); };
487+
bool isIncomplete() const;
488+
489+
size_t getNumElements() const { return getMembers().size(); };
490+
std::string getKindAsStr() {
491+
switch (getKind()) {
492+
case RecordKind::Union:
493+
return "union";
494+
case RecordKind::Struct:
495+
return "struct";
496+
}
497+
llvm_unreachable("Invalid value for RecordType::getKind()");
498+
}
499+
std::string getPrefixedName() {
500+
return getKindAsStr() + "." + getName().getValue().str();
501+
}
502+
}];
503+
504+
let hasCustomAssemblyFormat = 1;
505+
}
506+
507+
// Note CIRRecordType is used instead of CIR_RecordType
508+
// because of tablegen conflicts.
509+
def CIRRecordType : Type<
510+
CPred<"::mlir::isa<::cir::RecordType>($_self)">, "CIR record type">;
511+
403512
//===----------------------------------------------------------------------===//
404513
// Global type constraints
405514
//===----------------------------------------------------------------------===//
406515

407516
def CIR_AnyType : AnyTypeOf<[
408517
CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_IntType, CIR_AnyFloat,
409-
CIR_PointerType, CIR_FuncType
518+
CIR_PointerType, CIR_FuncType, CIR_RecordType
410519
]>;
411520

412521
#endif // MLIR_CIR_DIALECT_CIR_TYPES
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//===----------------------------------------------------------------------===//
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+
// This file contains implementation details, such as storage structures, of
10+
// CIR dialect types.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
#ifndef CIR_DIALECT_IR_CIRTYPESDETAILS_H
14+
#define CIR_DIALECT_IR_CIRTYPESDETAILS_H
15+
16+
#include "mlir/IR/BuiltinAttributes.h"
17+
#include "mlir/Support/LogicalResult.h"
18+
#include "clang/CIR/Dialect/IR/CIRTypes.h"
19+
#include "llvm/ADT/Hashing.h"
20+
21+
namespace cir {
22+
namespace detail {
23+
24+
//===----------------------------------------------------------------------===//
25+
// CIR RecordTypeStorage
26+
//===----------------------------------------------------------------------===//
27+
28+
/// Type storage for CIR record types.
29+
struct RecordTypeStorage : public mlir::TypeStorage {
30+
struct KeyTy {
31+
llvm::ArrayRef<mlir::Type> members;
32+
mlir::StringAttr name;
33+
bool incomplete;
34+
bool packed;
35+
bool padded;
36+
RecordType::RecordKind kind;
37+
38+
KeyTy(llvm::ArrayRef<mlir::Type> members, mlir::StringAttr name,
39+
bool incomplete, bool packed, bool padded,
40+
RecordType::RecordKind kind)
41+
: members(members), name(name), incomplete(incomplete), packed(packed),
42+
padded(padded), kind(kind) {}
43+
};
44+
45+
llvm::ArrayRef<mlir::Type> members;
46+
mlir::StringAttr name;
47+
bool incomplete;
48+
bool packed;
49+
bool padded;
50+
RecordType::RecordKind kind;
51+
52+
RecordTypeStorage(llvm::ArrayRef<mlir::Type> members, mlir::StringAttr name,
53+
bool incomplete, bool packed, bool padded,
54+
RecordType::RecordKind kind)
55+
: members(members), name(name), incomplete(incomplete), packed(packed),
56+
padded(padded), kind(kind) {
57+
assert(name || !incomplete && "Incomplete records must have a name");
58+
}
59+
60+
KeyTy getAsKey() const {
61+
return KeyTy(members, name, incomplete, packed, padded, kind);
62+
}
63+
64+
bool operator==(const KeyTy &key) const {
65+
if (name)
66+
return (name == key.name) && (kind == key.kind);
67+
return std::tie(members, name, incomplete, packed, padded, kind) ==
68+
std::tie(key.members, key.name, key.incomplete, key.packed,
69+
key.padded, key.kind);
70+
}
71+
72+
static llvm::hash_code hashKey(const KeyTy &key) {
73+
if (key.name)
74+
return llvm::hash_combine(key.name, key.kind);
75+
return llvm::hash_combine(key.members, key.incomplete, key.packed,
76+
key.padded, key.kind);
77+
}
78+
79+
static RecordTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
80+
const KeyTy &key) {
81+
return new (allocator.allocate<RecordTypeStorage>())
82+
RecordTypeStorage(allocator.copyInto(key.members), key.name,
83+
key.incomplete, key.packed, key.padded, key.kind);
84+
}
85+
86+
/// Mutates the members and attributes an identified record.
87+
///
88+
/// Once a record is mutated, it is marked as complete, preventing further
89+
/// mutations. Anonymous records are always complete and cannot be mutated.
90+
/// This method does not fail if a mutation of a complete record does not
91+
/// change the record.
92+
llvm::LogicalResult mutate(mlir::TypeStorageAllocator &allocator,
93+
llvm::ArrayRef<mlir::Type> members, bool packed,
94+
bool padded) {
95+
// Anonymous records cannot mutate.
96+
if (!name)
97+
return llvm::failure();
98+
99+
// Mutation of complete records are allowed if they change nothing.
100+
if (!incomplete)
101+
return mlir::success((this->members == members) &&
102+
(this->packed == packed) &&
103+
(this->padded == padded));
104+
105+
// Mutate incomplete record.
106+
this->members = allocator.copyInto(members);
107+
this->packed = packed;
108+
this->padded = padded;
109+
110+
incomplete = false;
111+
return llvm::success();
112+
}
113+
};
114+
115+
} // namespace detail
116+
} // namespace cir
117+
118+
#endif // CIR_DIALECT_IR_CIRTYPESDETAILS_H

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ struct MissingFeatures {
101101
static bool mayHaveIntegerOverflow() { return false; }
102102
static bool shouldReverseUnaryCondOnBoolExpr() { return false; }
103103

104+
// RecordType
105+
static bool recordTypeLayoutInfo() { return false; }
106+
104107
// Misc
105108
static bool cxxABI() { return false; }
106109
static bool tryEmitAsConstant() { return false; }

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,10 @@ def offload_compression_level_EQ : Joined<["--"], "offload-compression-level=">,
12391239
Flags<[HelpHidden]>,
12401240
HelpText<"Compression level for offload device binaries (HIP only)">;
12411241

1242+
def offload_jobs_EQ : Joined<["--"], "offload-jobs=">,
1243+
HelpText<"Specify the number of threads to use for device offloading tasks"
1244+
" during compilation.">;
1245+
12421246
defm offload_via_llvm : BoolFOption<"offload-via-llvm",
12431247
LangOpts<"OffloadViaLLVM">, DefaultFalse,
12441248
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use">,

0 commit comments

Comments
 (0)