[clang] [C++20] [Modules] Don't generate the defintition for non-const available external variables (PR #93530)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Tue May 28 22:18:01 PDT 2024


================
@@ -5341,6 +5341,15 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
       !IsDefinitionAvailableExternally &&
       D->needsDestruction(getContext()) == QualType::DK_cxx_destructor;
 
+  // It is helpless to emit the definition for an available_externally variable
+  // which can't be marked as const.
+  // We don't need to check if it needs global ctor or dtor. See the above
+  // comment for ideas.
+  if (IsDefinitionAvailableExternally &&
+      (!D->hasConstantInitialization() ||
+       !D->getType().isConstantStorage(getContext(), true, true)))
----------------
ChuanqiXu9 wrote:

Got it. Makes sense. Done.

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


More information about the cfe-commits mailing list