diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 7f3f81100292..48fb2318e612 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2627,7 +2627,7 @@ void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old, // This redeclaration adds a section attribute. if (New->hasAttr() && !Old->hasAttr()) { if (auto *VD = dyn_cast(New)) { - if (VD->isThisDeclarationADefinition() != VarDecl::Definition) { + if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly) { Diag(New->getLocation(), diag::warn_attribute_section_on_redeclaration); Diag(Old->getLocation(), diag::note_previous_declaration); } diff --git a/clang/test/Sema/attr-section.c b/clang/test/Sema/attr-section.c index 2fb4dbd6bfd7..b361738e8e20 100644 --- a/clang/test/Sema/attr-section.c +++ b/clang/test/Sema/attr-section.c @@ -23,3 +23,12 @@ enum __attribute__((section("NEAR,x"))) e { one }; // expected-error {{'section' extern int a; // expected-note {{previous declaration is here}} int *b = &a; extern int a __attribute__((section("foo,zed"))); // expected-warning {{section attribute is specified on redeclared variable}} + +// Not a warning. +int c; +int c __attribute__((section("foo,zed"))); + +// Also OK. +struct r_debug {}; +extern struct r_debug _r_debug; +struct r_debug _r_debug __attribute__((nocommon, section(".r_debug,bar")));