Skip to content

Commit bd63cfc

Browse files
authored
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_reference_binding_to_temporary
2 parents a1e77d2 + 16e051f commit bd63cfc

File tree

621 files changed

+19588
-11460
lines changed

Some content is hidden

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

621 files changed

+19588
-11460
lines changed

bolt/lib/Core/Relocation.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,11 @@ static bool skipRelocationProcessAArch64(uint64_t &Type, uint64_t Contents) {
271271
return (Contents & 0xfc000000) == 0x14000000;
272272
};
273273

274-
auto IsAdr = [](uint64_t Contents) -> bool {
275-
// The bits 31-24 are 0b0xx10000
276-
return (Contents & 0x9f000000) == 0x10000000;
277-
};
278-
279274
auto IsAddImm = [](uint64_t Contents) -> bool {
280275
// The bits 30-23 are 0b00100010
281276
return (Contents & 0x7F800000) == 0x11000000;
282277
};
283278

284-
auto IsNop = [](uint64_t Contents) -> bool { return Contents == 0xd503201f; };
285-
286-
// The linker might eliminate the instruction and replace it with NOP, ignore
287-
if (IsNop(Contents))
288-
return true;
289-
290279
// The linker might relax ADRP+LDR instruction sequence for loading symbol
291280
// address from GOT table to ADRP+ADD sequence that would point to the
292281
// binary-local symbol. Change relocation type in order to process it right.
@@ -332,18 +321,6 @@ static bool skipRelocationProcessAArch64(uint64_t &Type, uint64_t Contents) {
332321
}
333322
}
334323

335-
// The linker might relax ADRP+ADD or ADRP+LDR sequences to the ADR+NOP
336-
switch (Type) {
337-
default:
338-
break;
339-
case ELF::R_AARCH64_ADR_PREL_PG_HI21:
340-
case ELF::R_AARCH64_ADD_ABS_LO12_NC:
341-
case ELF::R_AARCH64_ADR_GOT_PAGE:
342-
case ELF::R_AARCH64_LD64_GOT_LO12_NC:
343-
if (IsAdr(Contents))
344-
return true;
345-
}
346-
347324
return false;
348325
}
349326

bolt/lib/Target/AArch64/AArch64MCSymbolizer.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ bool AArch64MCSymbolizer::tryAddingSymbolicOperand(
3131
if (BC.MIB->isBranch(Inst) || BC.MIB->isCall(Inst))
3232
return false;
3333

34-
// TODO: add handling for linker "relaxation". At the moment, relocations
35-
// corresponding to "relaxed" instructions are excluded from BinaryFunction
36-
// relocation list.
37-
3834
const uint64_t InstOffset = InstAddress - Function.getAddress();
3935
const Relocation *Relocation = Function.getRelocationAt(InstOffset);
4036

@@ -49,6 +45,21 @@ bool AArch64MCSymbolizer::tryAddingSymbolicOperand(
4945
BC.MIB->getTargetExprFor(Inst, Expr, *Ctx, RelType)));
5046
};
5147

