Skip to content

Commit 1a42fca

Browse files
Merge from 'main' to 'sycl-web' (19 commits)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaDeclAttr.cpp CONFLICT (content): Merge conflict in clang/lib/Sema/ParsedAttr.cpp CONFLICT (content): Merge conflict in clang/include/clang/Basic/DiagnosticSemaKinds.td
2 parents 006f67b + 8c7b64b commit 1a42fca

File tree

87 files changed

+2516
-691
lines changed

Some content is hidden

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

87 files changed

+2516
-691
lines changed

clang-tools-extra/clangd/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct Config {
129129
/// Configures hover feature.
130130
struct {
131131
/// Whether hover show a.k.a type.
132-
bool ShowAKA = false;
132+
bool ShowAKA = true;
133133
} Hover;
134134

135135
struct {

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8143,7 +8143,7 @@ For example:
81438143
The attribute does not have any effect on the semantics of the type system,
81448144
neither type checking rules, nor runtime semantics. In particular:
81458145

8146-
- ``std::is_same<T, T [[clang::annotate_type("foo")]]`` is true for all types
8146+
- ``std::is_same<T, T [[clang::annotate_type("foo")]]>`` is true for all types
81478147
``T``.
81488148

81498149
- It is not permissible for overloaded functions or template specializations

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ class AttributeCommonInfo {
150150

151151
bool isAlignasAttribute() const {
152152
// FIXME: Use a better mechanism to determine this.
153+
// We use this in `isCXX11Attribute` below, so it _should_ only return
154+
// true for the `alignas` spelling, but it currently also returns true
155+
// for the `_Alignas` spelling, which only exists in C11. Distinguishing
156+
// between the two is important because they behave differently:
157+
// - `alignas` may only appear in the attribute-specifier-seq before
158+
// the decl-specifier-seq and is therefore associated with the
159+
// declaration.
160+
// - `_Alignas` may appear anywhere within the declaration-specifiers
161+
// and is therefore associated with the `DeclSpec`.
162+
// It's not clear how best to fix this:
163+
// - We have the necessary information in the form of the `SpellingIndex`,
164+
// but we would need to compare against AlignedAttr::Keyword_alignas,
165+
// and we can't depend on clang/AST/Attr.h here.
166+
// - We could test `getAttrName()->getName() == "alignas"`, but this is
167+
// inefficient.
153168
return getParsedKind() == AT_Aligned && isKeywordAttribute();
154169
}
155170

clang/include/clang/Basic/DiagnosticCommonKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ def err_opencl_unknown_type_specifier : Error<
163163

164164
def warn_unknown_attribute_ignored : Warning<
165165
"unknown attribute %0 ignored">, InGroup<UnknownAttributes>;
166+
def warn_attribute_ignored : Warning<"%0 attribute ignored">,
167+
InGroup<IgnoredAttributes>;
166168
def err_use_of_tag_name_without_tag : Error<
167169
"must use '%1' tag to refer to type %0%select{| in this scope}2">;
168170

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ def warn_pragma_expected_colon : Warning<
12781278
def warn_pragma_expected_predicate : Warning<
12791279
"expected %select{'enable', 'disable', 'begin' or 'end'|'disable'}0 - ignoring">, InGroup<IgnoredPragmas>;
12801280
def warn_pragma_unknown_extension : Warning<
1281-
"unknown OpenCL extension %0 - ignoring">, InGroup<IgnoredPragmas>;
1281+
"OpenCL extension %0 unknown or does not require pragma - ignoring">, InGroup<IgnoredPragmas>;
12821282
def warn_pragma_unsupported_extension : Warning<
12831283
"unsupported OpenCL extension %0 - ignoring">, InGroup<IgnoredPragmas>;
12841284
def warn_pragma_extension_is_core : Warning<

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,8 +3397,6 @@ def warn_redeclaration_without_import_attribute : Warning<
33973397
def warn_dllimport_dropped_from_inline_function : Warning<
33983398
"%q0 redeclared inline; %1 attribute ignored">,
33993399
InGroup<IgnoredAttributes>;
3400-
def warn_attribute_ignored : Warning<"%0 attribute ignored">,
3401-
InGroup<IgnoredAttributes>;
34023400
def warn_attribute_on_direct_kernel_callee_only : Warning<"%0 attribute allowed"
34033401
" only on a function directly called from a SYCL kernel function; attribute ignored">,
34043402
InGroup<IgnoredAttributes>;
@@ -3438,8 +3436,11 @@ def note_attribute_has_no_effect_on_compile_time_if_here : Note<
34383436
"annotating the 'if %select{constexpr|consteval}0' statement here">;
34393437
def err_decl_attribute_invalid_on_stmt : Error<
34403438
"%0 attribute cannot be applied to a statement">;
3441-
def err_stmt_attribute_invalid_on_decl : Error<
3439+
def err_attribute_invalid_on_decl : Error<
34423440
"%0 attribute cannot be applied to a declaration">;
3441+
def warn_type_attribute_deprecated_on_decl : Warning<
3442+
"applying attribute %0 to a declaration is deprecated; apply it to the type instead">,
3443+
InGroup<DeprecatedAttributes>;
34433444
def warn_declspec_attribute_ignored : Warning<
34443445
"attribute %0 is ignored, place it after "
34453446
"\"%select{class|struct|interface|union|enum}1\" to apply attribute to "

clang/include/clang/Parse/Parser.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,8 @@ class Parser : public CodeCompletionHandler {
20762076
SourceLocation *TrailingElseLoc = nullptr);
20772077
StmtResult ParseStatementOrDeclarationAfterAttributes(
20782078
StmtVector &Stmts, ParsedStmtContext StmtCtx,
2079-
SourceLocation *TrailingElseLoc, ParsedAttributes &Attrs);
2079+
SourceLocation *TrailingElseLoc, ParsedAttributes &DeclAttrs,
2080+
ParsedAttributes &DeclSpecAttrs);
20802081
StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
20812082
StmtResult ParseLabeledStatement(ParsedAttributes &Attrs,
20822083
ParsedStmtContext StmtCtx);
@@ -2325,15 +2326,18 @@ class Parser : public CodeCompletionHandler {
23252326

23262327
DeclGroupPtrTy ParseDeclaration(DeclaratorContext Context,
23272328
SourceLocation &DeclEnd,
2328-
ParsedAttributes &Attrs,
2329+
ParsedAttributes &DeclAttrs,
2330+
ParsedAttributes &DeclSpecAttrs,
23292331
SourceLocation *DeclSpecStart = nullptr);
23302332
DeclGroupPtrTy
23312333
ParseSimpleDeclaration(DeclaratorContext Context, SourceLocation &DeclEnd,
2332-
ParsedAttributes &Attrs, bool RequireSemi,
2334+
ParsedAttributes &DeclAttrs,
2335+
ParsedAttributes &DeclSpecAttrs, bool RequireSemi,
23332336
ForRangeInit *FRI = nullptr,
23342337
SourceLocation *DeclSpecStart = nullptr);
23352338
bool MightBeDeclarator(DeclaratorContext Context);
23362339
DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, DeclaratorContext Context,
2340+
ParsedAttributes &Attrs,
23372341
SourceLocation *DeclEnd = nullptr,
23382342
ForRangeInit *FRI = nullptr);
23392343
Decl *ParseDeclarationAfterDeclarator(Declarator &D,

clang/include/clang/Parse/RAIIObjectsForParser.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,11 @@ namespace clang {
201201
ParsingDeclRAIIObject ParsingRAII;
202202

203203
public:
204-
ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, DeclaratorContext C)
205-
: Declarator(DS, C), ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {
206-
}
204+
ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS,
205+
const ParsedAttributes &DeclarationAttrs,
206+
DeclaratorContext C)
207+
: Declarator(DS, DeclarationAttrs, C),
208+
ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {}
207209

208210
const ParsingDeclSpec &getDeclSpec() const {
209211
return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec());
@@ -228,9 +230,10 @@ namespace clang {
228230
ParsingDeclRAIIObject ParsingRAII;
229231

230232
public:
231-
ParsingFieldDeclarator(Parser &P, const ParsingDeclSpec &DS)
232-
: FieldDeclarator(DS), ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {
233-
}
233+
ParsingFieldDeclarator(Parser &P, const ParsingDeclSpec &DS,
234+
const ParsedAttributes &DeclarationAttrs)
235+
: FieldDeclarator(DS, DeclarationAttrs),
236+
ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {}
234237

235238
const ParsingDeclSpec &getDeclSpec() const {
236239
return static_cast<const ParsingDeclSpec&>(D.getDeclSpec());

clang/include/clang/Sema/DeclSpec.h

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,9 +1852,13 @@ class Declarator {
18521852
/// Indicates whether this declarator has an initializer.
18531853
unsigned HasInitializer : 1;
18541854

1855-
/// Attrs - Attributes.
1855+
/// Attributes attached to the declarator.
18561856
ParsedAttributes Attrs;
18571857

1858+
/// Attributes attached to the declaration. See also documentation for the
1859+
/// corresponding constructor parameter.
1860+
const ParsedAttributesView &DeclarationAttrs;
1861+
18581862
/// The asm label, if specified.
18591863
Expr *AsmLabel;
18601864

@@ -1893,16 +1897,40 @@ class Declarator {
18931897
friend struct DeclaratorChunk;
18941898

18951899
public:
1896-
Declarator(const DeclSpec &ds, DeclaratorContext C)
1897-
: DS(ds), Range(ds.getSourceRange()), Context(C),
1900+
/// `DS` and `DeclarationAttrs` must outlive the `Declarator`. In particular,
1901+
/// take care not to pass temporary objects for these parameters.
1902+
///
1903+
/// `DeclarationAttrs` contains [[]] attributes from the
1904+
/// attribute-specifier-seq at the beginning of a declaration, which appertain
1905+
/// to the declared entity itself. Attributes with other syntax (e.g. GNU)
1906+
/// should not be placed in this attribute list; if they occur at the
1907+
/// beginning of a declaration, they apply to the `DeclSpec` and should be
1908+
/// attached to that instead.
1909+
///
1910+
/// Here is an example of an attribute associated with a declaration:
1911+
///
1912+
/// [[deprecated]] int x, y;
1913+
///
1914+
/// This attribute appertains to all of the entities declared in the
1915+
/// declaration, i.e. `x` and `y` in this case.
1916+
Declarator(const DeclSpec &DS, const ParsedAttributesView &DeclarationAttrs,
1917+
DeclaratorContext C)
1918+
: DS(DS), Range(DS.getSourceRange()), Context(C),
18981919
InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
18991920
GroupingParens(false), FunctionDefinition(static_cast<unsigned>(
19001921
FunctionDefinitionKind::Declaration)),
19011922
Redeclaration(false), Extension(false), ObjCIvar(false),
19021923
ObjCWeakProperty(false), InlineStorageUsed(false),
1903-
HasInitializer(false), Attrs(ds.getAttributePool().getFactory()),
1904-
AsmLabel(nullptr), TrailingRequiresClause(nullptr),
1905-
InventedTemplateParameterList(nullptr) {}
1924+
HasInitializer(false), Attrs(DS.getAttributePool().getFactory()),
1925+
DeclarationAttrs(DeclarationAttrs), AsmLabel(nullptr),
1926+
TrailingRequiresClause(nullptr),
1927+
InventedTemplateParameterList(nullptr) {
1928+
assert(llvm::all_of(DeclarationAttrs,
1929+
[](const ParsedAttr &AL) {
1930+
return AL.isStandardAttributeSyntax();
1931+
}) &&
1932+
"DeclarationAttrs may only contain [[]] attributes");
1933+
}
19061934

19071935
~Declarator() {
19081936
clear();
@@ -2531,9 +2559,14 @@ class Declarator {
25312559
const ParsedAttributes &getAttributes() const { return Attrs; }
25322560
ParsedAttributes &getAttributes() { return Attrs; }
25332561

2562+
const ParsedAttributesView &getDeclarationAttributes() const {
2563+
return DeclarationAttrs;
2564+
}
2565+
25342566
/// hasAttributes - do we contain any attributes?
25352567
bool hasAttributes() const {
2536-
if (!getAttributes().empty() || getDeclSpec().hasAttributes())
2568+
if (!getAttributes().empty() || !getDeclarationAttributes().empty() ||
2569+
getDeclSpec().hasAttributes())
25372570
return true;
25382571
for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
25392572
if (!getTypeObject(i).getAttrs().empty())
@@ -2615,8 +2648,10 @@ class Declarator {
26152648
struct FieldDeclarator {
26162649
Declarator D;
26172650
Expr *BitfieldSize;
2618-
explicit FieldDeclarator(const DeclSpec &DS)
2619-
: D(DS, DeclaratorContext::Member), BitfieldSize(nullptr) {}
2651+
explicit FieldDeclarator(const DeclSpec &DS,
2652+
const ParsedAttributes &DeclarationAttrs)
2653+
: D(DS, DeclarationAttrs, DeclaratorContext::Member),
2654+
BitfieldSize(nullptr) {}
26202655
};
26212656

26222657
/// Represents a C++11 virt-specifier-seq.

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,18 @@ class ParsedAttr final
658658
bool isSupportedByPragmaAttribute() const;
659659
bool supportsNonconformingLambdaSyntax() const;
660660

661+
/// Returns whether a [[]] attribute, if specified ahead of a declaration,
662+
/// should be applied to the decl-specifier-seq instead (i.e. whether it
663+
/// "slides" to the decl-specifier-seq).
664+
///
665+
/// By the standard, attributes specified before the declaration always
666+
/// appertain to the declaration, but historically we have allowed some of
667+
/// these attributes to slide to the decl-specifier-seq, so we need to keep
668+
/// supporting this behavior.
669+
///
670+
/// This may only be called if isStandardAttributeSyntax() returns true.
671+
bool slidesFromDeclToDeclSpecLegacyBehavior() const;
672+
661673
/// If the parsed attribute has a semantic equivalent, and it would
662674
/// have a semantic Spelling enumeration (due to having semantically-distinct
663675
/// spelling variations), return the value of that semantic spelling. If the
@@ -912,6 +924,12 @@ class ParsedAttributesView {
912924

913925
public:
914926
SourceRange Range;
927+
928+
static const ParsedAttributesView &none() {
929+
static const ParsedAttributesView Attrs;
930+
return Attrs;
931+
}
932+
915933
bool empty() const { return AttrList.empty(); }
916934
SizeType size() const { return AttrList.size(); }
917935
ParsedAttr &operator[](SizeType pos) { return *AttrList[pos]; }
@@ -1114,6 +1132,11 @@ class ParsedAttributes : public ParsedAttributesView {
11141132
mutable AttributePool pool;
11151133
};
11161134

1135+
/// Consumes the attributes from `First` and `Second` and concatenates them into
1136+
/// `Result`. Sets `Result.Range` to the combined range of `First` and `Second`.
1137+
void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &Second,
1138+
ParsedAttributes &Result);
1139+
11171140
/// These constants match the enumerated choices of
11181141
/// err_attribute_argument_n_type and err_attribute_argument_type.
11191142
enum AttributeArgumentNType {

0 commit comments

Comments
 (0)