Skip to content

Commit 6f87e58

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#2973)
2 parents 602791c + 9a93461 commit 6f87e58

File tree

231 files changed

+7044
-5790
lines changed

Some content is hidden

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

231 files changed

+7044
-5790
lines changed

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "bolt/Core/MCPlusBuilder.h"
2323
#include "llvm/BinaryFormat/ELF.h"
2424
#include "llvm/MC/MCContext.h"
25-
#include "llvm/MC/MCFixupKindInfo.h"
2625
#include "llvm/MC/MCInstBuilder.h"
2726
#include "llvm/MC/MCInstrInfo.h"
2827
#include "llvm/MC/MCRegister.h"

bolt/lib/Target/X86/X86MCPlusBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "bolt/Core/MCPlusBuilder.h"
1919
#include "llvm/BinaryFormat/ELF.h"
2020
#include "llvm/MC/MCContext.h"
21-
#include "llvm/MC/MCFixupKindInfo.h"
2221
#include "llvm/MC/MCInst.h"
2322
#include "llvm/MC/MCInstBuilder.h"
2423
#include "llvm/MC/MCInstrInfo.h"

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "llvm/ADT/StringExtras.h"
3434
#include "llvm/ADT/StringRef.h"
3535
#include "llvm/ADT/Twine.h"
36-
#include "llvm/ADT/identity.h"
3736
#include "llvm/Support/Casting.h"
3837
#include "llvm/Support/ErrorHandling.h"
3938
#include "llvm/Support/FormatVariadic.h"
@@ -339,53 +338,6 @@ QualType maybeDesugar(ASTContext &AST, QualType QT) {
339338
return QT;
340339
}
341340

342-
// Given a callee expression `Fn`, if the call is through a function pointer,
343-
// try to find the declaration of the corresponding function pointer type,
344-
// so that we can recover argument names from it.
345-
// FIXME: This function is mostly duplicated in SemaCodeComplete.cpp; unify.
346-
static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
347-
TypeLoc Target;
348-
Expr *NakedFn = Fn->IgnoreParenCasts();
349-
if (const auto *T = NakedFn->getType().getTypePtr()->getAs<TypedefType>()) {
350-
Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
351-
} else if (const auto *DR = dyn_cast<DeclRefExpr>(NakedFn)) {
352-
const auto *D = DR->getDecl();
353-
if (const auto *const VD = dyn_cast<VarDecl>(D)) {
354-
Target = VD->getTypeSourceInfo()->getTypeLoc();
355-
}
356-
}
357-
358-
if (!Target)
359-
return {};
360-
361-
// Unwrap types that may be wrapping the function type
362-
while (true) {
363-
if (auto P = Target.getAs<PointerTypeLoc>()) {
364-
Target = P.getPointeeLoc();
365-
continue;
366-
}
367-
if (auto A = Target.getAs<AttributedTypeLoc>()) {
368-
Target = A.getModifiedLoc();
369-
continue;
370-
}
371-
if (auto P = Target.getAs<ParenTypeLoc>()) {
372-
Target = P.getInnerLoc();
373-
continue;
374-
}
375-
break;
376-
}
377-
378-
if (auto F = Target.getAs<FunctionProtoTypeLoc>()) {
379-
// In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
380-
// which has null parameters. Avoid these as they don't contain useful
381-
// information.
382-
if (llvm::all_of(F.getParams(), llvm::identity<ParmVarDecl *>()))
383-
return F;
384-
}
385-
386-
return {};
387-
}
388-
389341
ArrayRef<const ParmVarDecl *>
390342
maybeDropCxxExplicitObjectParameters(ArrayRef<const ParmVarDecl *> Params) {
391343
if (!Params.empty() && Params.front()->isExplicitObjectParameter())
@@ -514,7 +466,8 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
514466
Callee.Decl = FD;
515467
else if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(CalleeDecls[0]))
516468
Callee.Decl = FTD->getTemplatedDecl();
517-
else if (FunctionProtoTypeLoc Loc = getPrototypeLoc(E->getCallee()))
469+
else if (FunctionProtoTypeLoc Loc =
470+
Resolver->getFunctionProtoTypeLoc(E->getCallee()))
518471
Callee.Loc = Loc;
519472
else
520473
return true;

