diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 0ad807cca36c7..3c2c7575ed998 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14363,8 +14363,8 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { bool MSVCEnv = Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment(); std::optional Reason; - if (var->hasInit() && HasConstInit && !(Reason = - var->getType().isNonConstantStorage(Context, true, false))) { + if (HasConstInit && + !(Reason = var->getType().isNonConstantStorage(Context, true, false))) { Stack = &ConstSegStack; } else { SectionFlags |= ASTContext::PSF_Write; diff --git a/clang/test/Sema/attr-section.c b/clang/test/Sema/attr-section.c index 1f058c24f980f..2f9ac2f1ce944 100644 --- a/clang/test/Sema/attr-section.c +++ b/clang/test/Sema/attr-section.c @@ -28,6 +28,9 @@ extern int a __attribute__((section("foo,zed"))); // expected-warning {{section int c; int c __attribute__((section("seg1,sec1"))); +const int with_init __attribute__((section("init_mix,x"))) = 1; +const int no_init __attribute__((section("init_mix,x"))); + // Also OK. struct r_debug {}; extern struct r_debug _r_debug;