aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-05-29 13:39:57 +0800
committerGitHub <noreply@github.com>2024-05-29 13:39:57 +0800
commitb0f10a1dc34aa1b73faeeabdc2d348074a02c75d (patch)
treed592996874282d0529604f57be49e8fc14df1088 /clang/lib/CodeGen/CodeGenModule.cpp
parent3613b2683107bd60fda6d9348623be0686f6d7e3 (diff)
downloadllvm-b0f10a1dc34aa1b73faeeabdc2d348074a02c75d.zip
llvm-b0f10a1dc34aa1b73faeeabdc2d348074a02c75d.tar.gz
llvm-b0f10a1dc34aa1b73faeeabdc2d348074a02c75d.tar.bz2
[C++20] [Modules] Don't generate the defintition for non-const available external variables (#93530)
Close https://github.com/llvm/llvm-project/issues/93497 The root cause of the problem is, we mark the variable from other modules as constnant in LLVM incorrectly. This patch fixes this problem by not emitting the defintition for non-const available external variables. Since the non const available externally variable is not helpful to the optimization.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index e4774a5..0b0b659 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5341,6 +5341,18 @@ 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() ||
+ // TODO: Update this when we have interface to check constexpr
+ // destructor.
+ D->needsDestruction(getContext()) ||
+ !D->getType().isConstantStorage(getContext(), true, true)))
+ return;
+
const VarDecl *InitDecl;
const Expr *InitExpr = D->getAnyInitializer(InitDecl);