[clang] [Sema] Don't call isNonConstantStorage on incomplete variable types (PR #161590)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 1 15:09:14 PDT 2025
================
@@ -14918,52 +14918,57 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
}
// Apply section attributes and pragmas to global variables.
- if (GlobalStorage && var->isThisDeclarationADefinition() &&
- !inTemplateInstantiation()) {
- PragmaStack<StringLiteral *> *Stack = nullptr;
- int SectionFlags = ASTContext::PSF_Read;
- bool MSVCEnv =
- Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment();
- std::optional<QualType::NonConstantStorageReason> Reason;
- if (HasConstInit &&
- !(Reason = var->getType().isNonConstantStorage(Context, true, false))) {
- Stack = &ConstSegStack;
- } else {
- SectionFlags |= ASTContext::PSF_Write;
- Stack = var->hasInit() && HasConstInit ? &DataSegStack : &BSSSegStack;
- }
- if (const SectionAttr *SA = var->getAttr<SectionAttr>()) {
- if (SA->getSyntax() == AttributeCommonInfo::AS_Declspec)
+ [&]() {
+ if (GlobalStorage && var->isThisDeclarationADefinition() &&
+ !inTemplateInstantiation()) {
+ PragmaStack<StringLiteral *> *Stack = nullptr;
+ int SectionFlags = ASTContext::PSF_Read;
+ bool MSVCEnv =
+ Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment();
+ std::optional<QualType::NonConstantStorageReason> Reason;
+ if (HasConstInit && var->getType()->isIncompleteType())
+ return;
----------------
efriedma-quic wrote:
This doesn't seem like it's quite the right thing to check; we shouldn't be be trying to compute the section at all for a definition inside a templated class/function, no matter what the type is.
https://github.com/llvm/llvm-project/pull/161590
More information about the cfe-commits
mailing list