Skip to content

Commit 1fec981

Browse files
committed
[C++20] [Modules] Skip ODR checks in implicit global modules
Previously we skipped the ODR checks in explicit global modules. And due to similar reasons, we should skip the ODR checks in implicit global modules too.
1 parent 7536ebf commit 1fec981

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

clang/include/clang/AST/DeclBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,9 @@ class alignas(8) Decl {
673673
/// Whether this declaration comes from explicit global module.
674674
bool isFromExplicitGlobalModule() const;
675675

676+
/// Whether this declaration comes from global module.
677+
bool isFromGlobalModule() const;
678+
676679
/// Whether this declaration comes from a named module.
677680
bool isInNamedModule() const;
678681

clang/include/clang/Serialization/ASTReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2478,7 +2478,7 @@ class BitsUnpacker {
24782478

24792479
inline bool shouldSkipCheckingODR(const Decl *D) {
24802480
return D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
2481-
D->isFromExplicitGlobalModule();
2481+
D->isFromGlobalModule();
24822482
}
24832483

24842484
} // namespace clang

clang/lib/AST/DeclBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,10 @@ bool Decl::isFromExplicitGlobalModule() const {
11441144
return getOwningModule() && getOwningModule()->isExplicitGlobalModule();
11451145
}
11461146

1147+
bool Decl::isFromGlobalModule() const {
1148+
return getOwningModule() && getOwningModule()->isGlobalModule();
1149+
}
1150+
11471151
bool Decl::isInNamedModule() const {
11481152
return getOwningModule() && getOwningModule()->isNamedModule();
11491153
}

clang/test/Modules/skip-odr-check-in-gmf.cppm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,28 @@ module;
3535
export module a;
3636
export using ::func;
3737

38+
export extern "C++" bool func1() { return true; }
39+
3840
//--- b.cppm
3941
module;
4042
#include "func2.h"
4143
export module b;
4244
export using ::func;
4345

46+
export extern "C++" bool func1() { return false; }
47+
4448
//--- test.cc
4549
import a;
4650
import b;
4751
bool test() {
48-
return func(1, 2);
52+
return func(1, 2) && func1();
4953
}
5054

5155
#ifdef IGNORE_ODR_VIOLATION
5256
// expected-no-diagnostics
5357
#else
5458
// [email protected]:1 {{'func' has different definitions in different modules;}}
5559
// [email protected]:1 {{but in 'a.<global>' found a different body}}
60+
// [email protected]:6 {{'func1' has different definitions in different modules; definition in module 'b.<implicit global>' first difference is function body}}
61+
// [email protected]:6 {{but in 'a.<implicit global>' found a different body}}
5662
#endif

0 commit comments

Comments
 (0)