Skip to content

Commit 7d97400

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:625891288087 into amd-gfx:3533ef87d458
Local branch amd-gfx 3533ef8 Merged main:05eaff18c401 into amd-gfx:314f2ed36cef Remote branch main 6258912 [clangd][clang-tidy] Add missing symbols to the symbol map.
2 parents 3533ef8 + 6258912 commit 7d97400

File tree

26 files changed

+546
-92
lines changed

26 files changed

+546
-92
lines changed

clang-tools-extra/include-cleaner/lib/TypesInternal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ enum class Hints : uint8_t {
6666
/// Symbol is directly originating from this header, rather than being
6767
/// exported or included transitively.
6868
OriginHeader = 1 << 0,
69-
/// Provides a generally-usable definition for the symbol. (a function decl,
70-
/// or class definition and not a forward declaration of a template).
71-
CompleteSymbol = 1 << 1,
7269
/// Header providing the symbol is explicitly marked as preferred, with an
7370
/// IWYU private pragma that points at this provider or header and symbol has
7471
/// ~the same name.
75-
PreferredHeader = 1 << 2,
72+
PreferredHeader = 1 << 1,
73+
/// Provides a generally-usable definition for the symbol. (a function decl,
74+
/// or class definition and not a forward declaration of a template).
75+
CompleteSymbol = 1 << 2,
7676
/// Symbol is provided by a public file. Only absent in the cases where file
7777
/// is explicitly marked as such, non self-contained or IWYU private
7878
/// pragmas.

clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ TEST_F(HeadersForSymbolTest, RankByName) {
344344
}
345345

346346
TEST_F(HeadersForSymbolTest, Ranking) {
347-
// Sorting is done over (canonical, public, complete, origin)-tuple.
347+
// Sorting is done over (public, complete, canonical, origin)-tuple.
348348
Inputs.Code = R"cpp(
349349
#include "private.h"
350350
#include "public.h"
@@ -363,11 +363,11 @@ TEST_F(HeadersForSymbolTest, Ranking) {
363363
)cpp");
364364
Inputs.ExtraFiles["public_complete.h"] = guard("struct foo {};");
365365
buildAST();
366-
EXPECT_THAT(headersForFoo(), ElementsAre(Header("\"canonical.h\""),
367-
physicalHeader("public_complete.h"),
368-
physicalHeader("public.h"),
369-
physicalHeader("exporter.h"),
370-
physicalHeader("private.h")));
366+
EXPECT_THAT(headersForFoo(),
367+
ElementsAre(physicalHeader("public_complete.h"),
368+
Header("\"canonical.h\""), physicalHeader("public.h"),
369+
physicalHeader("exporter.h"),
370+
physicalHeader("private.h")));
371371
}
372372

373373
TEST_F(HeadersForSymbolTest, PreferPublicOverComplete) {
@@ -391,14 +391,11 @@ TEST_F(HeadersForSymbolTest, PreferNameMatch) {
391391
#include "public_complete.h"
392392
#include "test/foo.fwd.h"
393393
)cpp";
394-
Inputs.ExtraFiles["public_complete.h"] = guard(R"cpp(
395-
struct foo {};
396-
)cpp");
394+
Inputs.ExtraFiles["public_complete.h"] = guard("struct foo {};");
397395
Inputs.ExtraFiles["test/foo.fwd.h"] = guard("struct foo;");
398396
buildAST();
399-
EXPECT_THAT(headersForFoo(),
400-
ElementsAre(physicalHeader("test/foo.fwd.h"),
401-
physicalHeader("public_complete.h")));
397+
EXPECT_THAT(headersForFoo(), ElementsAre(physicalHeader("public_complete.h"),
398+
physicalHeader("test/foo.fwd.h")));
402399
}
403400

404401
TEST_F(HeadersForSymbolTest, MainFile) {

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 161 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,58 @@ bool ByteCodeExprGen<Emitter>::VisitArraySubscriptExpr(
511511
return this->emitArrayElemPtrPop(IndexT, E);
512512
}
513513

514+
template <class Emitter>
515+
bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
516+
const Expr *E) {
517+
assert(E->getType()->isRecordType());
518+
const Record *R = getRecord(E->getType());
519+
520+
unsigned InitIndex = 0;
521+
for (const Expr *Init : Inits) {
522+
if (!this->emitDupPtr(E))
523+
return false;
524+
525+
if (std::optional<PrimType> T = classify(Init)) {
526+
const Record::Field *FieldToInit = R->getField(InitIndex);
527+
if (!this->visit(Init))
528+
return false;
529+
if (!this->emitInitField(*T, FieldToInit->Offset, E))
530+
return false;
531+
if (!this->emitPopPtr(E))
532+
return false;
533+
++InitIndex;
534+
} else {
535+
// Initializer for a direct base class.
536+
if (const Record::Base *B = R->getBase(Init->getType())) {
537+
if (!this->emitGetPtrBasePop(B->Offset, Init))
538+
return false;
539+
540+
if (!this->visitInitializer(Init))
541+
return false;
542+
543+
if (!this->emitPopPtr(E))
544+
return false;
545+
// Base initializers don't increase InitIndex, since they don't count
546+
// into the Record's fields.
547+
} else {
548+
const Record::Field *FieldToInit = R->getField(InitIndex);
549+
// Non-primitive case. Get a pointer to the field-to-initialize
550+
// on the stack and recurse into visitInitializer().
551+
if (!this->emitGetPtrField(FieldToInit->Offset, Init))
552+
return false;
553+
554+
if (!this->visitInitializer(Init))
555+
return false;
556+
557+
if (!this->emitPopPtr(E))
558+
return false;
559+
++InitIndex;
560+
}
561+
}
562+
}
563+
return true;
564+
}
565+
514566
template <class Emitter>
515567
bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
516568
// Handle discarding first.
@@ -530,56 +582,8 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
530582
}
531583

