Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit ad7fb41

Browse files
committed
Merge remote-tracking branch 'origin/swift-5.0-branch' into stable
2 parents 93a3928 + 051fdef commit ad7fb41

File tree

138 files changed

+11242
-3268
lines changed

Some content is hidden

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

138 files changed

+11242
-3268
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ cscope.out
2828
#==============================================================================#
2929
# Directories to ignore (do not add trailing '/'s, they skip symlinks).
3030
#==============================================================================#
31-
# Clang extra user tools, which is tracked independently (clang-tools-extra).
32-
tools/extra
3331
# Sphinx build products
3432
docs/_build
3533
docs/analyzer/_build

include/clang/AST/DeclCXX.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,9 @@ class CXXCtorInitializer final {
23122312
CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
23132313
SourceLocation L, Expr *Init, SourceLocation R);
23142314

2315+
/// \return Unique reproducible object identifier.
2316+
int64_t getID(const ASTContext &Context) const;
2317+
23152318
/// Determine whether this initializer is initializing a base class.
23162319
bool isBaseInitializer() const {
23172320
return Initializee.is<TypeSourceInfo*>() && !IsDelegating;

include/clang/Basic/Attr.td

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ def ObjCClassMethod : SubsetSubject<ObjCMethod,
9494
[{!S->isInstanceMethod()}],
9595
"Objective-C class methods">;
9696

97+
def NonStaticCXXMethod : SubsetSubject<CXXMethod,
98+
[{!S->isStatic()}],
99+
"non-static member functions">;
100+
101+
def NonStaticNonConstCXXMethod
102+
: SubsetSubject<CXXMethod,
103+
[{!S->isStatic() && !S->isConst()}],
104+
"non-static non-const member functions">;
105+
97106
def ObjCInstanceMethod : SubsetSubject<ObjCMethod,
98107
[{S->isInstanceMethod()}],
99108
"Objective-C instance methods">;
@@ -816,19 +825,44 @@ def CFUnknownTransfer : InheritableAttr {
816825
def CFReturnsRetained : InheritableAttr {
817826
let Spellings = [Clang<"cf_returns_retained">];
818827
// let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
819-
let Documentation = [Undocumented];
828+
let Documentation = [RetainBehaviorDocs];
820829
}
821830

822831
def CFReturnsNotRetained : InheritableAttr {
823832
let Spellings = [Clang<"cf_returns_not_retained">];
824833
// let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
825-
let Documentation = [Undocumented];
834+
let Documentation = [RetainBehaviorDocs];
826835
}
827836

828837
def CFConsumed : InheritableParamAttr {
829838
let Spellings = [Clang<"cf_consumed">];
830839
let Subjects = SubjectList<[ParmVar]>;
831-
let Documentation = [Undocumented];
840+
let Documentation = [RetainBehaviorDocs];
841+
}
842+
843+
// OSObject-based attributes.
844+
def OSConsumed : InheritableParamAttr {
845+
let Spellings = [Clang<"os_consumed">];
846+
let Subjects = SubjectList<[ParmVar]>;
847+
let Documentation = [RetainBehaviorDocs];
848+
}
849+
850+
def OSReturnsRetained : InheritableAttr {
851+
let Spellings = [Clang<"os_returns_retained">];
852+
let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
853+
let Documentation = [RetainBehaviorDocs];
854+
}
855+
856+
def OSReturnsNotRetained : InheritableAttr {
857+
let Spellings = [Clang<"os_returns_not_retained">];
858+
let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
859+
let Documentation = [RetainBehaviorDocs];
860+
}
861+
862+
def OSConsumesThis : InheritableAttr {
863+
let Spellings = [Clang<"os_consumes_this">];
864+
let Subjects = SubjectList<[NonStaticCXXMethod]>;
865+
let Documentation = [RetainBehaviorDocs];
832866
}
833867

834868
def Cleanup : InheritableAttr {
@@ -1605,31 +1639,31 @@ def NSErrorDomain : Attr {
16051639
def NSReturnsRetained : InheritableAttr {
16061640
let Spellings = [Clang<"ns_returns_retained">];
16071641
// let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1608-
let Documentation = [Undocumented];
1642+
let Documentation = [RetainBehaviorDocs];
16091643
}
16101644

16111645
def NSReturnsNotRetained : InheritableAttr {
16121646
let Spellings = [Clang<"ns_returns_not_retained">];
16131647
// let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1614-
let Documentation = [Undocumented];
1648+
let Documentation = [RetainBehaviorDocs];
16151649
}
16161650

16171651
def NSReturnsAutoreleased : InheritableAttr {
16181652
let Spellings = [Clang<"ns_returns_autoreleased">];
16191653
// let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1620-
let Documentation = [Undocumented];
1654+
let Documentation = [RetainBehaviorDocs];
16211655
}
16221656

16231657
def NSConsumesSelf : InheritableAttr {
16241658
let Spellings = [Clang<"ns_consumes_self">];
16251659
let Subjects = SubjectList<[ObjCMethod]>;
1626-
let Documentation = [Undocumented];
1660+
let Documentation = [RetainBehaviorDocs];
16271661
}
16281662

16291663
def NSConsumed : InheritableParamAttr {
16301664
let Spellings = [Clang<"ns_consumed">];
16311665
let Subjects = SubjectList<[ParmVar]>;
1632-
let Documentation = [Undocumented];
1666+
let Documentation = [RetainBehaviorDocs];
16331667
}
16341668

16351669
def ObjCException : InheritableAttr {
@@ -3107,3 +3141,9 @@ def AlwaysDestroy : InheritableAttr {
31073141
let Subjects = SubjectList<[Var]>;
31083142
let Documentation = [AlwaysDestroyDocs];
31093143
}
3144+
3145+
def Reinitializes : InheritableAttr {
3146+
let Spellings = [Clang<"reinitializes", 0>];
3147+
let Subjects = SubjectList<[NonStaticNonConstCXXMethod], ErrorDiag>;
3148+
let Documentation = [ReinitializesDocs];
3149+
}

include/clang/Basic/AttrDocs.td

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,58 @@ Query for this feature with ``__has_attribute(objc_method_family)``.
843843
}];
844844
}
845845

846+
def RetainBehaviorDocs : Documentation {
847+
let Category = DocCatFunction;
848+
let Content = [{
849+
The behavior of a function with respect to reference counting for Foundation
850+
(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming
851+
convention (e.g. functions starting with "get" are assumed to return at
852+
``+0``).
853+
854+
It can be overriden using a family of the following attributes. In
855+
Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to
856+
a function communicates that the object is returned at ``+1``, and the caller
857+
is responsible for freeing it.
858+
Similiarly, the annotation ``__attribute__((ns_returns_not_retained))``
859+
specifies that the object is returned at ``+0`` and the ownership remains with
860+
the callee.
861+
The annotation ``__attribute__((ns_consumes_self))`` specifies that
862+
the Objective-C method call consumes the reference to ``self``, e.g. by
863+
attaching it to a supplied parameter.
864+
Additionally, parameters can have an annotation
865+
``__attribute__((ns_consumed))``, which specifies that passing an owned object
866+
as that parameter effectively transfers the ownership, and the caller is no
867+
longer responsible for it.
868+
These attributes affect code generation when interacting with ARC code, and
869+
they are used by the Clang Static Analyzer.
870+
871+
In C programs using CoreFoundation, a similar set of attributes:
872+
``__attribute__((cf_returns_not_retained))``,
873+
``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))``
874+
have the same respective semantics when applied to CoreFoundation objects.
875+
These attributes affect code generation when interacting with ARC code, and
876+
they are used by the Clang Static Analyzer.
877+
878+
Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject),
879+
the same attribute family is present:
880+
``__attribute__((os_returns_not_retained))``,
881+
``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``,
882+
with the same respective semantics.
883+
Similar to ``__attribute__((ns_consumes_self))``,
884+
``__attribute__((os_consumes_this))`` specifies that the method call consumes
885+
the reference to "this" (e.g., when attaching it to a different object supplied
886+
as a parameter).
887+
These attributes are only used by the Clang Static Analyzer.
888+
889+
The family of attributes ``X_returns_X_retained`` can be added to functions,
890+
C++ methods, and Objective-C methods and properties.
891+
Attributes ``X_consumed`` can be added to parameters of methods, functions,
892+
and Objective-C methods.
893+
}];
894+
}
895+
896+
897+
846898
def NoDebugDocs : Documentation {
847899
let Category = DocCatVariable;
848900
let Content = [{
@@ -3605,3 +3657,32 @@ static and thread duration variable with this attribute is equivalent to
36053657
invoking clang with -fno-c++-static-destructors.
36063658
}];
36073659
}
3660+
3661+
3662+
def ReinitializesDocs : Documentation {
3663+
let Category = DocCatFunction;
3664+
let Content = [{
3665+
The ``reinitializes`` attribute can be applied to a non-static, non-const C++
3666+
member function to indicate that this member function reinitializes the entire
3667+
object to a known state, independent of the previous state of the object.
3668+
3669+
This attribute can be interpreted by static analyzers that warn about uses of an
3670+
object that has been left in an indeterminate state by a move operation. If a
3671+
member function marked with the ``reinitializes`` attribute is called on a
3672+
moved-from object, the analyzer can conclude that the object is no longer in an
3673+
indeterminate state.
3674+
3675+
A typical example where this attribute would be used is on functions that clear
3676+
a container class:
3677+
3678+
.. code-block:: c++
3679+
3680+
template <class T>
3681+
class Container {
3682+
public:
3683+
...
3684+
[[clang::reinitializes]] void Clear();
3685+
...
3686+
};
3687+
}];
3688+
}