clang/docs/DebuggingCoroutines.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ suspension point.
221221
Line 45 of "llvm-example.cpp" starts at address 0x201b <_ZL9coro_taski.destroy+555> and ends at 0x2046 <_ZL9coro_taski.destroy+598>.
222222
Line 45 of "llvm-example.cpp" starts at address 0x253b <_ZL9coro_taski.cleanup+555> and ends at 0x2566 <_ZL9coro_taski.cleanup+598>.
223223

224-
LLDB does not support looking up labels. Furthmore, those labels are only emitted
224+
LLDB does not support looking up labels. Furthermore, those labels are only emitted
225225
starting with clang 21.0.
226226

227227
For simple cases, you might still be able to guess the suspension point correctly.

clang/include/clang/Sema/HeuristicResolver.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CXXBasePath;
2020
class CXXDependentScopeMemberExpr;
2121
class DeclarationName;
2222
class DependentScopeDeclRefExpr;
23+
class FunctionProtoTypeLoc;
2324
class NamedDecl;
2425
class Type;
2526
class UnresolvedUsingValueDecl;
@@ -93,6 +94,12 @@ class HeuristicResolver {
9394
// during simplification, and the operation fails if no pointer type is found.
9495
QualType simplifyType(QualType Type, const Expr *E, bool UnwrapPointer);
9596

97+
// Given an expression `Fn` representing the callee in a function call,
98+
// if the call is through a function pointer, try to find the declaration of
99+
// the corresponding function pointer type, so that we can recover argument
100+
// names from it.
101+
FunctionProtoTypeLoc getFunctionProtoTypeLoc(const Expr *Fn) const;
102+
96103
private:
97104
ASTContext &Ctx;
98105
};

clang/lib/AST/ByteCode/Interp.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,30 +1139,12 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
11391139
}
11401140

11411141
if (Pointer::hasSameBase(LHS, RHS)) {
1142-
if (LHS.inUnion() && RHS.inUnion()) {
1143-
// If the pointers point into a union, things are a little more
1144-
// complicated since the offset we save in interp::Pointer can't be used
1145-
// to compare the pointers directly.
1146-
size_t A = LHS.computeOffsetForComparison();
1147-
size_t B = RHS.computeOffsetForComparison();
1148-
S.Stk.push<BoolT>(BoolT::from(Fn(Compare(A, B))));
1149-
return true;
1150-
}
1151-
1152-
unsigned VL = LHS.getByteOffset();
1153-
unsigned VR = RHS.getByteOffset();
1154-
// In our Pointer class, a pointer to an array and a pointer to the first
1155-
// element in the same array are NOT equal. They have the same Base value,
1156-
// but a different Offset. This is a pretty rare case, so we fix this here
1157-
// by comparing pointers to the first elements.
1158-
if (!LHS.isZero() && LHS.isArrayRoot())
1159-
VL = LHS.atIndex(0).getByteOffset();
1160-
if (!RHS.isZero() && RHS.isArrayRoot())
1161-
VR = RHS.atIndex(0).getByteOffset();
1162-
1163-
S.Stk.push<BoolT>(BoolT::from(Fn(Compare(VL, VR))));
1142+
size_t A = LHS.computeOffsetForComparison();
1143+
size_t B = RHS.computeOffsetForComparison();
1144+
S.Stk.push<BoolT>(BoolT::from(Fn(Compare(A, B))));
11641145
return true;
11651146
}
1147+
11661148
// Otherwise we need to do a bunch of extra checks before returning Unordered.
11671149
if (LHS.isOnePastEnd() && !RHS.isOnePastEnd() && !RHS.isZero() &&
11681150
RHS.getOffset() == 0) {

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,28 @@ void Pointer::print(llvm::raw_ostream &OS) const {
338338
}
339339
}
340340

