Skip to content

Commit 5064494

Browse files
authored
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_reference_binding_to_temporary
2 parents 17197b3 + 556eb82 commit 5064494

File tree

372 files changed

+17457
-6635
lines changed

Some content is hidden

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

372 files changed

+17457
-6635
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ Improvements to Clang's diagnostics
199199
- Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with
200200
``-Wno-error=parentheses``.
201201

202+
- The :doc:`ThreadSafetyAnalysis` now supports ``-Wthread-safety-pointer``,
203+
which enables warning on passing or returning pointers to guarded variables
204+
as function arguments or return value respectively. Note that
205+
:doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
206+
feature will be default-enabled with ``-Wthread-safety`` in a future release.
207+
202208
Improvements to Clang's time-trace
203209
----------------------------------
204210

clang/docs/ThreadSafetyAnalysis.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,12 @@ Warning flags
515515
+ ``-Wthread-safety-analysis``: The core analysis.
516516
+ ``-Wthread-safety-precise``: Requires that mutex expressions match precisely.
517517
This warning can be disabled for code which has a lot of aliases.
518-
+ ``-Wthread-safety-reference``: Checks when guarded members are passed by reference.
518+
+ ``-Wthread-safety-reference``: Checks when guarded members are passed or
519+
returned by reference.
519520

521+
* ``-Wthread-safety-pointer``: Checks when passing or returning pointers to
522+
guarded variables, or pointers to guarded data, as function argument or
523+
return value respectively.
520524

521525
:ref:`negative` are an experimental feature, which are enabled with:
522526

clang/include/clang/AST/ASTContext.h

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
410410
/// The identifier 'NSCopying'.
411411
IdentifierInfo *NSCopyingName = nullptr;
412412

413-
/// The identifier '__make_integer_seq'.
414-
mutable IdentifierInfo *MakeIntegerSeqName = nullptr;
415-
416-
/// The identifier '__type_pack_element'.
417-
mutable IdentifierInfo *TypePackElementName = nullptr;
418-
419-
/// The identifier '__builtin_common_type'.
420-
mutable IdentifierInfo *BuiltinCommonTypeName = nullptr;
413+
#define BuiltinTemplate(BTName) mutable IdentifierInfo *Name##BTName = nullptr;
414+
#include "clang/Basic/BuiltinTemplates.inc"
421415

422416
QualType ObjCConstantStringType;
423417
mutable RecordDecl *CFConstantStringTagDecl = nullptr;
@@ -629,9 +623,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
629623

630624
TranslationUnitDecl *TUDecl = nullptr;
631625
mutable ExternCContextDecl *ExternCContext = nullptr;
632-
mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
633-
mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
634-
mutable BuiltinTemplateDecl *BuiltinCommonTypeDecl = nullptr;
626+
627+
#define BuiltinTemplate(BTName) \
628+
mutable BuiltinTemplateDecl *Decl##BTName = nullptr;
629+
#include "clang/Basic/BuiltinTemplates.inc"
635630

636631
/// The associated SourceManager object.
637632
SourceManager &SourceMgr;
@@ -1157,9 +1152,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
11571152
}
11581153

11591154
ExternCContextDecl *getExternCContextDecl() const;
1160-
BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
1161-
BuiltinTemplateDecl *getTypePackElementDecl() const;
1162-
BuiltinTemplateDecl *getBuiltinCommonTypeDecl() const;
1155+
1156+
#define BuiltinTemplate(BTName) BuiltinTemplateDecl *get##BTName##Decl() const;
1157+
#include "clang/Basic/BuiltinTemplates.inc"
11631158

11641159
// Builtin Types.
11651160
CanQualType VoidTy;
@@ -2107,23 +2102,13 @@ class ASTContext : public RefCountedBase<ASTContext> {
21072102
return BoolName;
21082103
}
21092104