48+
// The linker can convert ADRP+ADD and ADRP+LDR instruction sequences into
49+
// NOP+ADR. After the conversion, the linker might keep the relocations and
50+
// if we try to symbolize ADR's operand using outdated relocations, we might
51+
// get unexpected results. Hence, we check for the conversion/relaxation, and
52+
// ignore the relocation. The symbolization is done based on the PC-relative
53+
// value of the operand instead.
54+
if (Relocation && BC.MIB->isADR(Inst)) {
55+
if (Relocation->Type == ELF::R_AARCH64_ADD_ABS_LO12_NC ||
56+
Relocation->Type == ELF::R_AARCH64_LD64_GOT_LO12_NC) {
57+
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: ignoring relocation at 0x"
58+
<< Twine::utohexstr(InstAddress) << '\n');
59+
Relocation = nullptr;
60+
}
61+
}
62+
5263
if (Relocation) {
5364
addOperand(Relocation->Symbol, Relocation->Addend, Relocation->Type);
5465
return true;

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,18 +460,24 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
460460
CodeCompleteResult Result = clangd::codeComplete(
461461
File, Pos, IP->Preamble, ParseInput, CodeCompleteOpts,
462462
SpecFuzzyFind ? &*SpecFuzzyFind : nullptr);
463+
// We don't want `codeComplete` to wait for the async call if it doesn't use
464+
// the result (e.g. non-index completion, speculation fails), so that `CB`
465+
// is called as soon as results are available.
463466
{
464467
clang::clangd::trace::Span Tracer("Completion results callback");
465468
CB(std::move(Result));
466469
}
467-
if (SpecFuzzyFind && SpecFuzzyFind->NewReq) {
470+
if (!SpecFuzzyFind)
471+
return;
472+
if (SpecFuzzyFind->NewReq) {
468473
std::lock_guard<std::mutex> Lock(CachedCompletionFuzzyFindRequestMutex);
469474
CachedCompletionFuzzyFindRequestByFile[File] = *SpecFuzzyFind->NewReq;
470475
}
471-
// SpecFuzzyFind is only destroyed after speculative fuzzy find finishes.
472-
// We don't want `codeComplete` to wait for the async call if it doesn't use
473-
// the result (e.g. non-index completion, speculation fails), so that `CB`
474-
// is called as soon as results are available.
476+
// Explicitly block until async task completes, this is fine as we've
477+
// already provided reply to the client and running as a preamble task
478+
// (i.e. won't block other preamble tasks).
479+
if (SpecFuzzyFind->Result.valid())
480+
SpecFuzzyFind->Result.wait();
475481
};
476482

477483
// We use a potentially-stale preamble because latency is critical here.

clang-tools-extra/clangd/CodeComplete.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ struct SpeculativeFuzzyFind {
274274
/// Set by `codeComplete()`. This can be used by callers to update cache.
275275
std::optional<FuzzyFindRequest> NewReq;
276276
/// The result is consumed by `codeComplete()` if speculation succeeded.
277-
/// NOTE: the destructor will wait for the async call to finish.
278277
std::future<std::pair<bool /*Incomplete*/, SymbolSlab>> Result;
279278
};
280279

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ Bug Fixes in This Version
251251
- Non-local variable and non-variable declarations in the first clause of a ``for`` loop in C are no longer incorrectly
252252
considered an error in C23 mode and are allowed as an extension in earlier language modes.
253253

254+
- Remove the ``static`` specifier for the value of ``_FUNCTION_`` for static functions, in MSVC compatibility mode.
255+
254256
Bug Fixes to Compiler Builtins
255257
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
256258

@@ -276,6 +278,7 @@ Bug Fixes to C++ Support
276278
- The initialization kind of elements of structured bindings
277279
direct-list-initialized from an array is corrected to direct-initialization.
278280
- Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327)
281+
- Clang now uses the parameter location for abbreviated function templates in ``extern "C"``. (#GH46386)
279282

280283
Bug Fixes to AST Handling
281284
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
723723
// (However they are still accessible via TranslationUnitDecl->decls())
724724
//
725725
// Changing the scope clears the parent cache, which is expensive to rebuild.
726-
std::vector<Decl *> getTraversalScope() const { return TraversalScope; }
726+
ArrayRef<Decl *> getTraversalScope() const { return TraversalScope; }
727727
void setTraversalScope(const std::vector<Decl *> &);
728728

729729
/// Forwards to get node parents from the ParentMapContext. New callers should

clang/include/clang/AST/AttrIterator.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "clang/Basic/LLVM.h"
1717
#include "llvm/ADT/ADL.h"
1818
#include "llvm/ADT/SmallVector.h"
19+
#include "llvm/ADT/iterator_range.h"
1920
#include "llvm/Support/Casting.h"
2021
#include <cassert>
2122
#include <cstddef>
@@ -124,6 +125,17 @@ inline auto *getSpecificAttr(const Container &container) {
124125
return It != specific_attr_end<IterTy>(container) ? *It : nullptr;
125126
}
126127

128+
template <typename SpecificAttr, typename Container>
129+
inline auto getSpecificAttrs(const Container &container) {
130+
using ValueTy = llvm::detail::ValueOfRange<Container>;
131+
using ValuePointeeTy = std::remove_pointer_t<ValueTy>;
132+
using IterTy = std::conditional_t<std::is_const_v<ValuePointeeTy>,
133+
const SpecificAttr, SpecificAttr>;
134+
auto Begin = specific_attr_begin<IterTy>(container);
135+
auto End = specific_attr_end<IterTy>(container);
136+
return llvm::make_range(Begin, End);
137+
}
138+
127139
} // namespace clang
128140

