PR3575 - warn on declared variable or function attributes after a definition, which are currently ignored.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77095 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 07e1ce7..0f4e9a4 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2085,6 +2085,15 @@
 
   CheckVariableDeclaration(NewVD, PrevDecl, Redeclaration);
 
+  // attributes declared post-definition are currently ignored
+  if (PrevDecl) {
+    const VarDecl *Def = 0, *PrevVD = dyn_cast<VarDecl>(PrevDecl);
+    if (PrevVD->getDefinition(Def) && D.hasAttributes()) {
+      Diag(NewVD->getLocation(), diag::warn_attribute_precede_definition);
+      Diag(Def->getLocation(), diag::note_previous_definition);
+    }
+  }
+
   // If this is a locally-scoped extern C variable, update the map of
   // such variables.
   if (CurContext->isFunctionOrMethod() && NewVD->isExternC(Context) &&
@@ -2582,6 +2591,16 @@
   // FIXME: This needs to happen before we merge declarations. Then,
   // let attribute merging cope with attribute conflicts.
   ProcessDeclAttributes(S, NewFD, D);
+
+  // attributes declared post-definition are currently ignored
+  if (PrevDecl) {
+    const FunctionDecl *Def, *PrevFD = dyn_cast<FunctionDecl>(PrevDecl);
+    if (PrevFD && PrevFD->getBody(Def) && D.hasAttributes()) {
+      Diag(NewFD->getLocation(), diag::warn_attribute_precede_definition);
+      Diag(Def->getLocation(), diag::note_previous_definition);
+    }
+  }
+
   AddKnownFunctionAttributes(NewFD);
 
   if (OverloadableAttrRequired && !NewFD->getAttr<OverloadableAttr>()) {