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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Tue May 28 20:52:16 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)))
----------------
efriedma-quic wrote:

No, I mean, please make sure we don't emit an available_externally definition in that case.

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


More information about the cfe-commits mailing list