532584
QualType T = E->getType();
533-
if (T->isRecordType()) {
534-
const Record *R = getRecord(T);
535-
536-
unsigned InitIndex = 0;
537-
for (const Expr *Init : E->inits()) {
538-
if (!this->emitDupPtr(E))
539-
return false;
540-
541-
if (std::optional<PrimType> T = classify(Init)) {
542-
const Record::Field *FieldToInit = R->getField(InitIndex);
543-
if (!this->visit(Init))
544-
return false;
545-
546-
if (!this->emitInitField(*T, FieldToInit->Offset, E))
547-
return false;
548-
549-
if (!this->emitPopPtr(E))
550-
return false;
551-
++InitIndex;
552-
} else {
553-
// Initializer for a direct base class.
554-
if (const Record::Base *B = R->getBase(Init->getType())) {
555-
if (!this->emitGetPtrBasePop(B->Offset, Init))
556-
return false;
557-
558-
if (!this->visitInitializer(Init))
559-
return false;
560-
561-
if (!this->emitPopPtr(E))
562-
return false;
563-
// Base initializers don't increase InitIndex, since they don't count
564-
// into the Record's fields.
565-
} else {
566-
const Record::Field *FieldToInit = R->getField(InitIndex);
567-
// Non-primitive case. Get a pointer to the field-to-initialize
568-
// on the stack and recurse into visitInitializer().
569-
if (!this->emitGetPtrField(FieldToInit->Offset, Init))
570-
return false;
571-
572-
if (!this->visitInitializer(Init))
573-
return false;
574-
575-
if (!this->emitPopPtr(E))
576-
return false;
577-
++InitIndex;
578-
}
579-
}
580-
}
581-
return true;
582-
}
585+
if (T->isRecordType())
586+
return this->visitInitList(E->inits(), E);
583587

584588
if (T->isArrayType()) {
585589
// FIXME: Array fillers.
@@ -612,6 +616,21 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
612616
return false;
613617
}
614618

