diff options
author | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2024-05-29 13:39:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 13:39:57 +0800 |
commit | b0f10a1dc34aa1b73faeeabdc2d348074a02c75d (patch) | |
tree | d592996874282d0529604f57be49e8fc14df1088 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 3613b2683107bd60fda6d9348623be0686f6d7e3 (diff) | |
download | llvm-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.cpp | 12 |
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); |