implement the alias attirbute (in both Sema and Codegen)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52092 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index f91cbf4..a86bc6b 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -319,6 +319,7 @@
void HandleExtVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr);
void HandleAlignedAttribute(Decl *d, AttributeList *rawAttr);
+ void HandleAliasAttribute(Decl *d, AttributeList *rawAttr);
void HandlePackedAttribute(Decl *d, AttributeList *rawAttr);
void HandleAnnotateAttribute(Decl *d, AttributeList *rawAttr);
void HandleNoReturnAttribute(Decl *d, AttributeList *rawAttr);
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index b56622c..ed34f9f 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2250,6 +2250,9 @@
}
// FIXME: Diagnostic?
break;
+ case AttributeList::AT_alias:
+ HandleAliasAttribute(New, Attr);
+ break;
case AttributeList::AT_deprecated:
HandleDeprecatedAttribute(New, Attr);
break;
@@ -2438,6 +2441,32 @@
rawAttr->getName()->getName());
}
+void Sema::HandleAliasAttribute(Decl *d, AttributeList *rawAttr) {
+ // check the attribute arguments.
+ if (rawAttr->getNumArgs() != 1) {
+ Diag(rawAttr->getLoc(), diag::err_attribute_wrong_number_arguments,
+ std::string("1"));
+ return;
+ }
+
+ Expr *Arg = static_cast<Expr*>(rawAttr->getArg(0));
+ Arg = Arg->IgnoreParenCasts();
+ StringLiteral *Str = dyn_cast<StringLiteral>(Arg);
+
+ if (Str == 0 || Str->isWide()) {
+ Diag(rawAttr->getLoc(), diag::err_attribute_argument_n_not_string,
+ "alias", std::string("1"));
+ return;
+ }
+
+ const char *Alias = Str->getStrData();
+ unsigned AliasLen = Str->getByteLength();
+
+ // FIXME: check if target symbol exists in current file
+
+ d->addAttr(new AliasAttr(std::string(Alias, AliasLen)));
+}
+
void Sema::HandleNoReturnAttribute(Decl *d, AttributeList *rawAttr) {
// check the attribute arguments.
if (rawAttr->getNumArgs() != 0) {