From 2c4bc52489de4075b24e275eec58f2ec4788666e Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Wed, 4 Oct 2017 22:16:24 +0000 Subject: [PATCH] Fix 'section' warning behavior with tentatively-defined values As reported on cfe-commits, r314262 resulted in tentatively-defined variables not being excluded for the warning. Patch By: Elizabeth Andrews git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314939 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 2 +- test/Sema/attr-section.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7f3f811002..48fb2318e6 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/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/test/Sema/attr-section.c b/test/Sema/attr-section.c index 2fb4dbd6bf..b361738e8e 100644 --- a/test/Sema/attr-section.c +++ b/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"))); -- 2.40.0