Skip to content

Commit

Permalink
Manually merged master:ada1e2ffa117 into amd-gfx:4baa63b509c7
Browse files Browse the repository at this point in the history
Local branch amd-gfx 4baa63b Merged master:8e712807e484 into amd-gfx:3bd64024f646
Remote branch master ada1e2f [lldb/examples] Add missing declaration in heap.py
  • Loading branch information
Flakebi committed Sep 25, 2020
2 parents 698ee93 + ada1e2f commit 3c5f340
Show file tree
Hide file tree
Showing 47 changed files with 1,651 additions and 442 deletions.
9 changes: 9 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,15 @@ def SwiftName : InheritableAttr {
let Documentation = [SwiftNameDocs];
}

def SwiftNewType : InheritableAttr {
let Spellings = [GNU<"swift_newtype">, GNU<"swift_wrapper">];
let Args = [EnumArgument<"NewtypeKind", "NewtypeKind",
["struct", "enum"], ["NK_Struct", "NK_Enum"]>];
let Subjects = SubjectList<[TypedefName], ErrorDiag>;
let Documentation = [SwiftNewTypeDocs];
let HasCustomParsing = 1;
}

def NoDeref : TypeAttr {
let Spellings = [Clang<"noderef">];
let Documentation = [NoDerefDocs];
Expand Down
30 changes: 30 additions & 0 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -3622,6 +3622,36 @@ must be a simple or qualified identifier.
}];
}

def SwiftNewTypeDocs : Documentation {
let Category = SwiftDocs;
let Heading = "swift_newtype";
let Content = [{
The ``swift_newtype`` attribute indicates that the typedef to which the
attribute appertains is imported as a new Swift type of the typedef's name.
Previously, the attribute was spelt ``swift_wrapper``. While the behaviour of
the attribute is identical with either spelling, ``swift_wrapper`` is
deprecated, only exists for compatibility purposes, and should not be used in
new code.

* ``swift_newtype(struct)`` means that a Swift struct will be created for this
typedef.

* ``swift_newtype(enum)`` means that a Swift enum will be created for this
ypedef.

.. code-block:: c

// Import UIFontTextStyle as an enum type, with enumerated values being
// constants.
typedef NSString * UIFontTextStyle __attribute__((__swift_newtype__(enum)));

// Import UIFontDescriptorFeatureKey as a structure type, with enumerated
// values being members of the type structure.
typedef NSString * UIFontDescriptorFeatureKey __attribute__((__swift_newtype__(struct)));

}];
}

def OMPDeclareSimdDocs : Documentation {
let Category = DocCatFunction;
let Heading = "#pragma omp declare simd";
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2804,6 +2804,14 @@ class Parser : public CodeCompletionHandler {
SourceLocation ScopeLoc,
ParsedAttr::Syntax Syntax);

void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
SourceLocation AttrNameLoc,
ParsedAttributes &Attrs,
SourceLocation *EndLoc,
IdentifierInfo *ScopeName,
SourceLocation ScopeLoc,
ParsedAttr::Syntax Syntax);

void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
SourceLocation AttrNameLoc,
ParsedAttributes &Attrs,
Expand Down
100 changes: 92 additions & 8 deletions clang/lib/Basic/DiagnosticIDs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,78 @@ using namespace clang;

