]> granicus.if.org Git - clang/commitdiff
Consider used attributes in hidden decls.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 25 Oct 2013 01:28:12 +0000 (01:28 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 25 Oct 2013 01:28:12 +0000 (01:28 +0000)
Without this patch we would warn and fail to output the function in the test.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193388 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-unused-filescoped.cpp

index ba7892840608f79fe549f2109574409fd56a0de1..2edebaba343987ba9dd936ce91c78751b628b855 100644 (file)
@@ -2099,6 +2099,12 @@ static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old) {
 /// mergeDeclAttributes - Copy attributes from the Old decl to the New one.
 void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old,
                                AvailabilityMergeKind AMK) {
+  if (UsedAttr *OldAttr = Old->getMostRecentDecl()->getAttr<UsedAttr>()) {
+    UsedAttr *NewAttr = OldAttr->clone(Context);
+    NewAttr->setInherited(true);
+    New->addAttr(NewAttr);
+  }
+
   if (!Old->hasAttrs() && !New->hasAttrs())
     return;
 
@@ -2136,6 +2142,10 @@ void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old,
       }
     }
 
+    // Already handled.
+    if (isa<UsedAttr>(*i))
+      continue;
+
     if (mergeDeclAttribute(*this, New, *i, Override))
       foundAny = true;
   }
index 65f10e6695aa4c7e0b2b68aa446eef7408deeb88..b0af5b33227069d853a336af3fc1d79f765d4f2e 100644 (file)
@@ -187,4 +187,10 @@ namespace UndefinedInternalStaticMember {
   }
 }
 
+namespace test8 {
+static void func();
+void bar() { void func() __attribute__((used)); }
+static void func() {}
+}
+
 #endif