619+
template <class Emitter>
620+
bool ByteCodeExprGen<Emitter>::VisitCXXParenListInitExpr(
621+
const CXXParenListInitExpr *E) {
622+
if (DiscardResult) {
623+
for (const Expr *Init : E->getInitExprs()) {
624+
if (!this->discard(Init))
625+
return false;
626+
}
627+
return true;
628+
}
629+
630+
assert(E->getType()->isRecordType());
631+
return this->visitInitList(E->getInitExprs(), E);
632+
}
633+
615634
template <class Emitter>
616635
bool ByteCodeExprGen<Emitter>::VisitSubstNonTypeTemplateParmExpr(
617636
const SubstNonTypeTemplateParmExpr *E) {
@@ -1383,6 +1402,62 @@ bool ByteCodeExprGen<Emitter>::VisitCXXConstructExpr(
13831402
return false;
13841403
}
13851404

1405+
template <class Emitter>
1406+
bool ByteCodeExprGen<Emitter>::VisitSourceLocExpr(const SourceLocExpr *E) {
1407+
if (DiscardResult)
1408+
return true;
1409+
1410+
const APValue Val =
1411+
E->EvaluateInContext(Ctx.getASTContext(), SourceLocDefaultExpr);
1412+
1413+
// Things like __builtin_LINE().
1414+
if (E->getType()->isIntegerType()) {
1415+
assert(Val.isInt());
1416+
const APSInt &I = Val.getInt();
1417+
return this->emitConst(I, E);
1418+
}
1419+
// Otherwise, the APValue is an LValue, with only one element.
1420+
// Theoretically, we don't need the APValue at all of course.
1421+
assert(E->getType()->isPointerType());
1422+
assert(Val.isLValue());
1423+
const APValue::LValueBase &Base = Val.getLValueBase();
1424+
if (const Expr *LValueExpr = Base.dyn_cast<const Expr *>())
1425+
return this->visit(LValueExpr);
1426+
1427+
// Otherwise, we have a decl (which is the case for
1428+
// __builtin_source_location).
1429+
assert(Base.is<const ValueDecl *>());
1430+
assert(Val.getLValuePath().size() == 0);
1431+
const auto *BaseDecl = Base.dyn_cast<const ValueDecl *>();
1432+
assert(BaseDecl);
1433+
1434+
auto *UGCD = cast<UnnamedGlobalConstantDecl>(BaseDecl);
1435+
1436+
std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(UGCD);
1437+
if (!GlobalIndex)
1438+
return false;
1439+
1440+
if (!this->emitGetPtrGlobal(*GlobalIndex, E))
1441+
return false;
1442+
1443+
const Record *R = getRecord(E->getType());
1444+
const APValue &V = UGCD->getValue();
1445+
for (unsigned I = 0, N = R->getNumFields(); I != N; ++I) {
1446+
const Record::Field *F = R->getField(I);
1447+
const APValue &FieldValue = V.getStructField(I);
1448+
1449+
PrimType FieldT = classifyPrim(F->Decl->getType());
1450+
1451+
if (!this->visitAPValue(FieldValue, FieldT, E))
1452+
return false;
1453+
if (!this->emitInitField(FieldT, F->Offset, E))
1454+
return false;
1455+
}
1456+
1457+
// Leave the pointer to the global on the stack.
1458+
return true;
1459+
}
1460+
13861461
template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
13871462
if (E->containsErrors())
13881463
return false;
@@ -1694,8 +1769,8 @@ bool ByteCodeExprGen<Emitter>::dereferenceVar(
16941769

16951770
template <class Emitter>
16961771
template <typename T>
1697-
bool ByteCodeExprGen<Emitter>::emitConst(T Value, const Expr *E) {
1698-
switch (classifyPrim(E->getType())) {
1772+
bool ByteCodeExprGen<Emitter>::emitConst(T Value, PrimType Ty, const Expr *E) {
1773+
switch (Ty) {
16991774
case PT_Sint8:
17001775
return this->emitConstSint8(Value, E);
17011776
case PT_Uint8:
@@ -1724,10 +1799,22 @@ bool ByteCodeExprGen<Emitter>::emitConst(T Value, const Expr *E) {
17241799
}
17251800

17261801
template <class Emitter>
1727-
bool ByteCodeExprGen<Emitter>::emitConst(const APSInt &Value, const Expr *E) {
1802+
template <typename T>
1803+
bool ByteCodeExprGen<Emitter>::emitConst(T Value, const Expr *E) {
1804+
return this->emitConst(Value, classifyPrim(E->getType()), E);
1805+
}
1806+
1807+
template <class Emitter>
1808+
bool ByteCodeExprGen<Emitter>::emitConst(const APSInt &Value, PrimType Ty,
1809+
const Expr *E) {
17281810
if (Value.isSigned())
1729-
return this->emitConst(Value.getSExtValue(), E);
1730-
return this->emitConst(Value.getZExtValue(), E);
1811+
return this->emitConst(Value.getSExtValue(), Ty, E);
1812+
return this->emitConst(Value.getZExtValue(), Ty, E);
1813+
}
1814+
1815+
template <class Emitter>
1816+
bool ByteCodeExprGen<Emitter>::emitConst(const APSInt &Value, const Expr *E) {
1817+
return this->emitConst(Value, classifyPrim(E->getType()), E);
17311818
}
17321819

17331820
template <class Emitter>
@@ -1923,6 +2010,22 @@ bool ByteCodeExprGen<Emitter>::visitVarDecl(const VarDecl *VD) {
19232010
return false;
19242011
}
19252012

2013+
template <class Emitter>
2014+
bool ByteCodeExprGen<Emitter>::visitAPValue(const APValue &Val,
2015+
PrimType ValType, const Expr *E) {
2016+
assert(!DiscardResult);
2017+
if (Val.isInt())
2018+
return this->emitConst(Val.getInt(), ValType, E);
2019+
2020+
if (Val.isLValue()) {
2021+
APValue::LValueBase Base = Val.getLValueBase();
2022+
if (const Expr *BaseExpr = Base.dyn_cast<const Expr *>())
2023+
return this->visit(BaseExpr);
2024+
}
2025+
2026+
return false;
2027+
}
2028+
19262029
template <class Emitter>
19272030
bool ByteCodeExprGen<Emitter>::VisitBuiltinCallExpr(const CallExpr *E) {
19282031
const Function *Func = getFunction(E->getDirectCallee());
@@ -2054,14 +2157,16 @@ bool ByteCodeExprGen<Emitter>::VisitCXXDefaultInitExpr(
20542157
return this->visitInitializer(E->getExpr());
20552158

20562159
assert(classify(E->getType()));
2160+
SourceLocScope<Emitter> SLS(this, E);
20572161
return this->visit(E->getExpr());
20582162
}
20592163

20602164
template <class Emitter>
20612165
bool ByteCodeExprGen<Emitter>::VisitCXXDefaultArgExpr(
20622166
const CXXDefaultArgExpr *E) {
2063-
const Expr *SubExpr = E->getExpr();
2167+
SourceLocScope<Emitter> SLS(this, E);
20642168

2169+
const Expr *SubExpr = E->getExpr();
20652170
if (std::optional<PrimType> T = classify(E->getExpr()))
20662171
return this->visit(SubExpr);
20672172

0 commit comments

Comments
 (0)