[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 30 18:38:04 PST 2024


================
@@ -457,6 +457,28 @@ Note that **currently** the compiler doesn't consider inconsistent macro definit
 Currently Clang would accept the above example. But it may produce surprising results if the
 debugging code depends on consistent use of ``NDEBUG`` also in other translation units.
 
+Definitions consistency
+^^^^^^^^^^^^^^^^^^^^^^^
+
+The C++ language defines that same declarations in different translation units should have
+the same definition, as known as ODR (One Definition Rule). Prior to modules, the translation
+units don't dependent on each other and the compiler itself don't and can't perform a strong
+ODR violation check. Sometimes it is the linker does some jobs related to ODR, where the
+higher level semantics are missing. With the introduction of modules, now the compiler have
+the chance to perform ODR violations with language semantics across translation units.
+
+However, in the practice we found the existing ODR checking mechanism may be too aggressive.
+In the many issue reports about ODR violation diagnostics, most of them are false positive
+ODR violations and the true positive ODR violations are rarely reported. Also MSVC don't
+perform ODR check for declarations in the global module fragment.
+
+So in order to get better user experience, save the time checking ODR and keep consistent
+behavior with MSVC, we disabled the ODR check for the declarations in the global module
+fragment by default. Users who want more strict check can still use the
+``-Xclang -fno-skip-odr-check-in-gmf`` flag to get the ODR check enabled. It is also
+encouraged to report issues if users find false positive ODR violations or false negative ODR
+violations with the flag enabled.
----------------
ChuanqiXu9 wrote:

My thought for writing this paragraph is:
1. The most important reason is to get better user experience. This is the major and the most important motivation.
2. Saving compilation time is the benefit we got after making this decision. And we can mention it to say something is getting better in some degree and under some conditions (the existing ODR checker is not good enough).
3. Keep consistent behavior with MSVC. This is a supporting argument. And we can find that this is the least important thing from the order. This shouldn't be a blocker if someday we think the ODR checker is good enough and want to enable the ODR checker by default.

I can understand your concerning totally. This is not a document for teaching developers. This document is for users. I feel it will be better to write the document in the current way to make the users to understand what's happening.

https://github.com/llvm/llvm-project/pull/79959


More information about the cfe-commits mailing list