341-
/// Compute an integer that can be used to compare this pointer to
342-
/// another one.
343341
size_t Pointer::computeOffsetForComparison() const {
342+
if (isIntegralPointer())
343+
return asIntPointer().Value + Offset;
344+
if (isTypeidPointer())
345+
return reinterpret_cast<uintptr_t>(asTypeidPointer().TypePtr) + Offset;
346+
344347
if (!isBlockPointer())
345348
return Offset;
346349

347350
size_t Result = 0;
348351
Pointer P = *this;
349-
while (!P.isRoot()) {
350-
if (P.isArrayRoot()) {
352+
while (true) {
353+
354+
if (P.isVirtualBaseClass()) {
355+
Result += getInlineDesc()->Offset;
356+
P = P.getBase();
357+
continue;
358+
}
359+
360+
if (P.isBaseClass()) {
361+
if (P.getRecord()->getNumVirtualBases() > 0)
362+
Result += P.getInlineDesc()->Offset;
351363
P = P.getBase();
352364
continue;
353365
}
@@ -358,14 +370,26 @@ size_t Pointer::computeOffsetForComparison() const {
358370
continue;
359371
}
360372

373+
if (P.isRoot()) {
374+
if (P.isOnePastEnd())
375+
++Result;
376+
break;
377+
}
378+
361379
if (const Record *R = P.getBase().getRecord(); R && R->isUnion()) {
362380
// Direct child of a union - all have offset 0.
363381
P = P.getBase();
364382
continue;
365383
}
366384

385+
// Fields, etc.
367386
Result += P.getInlineDesc()->Offset;
387+
if (P.isOnePastEnd())
388+
++Result;
389+
368390
P = P.getBase();
391+
if (P.isRoot())
392+
break;
369393
}
370394

371395
return Result;

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,9 @@ class Pointer {
761761
/// Prints the pointer.
762762
void print(llvm::raw_ostream &OS) const;
763763

764+
/// Compute an integer that can be used to compare this pointer to
765+
/// another one. This is usually NOT the same as the pointer offset
766+
/// regarding the AST record layout.
764767
size_t computeOffsetForComparison() const;
765768

766769
private:

clang/lib/Sema/HeuristicResolver.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang/AST/ExprCXX.h"
1414
#include "clang/AST/TemplateBase.h"
1515
#include "clang/AST/Type.h"
16+
#include "llvm/ADT/identity.h"
1617

1718
namespace clang {
1819

@@ -50,6 +51,7 @@ class HeuristicResolverImpl {
5051
llvm::function_ref<bool(const NamedDecl *ND)> Filter);
5152
TagDecl *resolveTypeToTagDecl(QualType T);
5253
QualType simplifyType(QualType Type, const Expr *E, bool UnwrapPointer);
54+
FunctionProtoTypeLoc getFunctionProtoTypeLoc(const Expr *Fn);
5355

5456
private:
5557
ASTContext &Ctx;
@@ -506,6 +508,56 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveDependentMember(
506508
}
507509
return {};
508510
}
511+
512+
FunctionProtoTypeLoc
513+
HeuristicResolverImpl::getFunctionProtoTypeLoc(const Expr *Fn) {
514+
TypeLoc Target;
515+
const Expr *NakedFn = Fn->IgnoreParenCasts();
516+
if (const auto *T = NakedFn->getType().getTypePtr()->getAs<TypedefType>()) {
517+
Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
518+
} else if (const auto *DR = dyn_cast<DeclRefExpr>(NakedFn)) {
519+
const auto *D = DR->getDecl();
520+
if (const auto *const VD = dyn_cast<VarDecl>(D)) {
521+
Target = VD->getTypeSourceInfo()->getTypeLoc();
522+
}
523+
} else if (const auto *ME = dyn_cast<MemberExpr>(NakedFn)) {
524+
const auto *MD = ME->getMemberDecl();
525+
if (const auto *FD = dyn_cast<FieldDecl>(MD)) {
526+
Target = FD->getTypeSourceInfo()->getTypeLoc();
527+
}
528+
}
529+
530+
if (!Target)
531+
return {};
532+
533+
// Unwrap types that may be wrapping the function type
534+
while (true) {
535+
if (auto P = Target.getAs<PointerTypeLoc>()) {
536+
Target = P.getPointeeLoc();
537+
continue;
538+
}
539+
if (auto A = Target.getAs<AttributedTypeLoc>()) {
540+
Target = A.getModifiedLoc();
541+
continue;
542+
}
543+
if (auto P = Target.getAs<ParenTypeLoc>()) {
544+
Target = P.getInnerLoc();
545+
continue;
546+
}
547+
break;
548+
}
549+
550+
if (auto F = Target.getAs<FunctionProtoTypeLoc>()) {
551+
// In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
552+
// which has null parameters. Avoid these as they don't contain useful
553+
// information.
554+
if (llvm::all_of(F.getParams(), llvm::identity<ParmVarDecl *>()))
555+
return F;
556+
}
557+
558+
return {};
559+
}
560+
509561
} // namespace
510562

511563
std::vector<const NamedDecl *> HeuristicResolver::resolveMemberExpr(
@@ -557,4 +609,9 @@ QualType HeuristicResolver::simplifyType(QualType Type, const Expr *E,
557609
return HeuristicResolverImpl(Ctx).simplifyType(Type, E, UnwrapPointer);
558610
}
559611

612+
FunctionProtoTypeLoc
613+
HeuristicResolver::getFunctionProtoTypeLoc(const Expr *Fn) const {
614+
return HeuristicResolverImpl(Ctx).getFunctionProtoTypeLoc(Fn);
615+
}
616+
560617
} // namespace clang

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6317,54 +6317,6 @@ ProduceSignatureHelp(Sema &SemaRef, MutableArrayRef<ResultCandidate> Candidates,
63176317
return getParamType(SemaRef, Candidates, CurrentArg);
63186318
}
63196319

6320-
// Given a callee expression `Fn`, if the call is through a function pointer,
6321-
// try to find the declaration of the corresponding function pointer type,
6322-
// so that we can recover argument names from it.
6323-
static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
6324-
TypeLoc Target;
6325-
6326-
if (const auto *T = Fn->getType().getTypePtr()->getAs<TypedefType>()) {
6327-
Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
6328-
6329-
} else if (const auto *DR = dyn_cast<DeclRefExpr>(Fn)) {
6330-
const auto *D = DR->getDecl();
6331-
if (const auto *const VD = dyn_cast<VarDecl>(D)) {
6332-
Target = VD->getTypeSourceInfo()->getTypeLoc();
6333-
}
6334-
} else if (const auto *ME = dyn_cast<MemberExpr>(Fn)) {
6335-
const auto *MD = ME->getMemberDecl();
6336-
if (const auto *FD = dyn_cast<FieldDecl>(MD)) {
6337-
Target = FD->getTypeSourceInfo()->getTypeLoc();
6338-
}
6339-
}
6340-
6341-
if (!Target)
6342-
return {};
6343-
6344-
// Unwrap types that may be wrapping the function type
6345-
while (true) {
6346-
if (auto P = Target.getAs<PointerTypeLoc>()) {
6347-
Target = P.getPointeeLoc();
6348-
continue;
6349-
}
6350-
if (auto A = Target.getAs<AttributedTypeLoc>()) {
6351-
Target = A.getModifiedLoc();
6352-
continue;
6353-
}
6354-
if (auto P = Target.getAs<ParenTypeLoc>()) {
6355-
Target = P.getInnerLoc();
6356-
continue;
6357-
}
6358-
break;
6359-
}
6360-
6361-
if (auto F = Target.getAs<FunctionProtoTypeLoc>()) {
6362-
return F;
6363-
}
6364-
6365-
return {};
6366-
}
6367-
63686320
QualType
63696321
SemaCodeCompletion::ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args,
63706322
SourceLocation OpenParLoc) {
@@ -6453,7 +6405,7 @@ SemaCodeCompletion::ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args,
64536405
// Lastly we check whether expression's type is function pointer or
64546406
// function.
64556407

6456-
FunctionProtoTypeLoc P = GetPrototypeLoc(NakedFn);
6408+
FunctionProtoTypeLoc P = Resolver.getFunctionProtoTypeLoc(NakedFn);
64576409
QualType T = NakedFn->getType();
64586410
if (!T->getPointeeType().isNull())
64596411
T = T->getPointeeType();

0 commit comments

Comments
 (0)