Skip to content

Commit

Permalink
Merge branch 'amd-staging' of ssh://gerrit-git.amd.com:29418/lightnin…
Browse files Browse the repository at this point in the history
…g/ec/llvm-project into amd-staging
  • Loading branch information
searlmc1 committed Apr 29, 2024
2 parents 13f3f22 + dfa313d commit dc5c524
Show file tree
Hide file tree
Showing 260 changed files with 3,597 additions and 12,461 deletions.
1 change: 1 addition & 0 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,7 @@ Conditional ``explicit`` __cpp_conditional_explicit C+
``if consteval`` __cpp_if_consteval C++23 C++20
``static operator()`` __cpp_static_call_operator C++23 C++03
Attributes on Lambda-Expressions C++23 C++11
Attributes on Structured Bindings __cpp_structured_bindings C++26 C++03
``= delete ("should have a reason");`` __cpp_deleted_function C++26 C++03
-------------------------------------------- -------------------------------- ------------- -------------
Designated initializers (N494) C99 C89
Expand Down
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ C++2c Feature Support

- Implemented `P2573R2: = delete("should have a reason"); <https://wg21.link/P2573R2>`_

- Implemented `P0609R3: Attributes for Structured Bindings <https://wg21.link/P0609R3>`_


Resolutions to C++ Defect Reports
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -3211,7 +3211,7 @@ def ObjCRequiresPropertyDefs : InheritableAttr {
def Unused : InheritableAttr {
let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">,
C23<"", "maybe_unused", 202106>];
let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
let Subjects = SubjectList<[Var, Binding, ObjCIvar, Type, Enum, EnumConstant, Label,
Field, ObjCMethod, FunctionLike]>;
let Documentation = [WarnMaybeUnusedDocs];
}
Expand Down
9 changes: 9 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,15 @@ def ext_decomp_decl_empty : ExtWarn<
"ISO C++17 does not allow a decomposition group to be empty">,
InGroup<DiagGroup<"empty-decomposition">>;

// C++26 structured bindings
def ext_decl_attrs_on_binding : ExtWarn<
"an attribute specifier sequence attached to a structured binding declaration "
"is a C++2c extension">, InGroup<CXX26>;
def warn_cxx23_compat_decl_attrs_on_binding : Warning<
"an attribute specifier sequence attached to a structured binding declaration "
"is incompatible with C++ standards before C++2c">,
InGroup<CXXPre26Compat>, DefaultIgnore;

/// Objective-C parser diagnostics
def err_expected_minus_or_plus : Error<
"method type specifier must start with '-' or '+'">;
Expand Down
10 changes: 6 additions & 4 deletions clang/include/clang/Sema/DeclSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include <optional>