129141
#endif // LLVM_CLANG_AST_ATTRITERATOR_H

clang/include/clang/AST/DeclOpenACC.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,61 @@ class OpenACCDeclareDecl final
101101
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
102102
static bool classofKind(Kind K) { return K == OpenACCDeclare; }
103103
};
104+
105+
class OpenACCRoutineDecl final
106+
: public OpenACCConstructDecl,
107+
private llvm::TrailingObjects<OpenACCRoutineDecl, const OpenACCClause *> {
108+
friend TrailingObjects;
109+
friend class ASTDeclReader;
110+
friend class ASTDeclWriter;
111+
112+
Expr *FuncRef = nullptr;
113+
SourceRange ParensLoc;
114+
115+
OpenACCRoutineDecl(unsigned NumClauses)
116+
: OpenACCConstructDecl(OpenACCRoutine) {
117+
std::uninitialized_value_construct(
118+
getTrailingObjects<const OpenACCClause *>(),
119+
getTrailingObjects<const OpenACCClause *>() + NumClauses);
120+
setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
121+
NumClauses));
122+
}
123+
124+
OpenACCRoutineDecl(DeclContext *DC, SourceLocation StartLoc,
125+
SourceLocation DirLoc, SourceLocation LParenLoc,
126+
Expr *FuncRef, SourceLocation RParenLoc,
127+
SourceLocation EndLoc,
128+
ArrayRef<const OpenACCClause *> Clauses)
129+
: OpenACCConstructDecl(OpenACCRoutine, DC, OpenACCDirectiveKind::Routine,
130+
StartLoc, DirLoc, EndLoc),
131+
FuncRef(FuncRef), ParensLoc(LParenLoc, RParenLoc) {
132+
// Initialize the trailing storage.
133+
std::uninitialized_copy(Clauses.begin(), Clauses.end(),
134+
getTrailingObjects<const OpenACCClause *>());
135+
setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
136+
Clauses.size()));
137+
}
138+
139+
public:
140+
static OpenACCRoutineDecl *
141+
Create(ASTContext &Ctx, DeclContext *DC, SourceLocation StartLoc,
142+
SourceLocation DirLoc, SourceLocation LParenLoc, Expr *FuncRef,
143+
SourceLocation RParenLoc, SourceLocation EndLoc,
144+
ArrayRef<const OpenACCClause *> Clauses);
145+
static OpenACCRoutineDecl *
146+
CreateDeserialized(ASTContext &Ctx, GlobalDeclID ID, unsigned NumClauses);
147+
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
148+
static bool classofKind(Kind K) { return K == OpenACCRoutine; }
149+
150+
const Expr *getFunctionReference() const { return FuncRef; }
151+
152+
Expr *getFunctionReference() { return FuncRef; }
153+
154+
SourceLocation getLParenLoc() const { return ParensLoc.getBegin(); }
155+
SourceLocation getRParenLoc() const { return ParensLoc.getEnd(); }
156+
157+
bool hasNameSpecified() const { return !ParensLoc.getBegin().isInvalid(); }
158+
};
104159
} // namespace clang
105160

106161
#endif

clang/include/clang/AST/JSONNodeDumper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ class JSONNodeDumper
282282
void VisitBlockDecl(const BlockDecl *D);
283283

284284
void VisitOpenACCDeclareDecl(const OpenACCDeclareDecl *D);
285+
void VisitOpenACCRoutineDecl(const OpenACCRoutineDecl *D);
285286

286287
void VisitDeclRefExpr(const DeclRefExpr *DRE);
287288
void VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E);

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,11 @@ DEF_TRAVERSE_DECL(OMPAllocateDecl, {
18251825
DEF_TRAVERSE_DECL(OpenACCDeclareDecl,
18261826
{ TRY_TO(VisitOpenACCClauseList(D->clauses())); })
18271827

1828+
DEF_TRAVERSE_DECL(OpenACCRoutineDecl, {
1829+
TRY_TO(TraverseStmt(D->getFunctionReference()));
1830+
TRY_TO(VisitOpenACCClauseList(D->clauses()));
1831+
})
1832+
18281833
// A helper method for TemplateDecl's children.
18291834
template <typename Derived>
18301835
bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(

0 commit comments

Comments
 (0)