Skip to content

Commit 91c4b55

Browse files
committed
[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
1 parent 0e17372 commit 91c4b55

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
@@ -177,6 +177,9 @@ Bug Fixes to C++ Support
177177
requires-expression. This fixes:
178178
(`#64138 <https://github.com/llvm/llvm-project/issues/64138>`_).
179179

180+
- Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
181+
(`#64171 <https://github.com/llvm/llvm-project/issues/64171>`_).
182+
180183
Bug Fixes to AST Handling
181184
^^^^^^^^^^^^^^^^^^^^^^^^^
182185
- Fixed an import failure of recursive friend class template.

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
@@ -7832,6 +7832,47 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConstructorUsingShadow) {
78327832
CheckAST(ToTU, ToC);
78337833
}
78347834

7835+
TEST_P(ASTImporterOptionSpecificTestBase,
7836+
ImportFunctionDeclBitShouldNotOverwriteCtorDeclBits) {
7837+
Decl *From, *To;
7838+
std::tie(From, To) = getImportedDecl(
7839+
R"s(
7840+
struct A {
7841+
A() : m() {}
7842+
int m;
7843+
};
7844+
7845+
A foo() { A a; return a; }
7846+
A bar() { return {}; }
7847+
)s",
7848+
Lang_CXX17,
7849+
R"s(
7850+
struct A {
7851+
A() : m() {}
7852+
int m;
7853+
};
7854+
A baz() { return {}; }
7855+
)s",
7856+
Lang_CXX17, "A");
7857+
7858+
auto HasCtorInit =
7859+
hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
7860+
auto ImpMoveCtor =
7861+
cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit);
7862+
7863+
auto *FromImpMoveCtor = FirstDeclMatcher<CXXConstructorDecl>().match(
7864+
From, ImpMoveCtor);
7865+
auto *ToImpMoveCtor = FirstDeclMatcher<CXXConstructorDecl>().match(
7866+
To, ImpMoveCtor);
7867+
7868+
EXPECT_TRUE(FromImpMoveCtor->getNumCtorInitializers() == 1);
7869+
EXPECT_FALSE(FromImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
7870+
7871+
EXPECT_TRUE(ToImpMoveCtor->getNumCtorInitializers() == 1);
7872+
EXPECT_FALSE(ToImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
7873+
EXPECT_TRUE(*ToImpMoveCtor->init_begin());
7874+
}
7875+
78357876
AST_MATCHER_P(UsingShadowDecl, hasIntroducerDecl, internal::Matcher<NamedDecl>,
78367877
InnerMatcher) {
78377878
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)