[clang] 1fec981 - [C++20] [Modules] Skip ODR checks in implicit global modules

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 5 02:02:23 PDT 2024


Author: Chuanqi Xu
Date: 2024-08-05T17:01:24+08:00
New Revision: 1fec981b67ac57abd4d8defd73beb5a9433c602f

URL: https://github.com/llvm/llvm-project/commit/1fec981b67ac57abd4d8defd73beb5a9433c602f
DIFF: https://github.com/llvm/llvm-project/commit/1fec981b67ac57abd4d8defd73beb5a9433c602f.diff

LOG: [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.

Added: 
    

Modified: 
    clang/include/clang/AST/DeclBase.h
    clang/include/clang/Serialization/ASTReader.h
    clang/lib/AST/DeclBase.cpp
    clang/test/Modules/skip-odr-check-in-gmf.cppm

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 40f01abf384e9..58f0aaba93b71 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -673,6 +673,9 @@ class alignas(8) Decl {
   /// Whether this declaration comes from explicit global module.
   bool isFromExplicitGlobalModule() const;
 
+  /// Whether this declaration comes from global module.
+  bool isFromGlobalModule() const;
+
   /// Whether this declaration comes from a named module.
   bool isInNamedModule() const;
 

diff  --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h
index 76e51ac7ab979..1ae1bf8ec7957 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -2478,7 +2478,7 @@ class BitsUnpacker {
 
 inline bool shouldSkipCheckingODR(const Decl *D) {
   return D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
-         D->isFromExplicitGlobalModule();
+         D->isFromGlobalModule();
 }
 
 } // namespace clang

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index a1f70546bde42..98a7746b7d997 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1144,6 +1144,10 @@ bool Decl::isFromExplicitGlobalModule() const {
   return getOwningModule() && getOwningModule()->isExplicitGlobalModule();
 }
 
+bool Decl::isFromGlobalModule() const {
+  return getOwningModule() && getOwningModule()->isGlobalModule();
+}
+
 bool Decl::isInNamedModule() const {
   return getOwningModule() && getOwningModule()->isNamedModule();
 }

diff  --git a/clang/test/Modules/skip-odr-check-in-gmf.cppm b/clang/test/Modules/skip-odr-check-in-gmf.cppm
index 3ee7d09224bfa..4a6003287a39a 100644
--- a/clang/test/Modules/skip-odr-check-in-gmf.cppm
+++ b/clang/test/Modules/skip-odr-check-in-gmf.cppm
@@ -35,17 +35,21 @@ module;
 export module a;
 export using ::func;
 
+export extern "C++" bool func1() { return true; }
+
 //--- b.cppm
 module;
 #include "func2.h"
 export module b;
 export using ::func;
 
+export extern "C++" bool func1() { return false; }
+
 //--- test.cc
 import a;
 import b;
 bool test() {
-    return func(1, 2);
+    return func(1, 2) && func1();
 }
 
 #ifdef IGNORE_ODR_VIOLATION
@@ -53,4 +57,6 @@ bool test() {
 #else
 // expected-error at func2.h:1 {{'func' has 
diff erent definitions in 
diff erent modules;}}
 // expected-note at func1.h:1 {{but in 'a.<global>' found a 
diff erent body}}
+// expected-error at b.cppm:6 {{'func1' has 
diff erent definitions in 
diff erent modules; definition in module 'b.<implicit global>' first 
diff erence is function body}}
+// expected-note at a.cppm:6 {{but in 'a.<implicit global>' found a 
diff erent body}}
 #endif


        


More information about the cfe-commits mailing list