Skip to content

Commit c669eaf

Browse files
ChuanqiXu9xgupta
authored andcommitted
[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 dfb1734 commit c669eaf

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ C++20 Feature Support
251251
- User defined constructors are allowed for copy-list-initialization with CTAD.
252252
(#GH62925).
253253

254+
- Clang won't perform ODR checks for decls in the global module fragment any
255+
more to ease the implementation and improve the user's using experience.
256+
This follows the MSVC's behavior.
257+
(`#79240 <https://github.com/llvm/llvm-project/issues/79240>`_).
258+
254259
C++23 Feature Support
255260
^^^^^^^^^^^^^^^^^^^^^
256261

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)