2110-
IdentifierInfo *getMakeIntegerSeqName() const {
2111-
if (!MakeIntegerSeqName)
2112-
MakeIntegerSeqName = &Idents.get("__make_integer_seq");
2113-
return MakeIntegerSeqName;
2114-
}
2115-
2116-
IdentifierInfo *getTypePackElementName() const {
2117-
if (!TypePackElementName)
2118-
TypePackElementName = &Idents.get("__type_pack_element");
2119-
return TypePackElementName;
2120-
}
2121-
2122-
IdentifierInfo *getBuiltinCommonTypeName() const {
2123-
if (!BuiltinCommonTypeName)
2124-
BuiltinCommonTypeName = &Idents.get("__builtin_common_type");
2125-
return BuiltinCommonTypeName;
2105+
#define BuiltinTemplate(BTName) \
2106+
IdentifierInfo *get##BTName##Name() const { \
2107+
if (!Name##BTName) \
2108+
Name##BTName = &Idents.get(#BTName); \
2109+
return Name##BTName; \
21262110
}
2111+
#include "clang/Basic/BuiltinTemplates.inc"
21272112

21282113
/// Retrieve the Objective-C "instancetype" type, if already known;
21292114
/// otherwise, returns a NULL type;

clang/include/clang/AST/DeclID.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,14 @@ enum PredefinedDeclIDs {
7171
/// The extern "C" context.
7272
PREDEF_DECL_EXTERN_C_CONTEXT_ID,
7373

74-
/// The internal '__make_integer_seq' template.
75-
PREDEF_DECL_MAKE_INTEGER_SEQ_ID,
76-
7774
/// The internal '__NSConstantString' typedef.
7875
PREDEF_DECL_CF_CONSTANT_STRING_ID,
7976

8077
/// The internal '__NSConstantString' tag type.
8178
PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID,
8279

83-
/// The internal '__type_pack_element' template.
84-
PREDEF_DECL_TYPE_PACK_ELEMENT_ID,
85-
86-
/// The internal '__builtin_common_type' template.
87-
PREDEF_DECL_COMMON_TYPE_ID,
80+
#define BuiltinTemplate(BTName) PREDEF_DECL##BTName##_ID,
81+
#include "clang/Basic/BuiltinTemplates.inc"
8882

8983
/// The number of declaration IDs that are predefined.
9084
NUM_PREDEF_DECL_IDS

clang/include/clang/Analysis/Analyses/ThreadSafety.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ enum ProtectedOperationKind {
5454

5555
/// Returning a pt-guarded variable by reference.
5656
POK_PtReturnByRef,
57+
58+
/// Passing pointer to a guarded variable.
59+
POK_PassPointer,
60+
61+
/// Passing a pt-guarded pointer.
62+
POK_PtPassPointer,
63+
64+
/// Returning pointer to a guarded variable.
65+
POK_ReturnPointer,
66+
67+
/// Returning a pt-guarded pointer.
68+
POK_PtReturnPointer,
5769
};
5870

5971
/// This enum distinguishes between different kinds of lock actions. For
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===--- BuiltinTemplates.td - Clang builtin template aliases ---*- 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+
class TemplateArg<string name> {
10+
string Name = name;
11+
}
12+
13+
class Template<list<TemplateArg> args, string name> : TemplateArg<name> {
14+
list<TemplateArg> Args = args;
15+
}
16+
17+
class Class<string name, bit is_variadic = 0> : TemplateArg<name> {
18+
bit IsVariadic = is_variadic;
19+
}
20+
21+
class NTTP<string type_name, string name, bit is_variadic = 0> : TemplateArg<name> {
22+
string TypeName = type_name;
23+
bit IsVariadic = is_variadic;
24+
}
25+
26+
class BuiltinNTTP<string type_name> : TemplateArg<""> {
27+
string TypeName = type_name;
28+
}
29+
30+
def SizeT : BuiltinNTTP<"size_t"> {}
31+
32+
class BuiltinTemplate<list<TemplateArg> template_head> {
33+
list<TemplateArg> TemplateHead = template_head;
34+
}
35+
36+
// template <template <class T, T... Ints> IntSeq, class T, T N>
37+
def __make_integer_seq : BuiltinTemplate<
38+
[Template<[Class<"T">, NTTP<"T", "Ints", /*is_variadic=*/1>], "IntSeq">, Class<"T">, NTTP<"T", "N">]>;
39+
40+
// template <size_t, class... T>
41+
def __type_pack_element : BuiltinTemplate<
42+
[SizeT, Class<"T", /*is_variadic=*/1>]>;
43+
44+
// template <template <class... Args> BaseTemplate,
45+
// template <class TypeMember> HasTypeMember,
46+
// class HasNoTypeMember
47+
// class... Ts>
48+
def __builtin_common_type : BuiltinTemplate<
49+
[Template<[Class<"Args", /*is_variadic=*/1>], "BaseTemplate">,
50+
Template<[Class<"TypeMember">], "HasTypeMember">,
51+
Class<"HasNoTypeMember">,
52+
Class<"Ts", /*is_variadic=*/1>]>;

clang/include/clang/Basic/Builtins.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,8 @@ bool evaluateRequiredTargetFeatures(
459459

460460
/// Kinds of BuiltinTemplateDecl.
461461
enum BuiltinTemplateKind : int {
462-
/// This names the __make_integer_seq BuiltinTemplateDecl.
463-
BTK__make_integer_seq,
464-
465-
/// This names the __type_pack_element BuiltinTemplateDecl.
466-
BTK__type_pack_element,
467-
468-
/// This names the __builtin_common_type BuiltinTemplateDecl.
469-
BTK__builtin_common_type,
462+
#define BuiltinTemplate(BTName) BTK##BTName,
463+
#include "clang/Basic/BuiltinTemplates.inc"
470464
};
471465

472466
} // end namespace clang

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ clang_tablegen(BuiltinsX86_64.inc -gen-clang-builtins
9696
SOURCE BuiltinsX86_64.td
9797
TARGET ClangBuiltinsX86_64)
9898

99+
clang_tablegen(BuiltinTemplates.inc -gen-clang-builtin-templates
100+
SOURCE BuiltinTemplates.td
101+
TARGET ClangBuiltinTemplates)
102+
99103
# ARM NEON and MVE
100104
clang_tablegen(arm_neon.inc -gen-arm-neon-sema
101105
SOURCE arm_neon.td

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ def ThreadSafetyPrecise : DiagGroup<"thread-safety-precise">;
11561156
def ThreadSafetyReferenceReturn : DiagGroup<"thread-safety-reference-return">;
11571157
def ThreadSafetyReference : DiagGroup<"thread-safety-reference",
11581158
[ThreadSafetyReferenceReturn]>;
1159+
def ThreadSafetyPointer : DiagGroup<"thread-safety-pointer">;
11591160
def ThreadSafetyNegative : DiagGroup<"thread-safety-negative">;
11601161
def ThreadSafety : DiagGroup<"thread-safety",
11611162
[ThreadSafetyAttributes,

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,8 @@ def warn_mmap_redundant_export_as : Warning<
917917
InGroup<PrivateModule>;
918918
def err_mmap_submodule_export_as : Error<
919919
"only top-level modules can be re-exported as public">;
920+
def err_mmap_qualified_export_as : Error<
921+
"a module can only be re-exported as another top-level module">;
920922

921923
def warn_quoted_include_in_framework_header : Warning<
922924
"double-quoted include \"%0\" in framework header, "

0 commit comments

Comments
 (0)