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

llvm-svn: 314939
This commit is contained in:
Erich Keane 2017-10-04 22:16:24 +00:00
parent 005b88c0a6
commit 95be5d2e49
2 changed files with 10 additions and 1 deletions

View File

@ -2627,7 +2627,7 @@ void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old,
// This redeclaration adds a section attribute.
if (New->hasAttr<SectionAttr>() && !Old->hasAttr<SectionAttr>()) {
if (auto *VD = dyn_cast<VarDecl>(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);
}

View File

@ -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")));