Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 2c4bc52

Browse files
author
Erich Keane
committed
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
1 parent 8dd6284 commit 2c4bc52

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: lib/Sema/SemaDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,7 @@ void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old,
26272627
// This redeclaration adds a section attribute.
26282628
if (New->hasAttr<SectionAttr>() && !Old->hasAttr<SectionAttr>()) {
26292629
if (auto *VD = dyn_cast<VarDecl>(New)) {
2630-
if (VD->isThisDeclarationADefinition() != VarDecl::Definition) {
2630+
if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly) {
26312631
Diag(New->getLocation(), diag::warn_attribute_section_on_redeclaration);
26322632
Diag(Old->getLocation(), diag::note_previous_declaration);
26332633
}

Diff for: test/Sema/attr-section.c

+9
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ enum __attribute__((section("NEAR,x"))) e { one }; // expected-error {{'section'
2323
extern int a; // expected-note {{previous declaration is here}}
2424
int *b = &a;
2525
extern int a __attribute__((section("foo,zed"))); // expected-warning {{section attribute is specified on redeclared variable}}
26+
27+
// Not a warning.
28+
int c;
29+
int c __attribute__((section("foo,zed")));
30+
31+
// Also OK.
32+
struct r_debug {};
33+
extern struct r_debug _r_debug;
34+
struct r_debug _r_debug __attribute__((nocommon, section(".r_debug,bar")));

0 commit comments

Comments
 (0)