Add r168519 back, but with a fix to also merge the used flag in variables.
authorRafael Espindola <rafael.espindola@gmail.com>
Sun, 25 Nov 2012 14:07:59 +0000 (14:07 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sun, 25 Nov 2012 14:07:59 +0000 (14:07 +0000)
llvm-svn: 168564

clang/lib/AST/DeclBase.cpp
clang/lib/Sema/SemaDecl.cpp

index 7b20e77..b04c149 100644 (file)
@@ -261,13 +261,6 @@ bool Decl::isUsed(bool CheckUsedAttr) const {
   if (CheckUsedAttr && hasAttr<UsedAttr>())
     return true;
 
-  // Check redeclarations. We merge attributes, so we don't need to check
-  // attributes in all redeclarations.
-  for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) {
-    if (I->Used)
-      return true;
-  }
-
   return false; 
 }
 
index 629fccc..6a9065e 100644 (file)
@@ -2388,6 +2388,10 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
   if (Old->isPure())
     New->setPure();
 
+  // Merge "used" flag.
+  if (Old->isUsed(false))
+    New->setUsed();
+
   // Merge attributes from the parameters.  These can mismatch with K&R
   // declarations.
   if (New->getNumParams() == Old->getNumParams())
@@ -2613,6 +2617,10 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
       New->getDeclContext() == Old->getDeclContext())
     New->setStorageClass(Old->getStorageClass());
 
+  // Merge "used" flag.
+  if (Old->isUsed(false))
+    New->setUsed();
+
   // Keep a chain of previous declarations.
   New->setPreviousDeclaration(Old);