namespace clang {
class ASTContext;
Expand Down Expand Up @@ -1790,6 +1791,7 @@ class DecompositionDeclarator {
struct Binding {
IdentifierInfo *Name;
SourceLocation NameLoc;
std::optional<ParsedAttributes> Attrs;
};

private:
Expand Down Expand Up @@ -2339,10 +2341,10 @@ class Declarator {
}

/// Set the decomposition bindings for this declarator.
void
setDecompositionBindings(SourceLocation LSquareLoc,
ArrayRef<DecompositionDeclarator::Binding> Bindings,
SourceLocation RSquareLoc);
void setDecompositionBindings(
SourceLocation LSquareLoc,
MutableArrayRef<DecompositionDeclarator::Binding> Bindings,
SourceLocation RSquareLoc);

/// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
/// EndLoc, which should be the last token of the chunk.
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Sema/ParsedAttr.h
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ class ParsedAttributes : public ParsedAttributesView {
ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
ParsedAttributes(const ParsedAttributes &) = delete;
ParsedAttributes &operator=(const ParsedAttributes &) = delete;
ParsedAttributes(ParsedAttributes &&G) = default;

AttributePool &getPool() const { return pool; }

Expand Down
4 changes: 3 additions & 1 deletion clang/lib/AST/DeclBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@ int64_t Decl::getID() const {

const FunctionType *Decl::getFunctionType(bool BlocksToo) const {
QualType Ty;
if (const auto *D = dyn_cast<ValueDecl>(this))
if (const auto *D = dyn_cast<BindingDecl>(this))
return nullptr;
else if (const auto *D = dyn_cast<ValueDecl>(this))
Ty = D->getType();
else if (const auto *D = dyn_cast<TypedefNameDecl>(this))
Ty = D->getUnderlyingType();
Expand Down
8 changes: 6 additions & 2 deletions clang/lib/Format/FormatToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -1623,10 +1623,10 @@ struct AdditionalKeywords {
IdentifierInfo *kw_then;

/// Returns \c true if \p Tok is a keyword or an identifier.
bool isWordLike(const FormatToken &Tok) const {
bool isWordLike(const FormatToken &Tok, bool IsVerilog = true) const {
// getIdentifierinfo returns non-null for keywords as well as identifiers.
return Tok.Tok.getIdentifierInfo() &&
!Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
(!IsVerilog || !isVerilogKeywordSymbol(Tok));
}

/// Returns \c true if \p Tok is a true JavaScript identifier, returns
Expand Down Expand Up @@ -1755,6 +1755,10 @@ struct AdditionalKeywords {
}
}

bool isVerilogKeywordSymbol(const FormatToken &Tok) const {
return Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
}

bool isVerilogWordOperator(const FormatToken &Tok) const {
return Tok.isOneOf(kw_before, kw_intersect, kw_dist, kw_iff, kw_inside,
kw_with);
Expand Down
13 changes: 8 additions & 5 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4780,9 +4780,14 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if (Left.Finalized)
return Right.hasWhitespaceBefore();

const bool IsVerilog = Style.isVerilog();
assert(!IsVerilog || !IsCpp);

// Never ever merge two words.
if (Keywords.isWordLike(Right) && Keywords.isWordLike(Left))
if (Keywords.isWordLike(Right, IsVerilog) &&
Keywords.isWordLike(Left, IsVerilog)) {
return true;
}

// Leave a space between * and /* to avoid C4138 `comment end` found outside
// of comment.
Expand Down Expand Up @@ -5063,12 +5068,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
Right.is(TT_TemplateOpener)) {
return true;
}
} else if (Style.isVerilog()) {
} else if (IsVerilog) {
// An escaped identifier ends with whitespace.
if (Style.isVerilog() && Left.is(tok::identifier) &&
Left.TokenText[0] == '\\') {
if (Left.is(tok::identifier) && Left.TokenText[0] == '\\')
return true;
}
// Add space between things in a primitive's state table unless in a
// transition like `(0?)`.
if ((Left.is(TT_VerilogTableItem) &&
Expand Down
11 changes: 7 additions & 4 deletions clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void WhitespaceManager::calculateLineBreakInformation() {
for (unsigned I = 1, e = Changes.size(); I != e; ++I) {
auto &C = Changes[I];
auto &P = Changes[I - 1];
auto &PrevTokLength = P.TokenLength;
SourceLocation OriginalWhitespaceStart =
C.OriginalWhitespaceRange.getBegin();
SourceLocation PreviousOriginalWhitespaceEnd =
Expand Down Expand Up @@ -169,21 +170,23 @@ void WhitespaceManager::calculateLineBreakInformation() {
// line of the token.
auto NewlinePos = Text.find_first_of('\n');
if (NewlinePos == StringRef::npos) {
P.TokenLength = OriginalWhitespaceStartOffset -
PrevTokLength = OriginalWhitespaceStartOffset -
PreviousOriginalWhitespaceEndOffset +
C.PreviousLinePostfix.size() + P.CurrentLinePrefix.size();
if (!P.IsInsideToken)
PrevTokLength = std::min(PrevTokLength, P.Tok->ColumnWidth);
} else {
P.TokenLength = NewlinePos + P.CurrentLinePrefix.size();
PrevTokLength = NewlinePos + P.CurrentLinePrefix.size();
}

// If there are multiple changes in this token, sum up all the changes until
// the end of the line.
if (P.IsInsideToken && P.NewlinesBefore == 0)
LastOutsideTokenChange->TokenLength += P.TokenLength + P.Spaces;
LastOutsideTokenChange->TokenLength += PrevTokLength + P.Spaces;
else
LastOutsideTokenChange = &P;

C.PreviousEndOfTokenColumn = P.StartOfTokenColumn + P.TokenLength;
C.PreviousEndOfTokenColumn = P.StartOfTokenColumn + PrevTokLength;

P.IsTrailingComment =
(C.NewlinesBefore > 0 || C.Tok->is(tok::eof) ||
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
Builder.defineMacro("__cpp_nested_namespace_definitions", "201411L");
Builder.defineMacro("__cpp_variadic_using", "201611L");
Builder.defineMacro("__cpp_aggregate_bases", "201603L");
Builder.defineMacro("__cpp_structured_bindings", "201606L");
Builder.defineMacro("__cpp_structured_bindings", "202403L");
Builder.defineMacro("__cpp_nontype_template_args",
"201411L"); // (not latest)
Builder.defineMacro("__cpp_fold_expressions", "201603L");
Expand Down
41 changes: 31 additions & 10 deletions clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7038,18 +7038,23 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
void Parser::ParseDecompositionDeclarator(Declarator &D) {
assert(Tok.is(tok::l_square));

TentativeParsingAction PA(*this);
BalancedDelimiterTracker T(*this, tok::l_square);
T.consumeOpen();

if (isCXX11AttributeSpecifier())
DiagnoseAndSkipCXX11Attributes();

// If this doesn't look like a structured binding, maybe it's a misplaced
// array declarator.
// FIXME: Consume the l_square first so we don't need extra lookahead for
// this.
if (!(NextToken().is(tok::identifier) &&
GetLookAheadToken(2).isOneOf(tok::comma, tok::r_square)) &&
!(NextToken().is(tok::r_square) &&
GetLookAheadToken(2).isOneOf(tok::equal, tok::l_brace)))
if (!(Tok.is(tok::identifier) &&
NextToken().isOneOf(tok::comma, tok::r_square, tok::kw_alignas,
tok::l_square)) &&
!(Tok.is(tok::r_square) &&
NextToken().isOneOf(tok::equal, tok::l_brace))) {
PA.Revert();
return ParseMisplacedBracketDeclarator(D);

BalancedDelimiterTracker T(*this, tok::l_square);
T.consumeOpen();
}

SmallVector<DecompositionDeclarator::Binding, 32> Bindings;
while (Tok.isNot(tok::r_square)) {
Expand All @@ -7074,13 +7079,27 @@ void Parser::ParseDecompositionDeclarator(Declarator &D) {
}
}

if (isCXX11AttributeSpecifier())
DiagnoseAndSkipCXX11Attributes();

if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected) << tok::identifier;
break;
}

Bindings.push_back({Tok.getIdentifierInfo(), Tok.getLocation()});
IdentifierInfo *II = Tok.getIdentifierInfo();
SourceLocation Loc = Tok.getLocation();
ConsumeToken();

ParsedAttributes Attrs(AttrFactory);
if (isCXX11AttributeSpecifier()) {
Diag(Tok, getLangOpts().CPlusPlus26
? diag::warn_cxx23_compat_decl_attrs_on_binding
: diag::ext_decl_attrs_on_binding);
MaybeParseCXX11Attributes(Attrs);
}

Bindings.push_back({II, Loc, std::move(Attrs)});
}

if (Tok.isNot(tok::r_square))
Expand All @@ -7095,6 +7114,8 @@ void Parser::ParseDecompositionDeclarator(Declarator &D) {
T.consumeClose();
}

PA.Commit();

return D.setDecompositionBindings(T.getOpenLocation(), Bindings,
T.getCloseLocation());
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/DeclSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto,

void Declarator::setDecompositionBindings(
SourceLocation LSquareLoc,
ArrayRef<DecompositionDeclarator::Binding> Bindings,
MutableArrayRef<DecompositionDeclarator::Binding> Bindings,
SourceLocation RSquareLoc) {
assert(!hasName() && "declarator given multiple names!");

Expand All @@ -317,7 +317,7 @@ void Declarator::setDecompositionBindings(
new DecompositionDeclarator::Binding[Bindings.size()];
BindingGroup.DeleteBindings = true;
}
std::uninitialized_copy(Bindings.begin(), Bindings.end(),
std::uninitialized_move(Bindings.begin(), Bindings.end(),
BindingGroup.Bindings);
}
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions &LangOpts,
// it is, by the bindings' expressions).
bool IsAllPlaceholders = true;
for (const auto *BD : DD->bindings()) {
if (BD->isReferenced())
if (BD->isReferenced() || BD->hasAttr<UnusedAttr>())
return false;
IsAllPlaceholders = IsAllPlaceholders && BD->isPlaceholderVar(LangOpts);
}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,8 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,

auto *BD = BindingDecl::Create(Context, DC, B.NameLoc, VarName);

ProcessDeclAttributeList(S, BD, *B.Attrs);

// Find the shadowed declaration before filtering for scope.
NamedDecl *ShadowedDecl = D.getCXXScopeSpec().isEmpty()
? getShadowedDeclaration(BD, Previous)
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/amdgpu-toolchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@

// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
// RUN: -fuse-ld=ld %s 2>&1 | FileCheck -check-prefixes=LD %s
// LD: ld.lld"
// LD: ld.lld
2 changes: 1 addition & 1 deletion clang/test/Lexer/cxx-features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
#error "wrong value for __cpp_aggregate_bases"
#endif

#if check(structured_bindings, 0, 0, 0, 201606, 201606, 201606, 201606)
#if check(structured_bindings, 0, 0, 0, 202403L, 202403L, 202403L, 202403L)
#error "wrong value for __cpp_structured_bindings"
#endif

Expand Down
13 changes: 13 additions & 0 deletions clang/test/Misc/cc1as-relax-all.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// REQUIRES: x86-registered-target
// RUN: %clang -cc1as -triple x86_64 -filetype obj -mrelax-all %s -o %t.o
// RUN: llvm-objdump -d %t.o | FileCheck %s

// CHECK: <.text>:
// CHECK-NEXT: 0: e9 06 00 00 00 jmp 0xb <foo>
// CHECK-NEXT: 5: 0f 84 00 00 00 00 je 0xb <foo>
// CHECK-EMPTY:

jmp foo
je foo

foo: ret
Loading

0 comments on commit dc5c524

Please sign in to comment.