Skip to content

Commit 4dea033

Browse files
danix800tru
authored andcommitted
[clang] Update NumFunctionDeclBits for FunctionDeclBitfields
NumFunctionDeclBits is not updated when DeductionCandidateKind is incremented. Fixes llvm#64171 Reviewed By: cor3ntin, balazske, aaron.ballman Differential Revision: https://reviews.llvm.org/D158145 (cherry picked from commit 91c4b55)
1 parent 2c9feb0 commit 4dea033

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,9 @@ Bug Fixes to C++ Support
833833
- Fix constraint checking of non-generic lambdas.
834834
(`#63181 <https://github.com/llvm/llvm-project/issues/63181>`_)
835835

836+
- Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
837+
(`#64171 <https://github.com/llvm/llvm-project/issues/64171>`_).
838+
836839
Bug Fixes to AST Handling
837840
^^^^^^^^^^^^^^^^^^^^^^^^^
838841

clang/include/clang/AST/DeclBase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ class DeclContext {
17021702
};
17031703

17041704
/// Number of non-inherited bits in FunctionDeclBitfields.
1705-
enum { NumFunctionDeclBits = 30 };
1705+
enum { NumFunctionDeclBits = 31 };
17061706

17071707
/// Stores the bits used by CXXConstructorDecl. If modified
17081708
/// NumCXXConstructorDeclBits and the accessor
@@ -1714,12 +1714,12 @@ class DeclContext {
17141714
/// For the bits in FunctionDeclBitfields.
17151715
uint64_t : NumFunctionDeclBits;
17161716

1717-
/// 21 bits to fit in the remaining available space.
1717+
/// 20 bits to fit in the remaining available space.
17181718
/// Note that this makes CXXConstructorDeclBitfields take
17191719
/// exactly 64 bits and thus the width of NumCtorInitializers
17201720
/// will need to be shrunk if some bit is added to NumDeclContextBitfields,
17211721
/// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
1722-
uint64_t NumCtorInitializers : 18;
1722+
uint64_t NumCtorInitializers : 17;
17231723
uint64_t IsInheritingConstructor : 1;
17241724

17251725
/// Whether this constructor has a trail-allocated explicit specifier.

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
580580
}
581581

582582
void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
583-
static_assert(DeclContext::NumFunctionDeclBits == 30,
583+
static_assert(DeclContext::NumFunctionDeclBits == 31,
584584
"You need to update the serializer after you change the "
585585
"FunctionDeclBits");
586586

@@ -1495,7 +1495,7 @@ void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
14951495
}
14961496

14971497
void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
1498-
static_assert(DeclContext::NumCXXConstructorDeclBits == 21,
1498+
static_assert(DeclContext::NumCXXConstructorDeclBits == 20,
14991499
"You need to update the serializer after you change the "
15001500
"CXXConstructorDeclBits");
15011501

clang/unittests/AST/ASTImporterTest.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7711,6 +7711,47 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConstructorUsingShadow) {
77117711
CheckAST(ToTU, ToC);
77127712
}
77137713

7714+
TEST_P(ASTImporterOptionSpecificTestBase,
7715+
ImportFunctionDeclBitShouldNotOverwriteCtorDeclBits) {
7716+
Decl *From, *To;
7717+
std::tie(From, To) = getImportedDecl(
7718+
R"s(
7719+
struct A {
7720+
A() : m() {}
7721+
int m;
7722+
};
7723+
7724+
A foo() { A a; return a; }
7725+
A bar() { return {}; }
7726+
)s",
7727+
Lang_CXX17,
7728+
R"s(
7729+
struct A {
7730+
A() : m() {}
7731+
int m;
7732+
};
7733+
A baz() { return {}; }
7734+
)s",
7735+
Lang_CXX17, "A");
7736+
7737+
auto HasCtorInit =
7738+
hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
7739+
auto ImpMoveCtor =
7740+
cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit);
7741+
7742+
auto *FromImpMoveCtor = FirstDeclMatcher<CXXConstructorDecl>().match(
7743+
From, ImpMoveCtor);
7744+
auto *ToImpMoveCtor = FirstDeclMatcher<CXXConstructorDecl>().match(
7745+
To, ImpMoveCtor);
7746+
7747+
EXPECT_TRUE(FromImpMoveCtor->getNumCtorInitializers() == 1);
7748+
EXPECT_FALSE(FromImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
7749+
7750+
EXPECT_TRUE(ToImpMoveCtor->getNumCtorInitializers() == 1);
7751+
EXPECT_FALSE(ToImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
7752+
EXPECT_TRUE(*ToImpMoveCtor->init_begin());
7753+
}
7754+
77147755
AST_MATCHER_P(UsingShadowDecl, hasIntroducerDecl, internal::Matcher<NamedDecl>,
77157756
InnerMatcher) {
77167757
return InnerMatcher.matches(*Node.getIntroducer(), Finder, Builder);

clang/unittests/AST/DeclTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,32 @@ TEST(Decl, FriendFunctionWithinClassInHeaderUnit) {
353353
EXPECT_TRUE(getFooValue->isInlined());
354354
}
355355

356+
TEST(Decl, FunctionDeclBitsShouldNotOverlapWithCXXConstructorDeclBits) {
357+
llvm::Annotations Code(R"(
358+
struct A {
359+
A() : m() {}
360+
int m;
361+
};
362+
363+
A f() { return A(); }
364+
)");
365+
366+
auto AST = tooling::buildASTFromCodeWithArgs(Code.code(), {"-std=c++14"});
367+
ASTContext &Ctx = AST->getASTContext();
368+
369+
auto HasCtorInit =
370+
hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
371+
auto ImpMoveCtor =
372+
cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit)
373+
.bind("MoveCtor");
374+
375+
auto *ToImpMoveCtor =
376+
selectFirst<CXXConstructorDecl>("MoveCtor", match(ImpMoveCtor, Ctx));
377+
378+
EXPECT_TRUE(ToImpMoveCtor->getNumCtorInitializers() == 1);
379+
EXPECT_FALSE(ToImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
380+
}
381+
356382
TEST(Decl, NoProtoFunctionDeclAttributes) {
357383
llvm::Annotations Code(R"(
358384
void f();

0 commit comments

Comments
 (0)