Skip to content

Commit f3f9c3f

Browse files
ChuanqiXu9Shivam Gupta
authored and
Shivam Gupta
committed
[C++20] [Modules] Don't perform ODR checks in GMF
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.
1 parent 9b4f604 commit f3f9c3f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,9 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
532532
EnumDeclBits.addBit(D->isFixed());
533533
Record.push_back(EnumDeclBits);
534534

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

537539
if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
538540
Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
@@ -549,7 +551,7 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
549551
!D->isTopLevelDeclInObjCContainer() &&
550552
!CXXRecordDecl::classofKind(D->getKind()) &&
551553
!D->getIntegerTypeSourceInfo() && !D->getMemberSpecializationInfo() &&
552-
!needsAnonymousDeclarationNumber(D) &&
554+
!needsAnonymousDeclarationNumber(D) && !isFromExplicitGMF(D) &&
553555
D->getDeclName().getNameKind() == DeclarationName::Identifier)
554556
AbbrevToUse = Writer.getDeclEnumAbbrev();
555557

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

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

745749
if (D->isDefaulted() || D->isDeletedAsWritten()) {
746750
if (auto *FDI = D->getDefalutedOrDeletedInfo()) {
@@ -1558,7 +1562,8 @@ void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
15581562
D->getFirstDecl() == D->getMostRecentDecl() && !D->isInvalidDecl() &&
15591563
!D->hasAttrs() && !D->isTopLevelDeclInObjCContainer() &&
15601564
D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1561-
!D->hasExtInfo() && !D->isExplicitlyDefaulted()) {
1565+
!isFromExplicitGMF(D) && !D->hasExtInfo() &&
1566+
!D->isExplicitlyDefaulted()) {
15621567
if (D->getTemplatedKind() == FunctionDecl::TK_NonTemplate ||
15631568
D->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate ||
15641569
D->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization ||

0 commit comments

Comments
 (0)