include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ def err_analyzer_config_no_value : Error<
295295
"analyzer-config option '%0' has a key but no value">;
296296
def err_analyzer_config_multiple_values : Error<
297297
"analyzer-config option '%0' should contain only one '='">;
298+
def err_analyzer_config_invalid_input : Error<
299+
"invalid input for analyzer-config option '%0', that expects %1 value">;
300+
def err_analyzer_config_unknown : Error<"unknown analyzer-config '%0'">;
298301

299302
def err_drv_invalid_hvx_length : Error<
300303
"-mhvx-length is not supported without a -mhvx/-mhvx= flag">;

include/clang/Driver/CC1Options.td

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ def analyzer_checker : Separate<["-"], "analyzer-checker">,
106106
ValuesCode<[{
107107
const char *Values =
108108
#define GET_CHECKERS
109-
#define CHECKER(FULLNAME, CLASS, DESCFILE, HT, G, H) FULLNAME ","
109+
#define CHECKER(FULLNAME, CLASS, HT) FULLNAME ","
110110
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
111111
#undef GET_CHECKERS
112112
#define GET_PACKAGES
113-
#define PACKAGE(FULLNAME, G, D) FULLNAME ","
113+
#define PACKAGE(FULLNAME) FULLNAME ","
114114
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
115115
#undef GET_PACKAGES
116116
;
@@ -129,12 +129,21 @@ def analyzer_disable_all_checks : Flag<["-"], "analyzer-disable-all-checks">,
129129
def analyzer_checker_help : Flag<["-"], "analyzer-checker-help">,
130130
HelpText<"Display the list of analyzer checkers that are available">;
131131

132+
def analyzer_config_help : Flag<["-"], "analyzer-config-help">,
133+
HelpText<"Display the list of -analyzer-config options">;
134+
132135
def analyzer_list_enabled_checkers : Flag<["-"], "analyzer-list-enabled-checkers">,
133136
HelpText<"Display the list of enabled analyzer checkers">;
134137

135138
def analyzer_config : Separate<["-"], "analyzer-config">,
136139
HelpText<"Choose analyzer options to enable">;
137140

141+
def analyzer_config_compatibility_mode : Separate<["-"], "analyzer-config-compatibility-mode">,
142+
HelpText<"Don't emit errors on invalid analyzer-config inputs">;
143+
144+
def analyzer_config_compatibility_mode_EQ : Joined<["-"], "analyzer-config-compatibility-mode=">,
145+
Alias<analyzer_config_compatibility_mode>;
146+
138147
//===----------------------------------------------------------------------===//
139148
// Migrator Options
140149
//===----------------------------------------------------------------------===//

include/clang/Lex/MacroInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ class MacroDirective {
395395

396396
/// Find macro definition active in the specified source location. If
397397
/// this macro was not defined there, return NULL.
398-
const DefInfo findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const;
398+
const DefInfo findDirectiveAtLoc(SourceLocation L,
399+
const SourceManager &SM) const;
399400

400401
void dump() const;
401402

include/clang/Sema/Sema.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8585,9 +8585,9 @@ class Sema {
85858585
void AddParameterABIAttr(SourceRange AttrRange, Decl *D,
85868586
ParameterABI ABI, unsigned SpellingListIndex);
85878587

8588-
void AddNSConsumedAttr(SourceRange AttrRange, Decl *D,
8589-
unsigned SpellingListIndex, bool isNSConsumed,
8590-
bool isTemplateInstantiation);
8588+
enum class RetainOwnershipKind {NS, CF, OS};
8589+
void AddXConsumedAttr(Decl *D, SourceRange SR, unsigned SpellingIndex,
8590+
RetainOwnershipKind K, bool IsTemplateInstantiation);
85918591

85928592
bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type);
85938593

include/clang/StaticAnalyzer/Checkers/CheckerBase.td

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,34 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
class CheckerGroup<string name> {
15-
string GroupName = name;
16-
}
17-
class InGroup<CheckerGroup G> { CheckerGroup Group = G; }
18-
14+
/// Describes a package. Every checker is a part of a package, for example,
15+
/// 'NullDereference' is part of the 'core' package, hence it's full name is
16+
/// 'core.NullDereference'.
17+
/// Example:
18+
/// def Core : Package<"core">;
1919
class Package<string name> {
2020
string PackageName = name;
21-
bit Hidden = 0;
2221
Package ParentPackage;
23-
CheckerGroup Group;
2422
}
25-
class InPackage<Package P> { Package ParentPackage = P; }
2623

27-
// All checkers are an indirect subclass of this.
24+
/// Describes a 'super' package that holds another package inside it. This is
25+
/// used to nest packages in one another. One may, for example, create the
26+
/// 'builtin' package inside 'core', thus creating the package 'core.builtin'.
27+
/// Example:
28+
/// def CoreBuiltin : Package<"builtin">, ParentPackage<Core>;
29+
class ParentPackage<Package P> { Package ParentPackage = P; }
30+
31+
/// A description. May be displayed to the user when clang is invoked with
32+
/// a '-help'-like command line option.
33+
class HelpText<string text> { string HelpText = text; }
34+
35+
/// Describes a checker. Every builtin checker has to be registered with the use
36+
/// of this class (out-of-trunk checkers loaded from plugins obviously don't).
37+
/// Note that a checker has a name (e.g.: 'NullDereference'), and a fullname,
38+
/// that is autogenerated with the help of the ParentPackage field, that also
39+
/// includes package names (e.g.: 'core.NullDereference').
2840
class Checker<string name = ""> {
2941
string CheckerName = name;
30-
string DescFile;
3142
string HelpText;
32-
bit Hidden = 0;
3343
Package ParentPackage;
34-
CheckerGroup Group;
3544
}
36-
37-
class DescFile<string filename> { string DescFile = filename; }
38-
class HelpText<string text> { string HelpText = text; }
39-
class Hidden { bit Hidden = 1; }

0 commit comments

Comments
 (0)