[PATCH] D119409: [C++20] [Modules] Remain variable's definition in module interface

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 13 19:35:36 PST 2022

ChuanqiXu added inline comments.

Comment at: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp:5
 // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global
-// CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @inline_var_exported = available_externally {{(dso_local )?}}global
 // CHECK-DAG: @const_var_exported = available_externally {{(dso_local )?}}constant i32 3,
urnathan wrote:
> I don;t think this is correct.  That should still be a linkonce odr, otherwise you'll get conflicts with other module implementation units.
It is still linkonce_odr in the module it get defined. See the new added test case: inline-variable-in-module.cpp for example. The attribute `available_externally` is equivalent to external from the perspective of linker. See https://llvm.org/docs/LangRef.html#linkage-types. According to [dcl.inline]p7, inline variable attached to named module should be defined in that domain. Note that the variable attached to global module fragment and private module fragment shouldn't be accessed outside the module, so it implies that all the variable defined in the module could only be defined in the module unit itself.

Comment at: clang/test/CodeGenCXX/static-variable-in-module.cpp:2-8
+// RUN: mkdir %t
+// RUN: echo "struct S { S(); };" >> %t/foo.h
+// RUN: echo "static S s = S();" >> %t/foo.h
+// RUN: %clang -std=c++20 -I%t %s -S -emit-llvm -o - | FileCheck %s
+#include "foo.h"
+export module m;
urnathan wrote:
> rather than generate a foo.h file, why not (ab)use the preprocessor with internal line directives?
> ```
> module;
> # 3 __FILE__ 1 // use the next physical line number here (and below)
> struct S { S(); };
> static S s = S();
> # 6 "" 2
> export module m;
> ...
> ```
Yeah, the form is useful when we need to add expected-* diagnostic message to GMF. But I feel it is a little bit hacker. I guess the form mimics looks like user more wouldn't be worse personally.



More information about the cfe-commits mailing list