Skip to content

Commit

Permalink
[clangd] Fix C++20 modules crash
Browse files Browse the repository at this point in the history
This fix partially reverts llvm@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 llvm#80570.
  • Loading branch information
CLRN committed Feb 15, 2024
1 parent 235ec0f commit dae725e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
21 changes: 7 additions & 14 deletions clang/lib/Serialization/ASTReaderDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,8 @@ void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
ED->setScopedUsingClassTag(EnumDeclBits.getNextBit());
ED->setFixed(EnumDeclBits.getNextBit());

if (!shouldSkipCheckingODR(ED)) {
ED->setHasODRHash(true);
ED->ODRHash = Record.readInt();
}
ED->setHasODRHash(true);
ED->ODRHash = Record.readInt();

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

if (!shouldSkipCheckingODR(FD)) {
FD->ODRHash = Record.readInt();
FD->setHasODRHash(true);
}
FD->ODRHash = Record.readInt();
FD->setHasODRHash(true);

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

// We only perform ODR checks for decls not in GMF.
if (!shouldSkipCheckingODR(D)) {
// Note: the caller has deserialized the IsLambda bit already.
Data.ODRHash = Record.readInt();
Data.HasODRHash = true;
}
// Note: the caller has deserialized the IsLambda bit already.
Data.ODRHash = Record.readInt();
Data.HasODRHash = true;

if (Record.readInt()) {
Reader.DefinitionSource[D] =
Expand Down
9 changes: 3 additions & 6 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6068,12 +6068,9 @@ void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {

Record->push_back(DefinitionBits);

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

bool ModulesDebugInfo =
Writer->Context->getLangOpts().ModulesDebugInfo && !D->isDependentType();
Expand Down
8 changes: 2 additions & 6 deletions clang/lib/Serialization/ASTWriterDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,7 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
EnumDeclBits.addBit(D->isFixed());
Record.push_back(EnumDeclBits);

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

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

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

if (D->isDefaulted()) {
if (auto *FDI = D->getDefaultedFunctionInfo()) {
Expand Down

0 comments on commit dae725e

Please sign in to comment.