r193388 - Consider used attributes in hidden decls.

Rafael Espindola rafael.espindola at gmail.com
Thu Oct 24 18:28:12 PDT 2013


Author: rafael
Date: Thu Oct 24 20:28:12 2013
New Revision: 193388

URL: http://llvm.org/viewvc/llvm-project?rev=193388&view=rev
Log:
Consider used attributes in hidden decls.

Without this patch we would warn and fail to output the function in the test.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=193388&r1=193387&r2=193388&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct 24 20:28:12 2013
@@ -2099,6 +2099,12 @@ static void checkNewAttributesAfterDef(S
 /// 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
       }
     }
 
+    // Already handled.
+    if (isa<UsedAttr>(*i))
+      continue;
+
     if (mergeDeclAttribute(*this, New, *i, Override))
       foundAny = true;
   }

Modified: cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp?rev=193388&r1=193387&r2=193388&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp Thu Oct 24 20:28:12 2013
@@ -187,4 +187,10 @@ namespace UndefinedInternalStaticMember
   }
 }
 
+namespace test8 {
+static void func();
+void bar() { void func() __attribute__((used)); }
+static void func() {}
+}
+
 #endif





More information about the cfe-commits mailing list