namespace {

struct StaticDiagInfoRec;

// Store the descriptions in a separate table to avoid pointers that need to
// be relocated, and also decrease the amount of data needed on 64-bit
// platforms. See "How To Write Shared Libraries" by Ulrich Drepper.
struct StaticDiagInfoDescriptionStringTable {
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
char ENUM##_desc[sizeof(DESC)];
// clang-format off
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
#include "clang/Basic/DiagnosticSerializationKinds.inc"
#include "clang/Basic/DiagnosticLexKinds.inc"
#include "clang/Basic/DiagnosticParseKinds.inc"
#include "clang/Basic/DiagnosticASTKinds.inc"
#include "clang/Basic/DiagnosticCommentKinds.inc"
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
#include "clang/Basic/DiagnosticSemaKinds.inc"
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
// clang-format on
#undef DIAG
};

const StaticDiagInfoDescriptionStringTable StaticDiagInfoDescriptions = {
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
DESC,
// clang-format off
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
#include "clang/Basic/DiagnosticSerializationKinds.inc"
#include "clang/Basic/DiagnosticLexKinds.inc"
#include "clang/Basic/DiagnosticParseKinds.inc"
#include "clang/Basic/DiagnosticASTKinds.inc"
#include "clang/Basic/DiagnosticCommentKinds.inc"
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
#include "clang/Basic/DiagnosticSemaKinds.inc"
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
// clang-format on
#undef DIAG
};

extern const StaticDiagInfoRec StaticDiagInfo[];

// Stored separately from StaticDiagInfoRec to pack better. Otherwise,
// StaticDiagInfoRec would have extra padding on 64-bit platforms.
const uint32_t StaticDiagInfoDescriptionOffsets[] = {
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
offsetof(StaticDiagInfoDescriptionStringTable, ENUM##_desc),
// clang-format off
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
#include "clang/Basic/DiagnosticSerializationKinds.inc"
#include "clang/Basic/DiagnosticLexKinds.inc"
#include "clang/Basic/DiagnosticParseKinds.inc"
#include "clang/Basic/DiagnosticASTKinds.inc"
#include "clang/Basic/DiagnosticCommentKinds.inc"
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
#include "clang/Basic/DiagnosticSemaKinds.inc"
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
// clang-format on
#undef DIAG
};

// Diagnostic classes.
enum {
CLASS_NOTE = 0x01,
Expand All @@ -48,14 +120,16 @@ struct StaticDiagInfoRec {
uint16_t OptionGroupIndex;

uint16_t DescriptionLen;
const char *DescriptionStr;

unsigned getOptionGroupIndex() const {
return OptionGroupIndex;
}

StringRef getDescription() const {
return StringRef(DescriptionStr, DescriptionLen);
size_t MyIndex = this - &StaticDiagInfo[0];
uint32_t StringOffset = StaticDiagInfoDescriptionOffsets[MyIndex];
const char* Table = reinterpret_cast<const char*>(&StaticDiagInfoDescriptions);
return StringRef(&Table[StringOffset], DescriptionLen);
}

diag::Flavor getFlavor() const {
Expand Down Expand Up @@ -93,14 +167,21 @@ VALIDATE_DIAG_SIZE(REFACTORING)
#undef VALIDATE_DIAG_SIZE
#undef STRINGIFY_NAME

} // namespace anonymous

static const StaticDiagInfoRec StaticDiagInfo[] = {
const StaticDiagInfoRec StaticDiagInfo[] = {
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
{diag::ENUM, DEFAULT_SEVERITY, CLASS, DiagnosticIDs::SFINAE, \
NOWERROR, SHOWINSYSHEADER, DEFERRABLE, CATEGORY, \
GROUP, STR_SIZE(DESC, uint16_t), DESC},
{ \
diag::ENUM, \
DEFAULT_SEVERITY, \
CLASS, \
DiagnosticIDs::SFINAE, \
NOWERROR, \
SHOWINSYSHEADER, \
DEFERRABLE, \
CATEGORY, \
GROUP, \
STR_SIZE(DESC, uint16_t)},
// clang-format off
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
Expand All @@ -113,9 +194,12 @@ static const StaticDiagInfoRec StaticDiagInfo[] = {
#include "clang/Basic/DiagnosticSemaKinds.inc"
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
// clang-format on
#undef DIAG
};

} // namespace

static const unsigned StaticDiagInfoSize = llvm::array_lengthof(StaticDiagInfo);

/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
Expand Down
52 changes: 52 additions & 0 deletions clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "clang/Sema/Lookup.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallString.h"
Expand Down Expand Up @@ -452,6 +453,10 @@ void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
ScopeName, ScopeLoc, Syntax);
return;
} else if (AttrKind == ParsedAttr::AT_SwiftNewType) {
ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
ScopeLoc, Syntax);
return;
} else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) {
ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
ScopeName, ScopeLoc, Syntax);
Expand Down Expand Up @@ -506,6 +511,10 @@ unsigned Parser::ParseClangAttributeArgs(
ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
ScopeName, ScopeLoc, Syntax);
break;
case ParsedAttr::AT_SwiftNewType:
ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
ScopeLoc, Syntax);
break;
case ParsedAttr::AT_TypeTagForDatatype:
ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
ScopeName, ScopeLoc, Syntax);
Expand Down Expand Up @@ -1409,6 +1418,49 @@ void Parser::ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
Syntax);
}


void Parser::ParseSwiftNewTypeAttribute(
IdentifierInfo &AttrName, SourceLocation AttrNameLoc,
ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName,
SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) {
BalancedDelimiterTracker T(*this, tok::l_paren);

// Opening '('
if (T.consumeOpen()) {
Diag(Tok, diag::err_expected) << tok::l_paren;
return;
}

if (Tok.is(tok::r_paren)) {
Diag(Tok.getLocation(), diag::err_argument_required_after_attribute);
T.consumeClose();
return;
}
if (Tok.isNot(tok::kw_struct) && Tok.isNot(tok::kw_enum)) {
Diag(Tok, diag::warn_attribute_type_not_supported)
<< &AttrName << Tok.getIdentifierInfo();
if (!isTokenSpecial())
ConsumeToken();
T.consumeClose();
return;
}

auto *SwiftType = IdentifierLoc::create(Actions.Context, Tok.getLocation(),
Tok.getIdentifierInfo());
ConsumeToken();

// Closing ')'
if (T.consumeClose())
return;
if (EndLoc)
*EndLoc = T.getCloseLocation();

ArgsUnion Args[] = {SwiftType};
Attrs.addNew(&AttrName, SourceRange(AttrNameLoc, T.getCloseLocation()),
ScopeName, ScopeLoc, Args, llvm::array_lengthof(Args), Syntax);
}


