]> granicus.if.org Git - clang/commitdiff
Fix 'section' warning behavior with tentatively-defined values
authorErich Keane <erich.keane@intel.com>
Wed, 4 Oct 2017 22:16:24 +0000 (22:16 +0000)
committerErich Keane <erich.keane@intel.com>
Wed, 4 Oct 2017 22:16:24 +0000 (22:16 +0000)
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
test/Sema/attr-section.c

index 7f3f81100292f6a3420dceb471c790cfcd5ddaf7..48fb2318e6125d993de1a4f5df24b7bb7b1170be 100644 (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);
       }
index 2fb4dbd6bfd7c3934893919f85ff0c535cd30e05..b361738e8e20c51992b03829529eb298ddf265f1 100644 (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")));