Skip to content

Commit

Permalink
[C++20] [Modules] Don't perform ODR checks in GMF
Browse files Browse the repository at this point in the history
Close llvm#79240.

See the linked issue for details. Given the frequency of issue reporting
about false positive ODR checks (I received private issue reports too),
I'd like to backport this to 18.x too.
  • Loading branch information
ChuanqiXu9 authored and Shivam Gupta committed Sep 5, 2024
1 parent 7fe1d55 commit b33fcf6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions clang/lib/Serialization/ASTWriterDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,9 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
EnumDeclBits.addBit(D->isFixed());
Record.push_back(EnumDeclBits);

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

if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
Expand All @@ -549,7 +551,7 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
!D->isTopLevelDeclInObjCContainer() &&
!CXXRecordDecl::classofKind(D->getKind()) &&
!D->getIntegerTypeSourceInfo() && !D->getMemberSpecializationInfo() &&
!needsAnonymousDeclarationNumber(D) &&
!needsAnonymousDeclarationNumber(D) && !isFromExplicitGMF(D) &&
D->getDeclName().getNameKind() == DeclarationName::Identifier)
AbbrevToUse = Writer.getDeclEnumAbbrev();

Expand Down Expand Up @@ -740,7 +742,9 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
if (D->isExplicitlyDefaulted())
Record.AddSourceLocation(D->getDefaultLoc());

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

if (D->isDefaulted() || D->isDeletedAsWritten()) {
if (auto *FDI = D->getDefalutedOrDeletedInfo()) {
Expand Down Expand Up @@ -1558,7 +1562,8 @@ void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
D->getFirstDecl() == D->getMostRecentDecl() && !D->isInvalidDecl() &&
!D->hasAttrs() && !D->isTopLevelDeclInObjCContainer() &&
D->getDeclName().getNameKind() == DeclarationName::Identifier &&
!D->hasExtInfo() && !D->isExplicitlyDefaulted()) {
!isFromExplicitGMF(D) && !D->hasExtInfo() &&
!D->isExplicitlyDefaulted()) {
if (D->getTemplatedKind() == FunctionDecl::TK_NonTemplate ||
D->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate ||
D->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization ||
Expand Down

0 comments on commit b33fcf6

Please sign in to comment.