void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
SourceLocation AttrNameLoc,
ParsedAttributes &Attrs,
Expand Down
30 changes: 30 additions & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5946,6 +5946,33 @@ static void handleSwiftName(Sema &S, Decl *D, const ParsedAttr &AL) {
D->addAttr(::new (S.Context) SwiftNameAttr(S.Context, AL, Name));
}

static void handleSwiftNewType(Sema &S, Decl *D, const ParsedAttr &AL) {
// Make sure that there is an identifier as the annotation's single argument.
if (!checkAttributeNumArgs(S, AL, 1))
return;

if (!AL.isArgIdent(0)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
<< AL << AANT_ArgumentIdentifier;
return;
}

SwiftNewTypeAttr::NewtypeKind Kind;
IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
if (!SwiftNewTypeAttr::ConvertStrToNewtypeKind(II->getName(), Kind)) {
S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
return;
}

if (!isa<TypedefNameDecl>(D)) {
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type_str)
<< AL << "typedefs";
return;
}

D->addAttr(::new (S.Context) SwiftNewTypeAttr(S.Context, AL, Kind));
}

//===----------------------------------------------------------------------===//
// Microsoft specific attribute handlers.
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -7871,6 +7898,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
case ParsedAttr::AT_SwiftName:
handleSwiftName(S, D, AL);
break;
case ParsedAttr::AT_SwiftNewType:
handleSwiftNewType(S, D, AL);
break;
case ParsedAttr::AT_SwiftObjCMembers:
handleSimpleAttribute<SwiftObjCMembersAttr>(S, D, AL);
break;
Expand Down
19 changes: 19 additions & 0 deletions clang/test/AST/attr-swift_newtype.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %clang_cc1 -ast-dump %s | FileCheck %s

typedef int T1 __attribute__((__swift_newtype__(struct)));
typedef int T2 __attribute__((__swift_newtype__(enum)));

typedef int T3 __attribute__((__swift_wrapper__(struct)));
typedef int T4 __attribute__((__swift_wrapper__(enum)));

typedef int T5;
typedef int T5 __attribute__((__swift_wrapper__(struct)));
typedef int T5;
// CHECK-LABEL: TypedefDecl {{.+}} T5 'int'
// CHECK-NEXT: BuiltinType {{.+}} 'int'
// CHECK-NEXT: TypedefDecl {{.+}} T5 'int'
// CHECK-NEXT: BuiltinType {{.+}} 'int'
// CHECK-NEXT: SwiftNewTypeAttr {{.+}} NK_Struct
// CHECK-NEXT: TypedefDecl {{.+}} T5 'int'
// CHECK-NEXT: BuiltinType {{.+}} 'int'
// CHECK-NEXT: SwiftNewTypeAttr {{.+}} NK_Struct
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
// CHECK-NEXT: SwiftError (SubjectMatchRule_function, SubjectMatchRule_objc_method)
// CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: SwiftIndirectResult (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: SwiftNewType (SubjectMatchRule_type_alias)
// CHECK-NEXT: SwiftObjCMembers (SubjectMatchRule_objc_interface)
// CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
// CHECK-NEXT: Target (SubjectMatchRule_function)
Expand Down
13 changes: 13 additions & 0 deletions clang/test/SemaObjC/attr-swift_newtype.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s

typedef int Bad1 __attribute__((swift_newtype(invalid)));
// expected-warning@-1 {{'swift_newtype' attribute argument not supported: 'invalid'}}
typedef int Bad2 __attribute__((swift_newtype()));
// expected-error@-1 {{argument required after attribute}}
typedef int Bad3 __attribute__((swift_newtype(invalid, ignored)));
// expected-error@-1 {{expected ')'}}
// expected-note@-2 {{to match this '('}}
// expected-warning@-3 {{'swift_newtype' attribute argument not supported: 'invalid'}}

struct __attribute__((__swift_newtype__(struct))) Bad4 {};
// expected-error@-1 {{'__swift_newtype__' attribute only applies to typedefs}}
1 change: 1 addition & 0 deletions lldb/examples/darwin/heap_find/heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def get_iterate_memory_expr(
void *reserved1[12];
struct malloc_introspection_t *introspect;
} malloc_zone_t;
kern_return_t malloc_get_all_zones(task_t task, memory_reader_t reader, vm_address_t **addresses, unsigned *count);
memory_reader_t task_peek = [](task_t task, vm_address_t remote_address, vm_size_t size, void **local_memory) -> kern_return_t {
*local_memory = (void*) remote_address;
return KERN_SUCCESS;
Expand Down
Loading

0 comments on commit 3c5f340

Please sign in to comment.