Start of a Sema implementation for #pragma weak.  This isn't really the
right approach, but I'm still not sure what the best way to go about this is.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72912 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 41e73c1..4b9b703 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -131,6 +131,8 @@
 
 def warn_pragma_unused_expected_localvar : Warning<
   "only local variables can be arguments to '#pragma unused'">;
+def err_unsupported_pragma_weak : Error<
+  "using '#pragma weak' to refer to an undeclared identifier is not yet supported">;
 
 /// Objective-C parser diagnostics
 def err_duplicate_class_def : Error<
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index d8cc01e..fef476f 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -2449,7 +2449,19 @@
                                  SourceLocation PragmaLoc, 
                                  SourceLocation LParenLoc,
                                  SourceLocation RParenLoc);
-  
+
+  /// ActOnPragmaPack - Called on well formed #pragma weak ident.
+  virtual void ActOnPragmaWeakID(IdentifierInfo* WeakName,
+                                 SourceLocation PragmaLoc,
+                                 SourceLocation WeakNameLoc);
+
+  /// ActOnPragmaPack - Called on well formed #pragma weak ident = ident.
+  virtual void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
+                                    IdentifierInfo* AliasName,
+                                    SourceLocation PragmaLoc,
+                                    SourceLocation WeakNameLoc,
+                                    SourceLocation AliasNameLoc);
+
   /// getPragmaPackAlignment() - Return the current alignment as specified by
   /// the current #pragma pack directive, or 0 if none is currently active.
   unsigned getPragmaPackAlignment() const;
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index a39ff47..18636a4 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -4414,3 +4414,33 @@
   CurContext->addDecl(Context, New);
   return DeclPtrTy::make(New);
 }
+
+void Sema::ActOnPragmaWeakID(IdentifierInfo* Name,
+                             SourceLocation PragmaLoc,
+                             SourceLocation NameLoc) {
+  Decl *PrevDecl = LookupName(TUScope, Name, LookupOrdinaryName);
+
+  // FIXME: This implementation is an ugly hack!
+  if (PrevDecl) {
+    PrevDecl->addAttr(::new (Context) WeakAttr());
+    return;
+  }
+  Diag(PragmaLoc, diag::err_unsupported_pragma_weak);
+  return;
+}
+
+void Sema::ActOnPragmaWeakAlias(IdentifierInfo* Name,
+                                IdentifierInfo* AliasName,
+                                SourceLocation PragmaLoc,
+                                SourceLocation NameLoc,
+                                SourceLocation AliasNameLoc) {
+  Decl *PrevDecl = LookupName(TUScope, Name, LookupOrdinaryName);
+
+  // FIXME: This implementation is an ugly hack!
+  if (PrevDecl) {
+    PrevDecl->addAttr(::new (Context) AliasAttr(AliasName->getName()));
+    return;
+  }
+  Diag(PragmaLoc, diag::err_unsupported_pragma_weak);
+  return;
+}