Skip to content

Commit dae725e

Browse files
committed
[clangd] Fix C++20 modules crash
This fix partially reverts a0b6747. The serialization part is restored to the state prior to the mentioned commit as it causing issue with reading back Decl. ODR checks logic is kept in place. Close #80570.
1 parent 235ec0f commit dae725e

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,8 @@ void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
804804
ED->setScopedUsingClassTag(EnumDeclBits.getNextBit());
805805
ED->setFixed(EnumDeclBits.getNextBit());
806806

807-
if (!shouldSkipCheckingODR(ED)) {
808-
ED->setHasODRHash(true);
809-
ED->ODRHash = Record.readInt();
810-
}
807+
ED->setHasODRHash(true);
808+
ED->ODRHash = Record.readInt();
811809

812810
// If this is a definition subject to the ODR, and we already have a
813811
// definition, merge this one into it.
@@ -1102,10 +1100,8 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
11021100
if (FD->isExplicitlyDefaulted())
11031101
FD->setDefaultLoc(readSourceLocation());
11041102

1105-
if (!shouldSkipCheckingODR(FD)) {
1106-
FD->ODRHash = Record.readInt();
1107-
FD->setHasODRHash(true);
1108-
}
1103+
FD->ODRHash = Record.readInt();
1104+
FD->setHasODRHash(true);
11091105

11101106
if (FD->isDefaulted()) {
11111107
if (unsigned NumLookups = Record.readInt()) {
@@ -1981,12 +1977,9 @@ void ASTDeclReader::ReadCXXDefinitionData(
19811977
#include "clang/AST/CXXRecordDeclDefinitionBits.def"
19821978
#undef FIELD
19831979

1984-
// We only perform ODR checks for decls not in GMF.
1985-
if (!shouldSkipCheckingODR(D)) {
1986-
// Note: the caller has deserialized the IsLambda bit already.
1987-
Data.ODRHash = Record.readInt();
1988-
Data.HasODRHash = true;
1989-
}
1980+
// Note: the caller has deserialized the IsLambda bit already.
1981+
Data.ODRHash = Record.readInt();
1982+
Data.HasODRHash = true;
19901983

19911984
if (Record.readInt()) {
19921985
Reader.DefinitionSource[D] =

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6068,12 +6068,9 @@ void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {
60686068

60696069
Record->push_back(DefinitionBits);
60706070

6071-
// We only perform ODR checks for decls not in GMF.
6072-
if (!shouldSkipCheckingODR(D)) {
6073-
// getODRHash will compute the ODRHash if it has not been previously
6074-
// computed.
6075-
Record->push_back(D->getODRHash());
6076-
}
6071+
// getODRHash will compute the ODRHash if it has not been previously
6072+
// computed.
6073+
Record->push_back(D->getODRHash());
60776074

60786075
bool ModulesDebugInfo =
60796076
Writer->Context->getLangOpts().ModulesDebugInfo && !D->isDependentType();

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,7 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
493493
EnumDeclBits.addBit(D->isFixed());
494494
Record.push_back(EnumDeclBits);
495495

496-
// We only perform ODR checks for decls not in GMF.
497-
if (!shouldSkipCheckingODR(D))
498-
Record.push_back(D->getODRHash());
496+
Record.push_back(D->getODRHash());
499497

500498
if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
501499
Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
@@ -703,9 +701,7 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
703701
if (D->isExplicitlyDefaulted())
704702
Record.AddSourceLocation(D->getDefaultLoc());
705703

706-
// We only perform ODR checks for decls not in GMF.
707-
if (!shouldSkipCheckingODR(D))
708-
Record.push_back(D->getODRHash());
704+
Record.push_back(D->getODRHash());
709705

710706
if (D->isDefaulted()) {
711707
if (auto *FDI = D->getDefaultedFunctionInfo()) {

0 commit comments

Comments
 (0)