From: Dan Gohman Date: Wed, 17 Nov 2010 00:03:07 +0000 (+0000) Subject: Front-end support for __attribute__((may_alias)). This is not X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34c26300b384286c544e0b9fd45e7a3648ac79e3;p=clang Front-end support for __attribute__((may_alias)). This is not yet hooked up to anything yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119407 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 506f76f004..b01a6b1a7d 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -241,6 +241,10 @@ def MaxFieldAlignment : Attr { let Args = [UnsignedArgument<"Alignment">]; } +def MayAlias : Attr { + let Spellings = ["may_alias"]; +} + def MSP430Interrupt : Attr { let Spellings = []; let Args = [UnsignedArgument<"Number">]; diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h index 577b7edc89..bdb756b329 100644 --- a/include/clang/Sema/AttributeList.h +++ b/include/clang/Sema/AttributeList.h @@ -105,6 +105,7 @@ public: AT_gnu_inline, AT_hiding, AT_malloc, + AT_may_alias, AT_mode, AT_neon_polyvector_type, // Clang-specific. AT_neon_vector_type, // Clang-specific. diff --git a/lib/Sema/AttributeList.cpp b/lib/Sema/AttributeList.cpp index 87639e017e..4faa67223c 100644 --- a/lib/Sema/AttributeList.cpp +++ b/lib/Sema/AttributeList.cpp @@ -83,7 +83,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { .Case("NSObject", AT_nsobject) .Case("dllimport", AT_dllimport) .Case("dllexport", AT_dllexport) - .Case("may_alias", IgnoredAttribute) // FIXME: TBAA + .Case("may_alias", AT_may_alias) .Case("base_check", AT_base_check) .Case("deprecated", AT_deprecated) .Case("visibility", AT_visibility) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 439ce531e6..d66ae0a554 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -731,6 +731,22 @@ static void HandleMallocAttr(Decl *d, const AttributeList &Attr, Sema &S) { S.Diag(Attr.getLoc(), diag::warn_attribute_malloc_pointer_only); } +static void HandleMayAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) { + // check the attribute arguments. + if (Attr.getNumArgs() != 0) { + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; + return; + } + + if (!isa(d)) { + S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) + << Attr.getName() << 2 /*variable and function*/; + return; + } + + d->addAttr(::new (S.Context) MayAliasAttr(Attr.getLoc(), S.Context)); +} + static void HandleNoReturnAttr(Decl *d, const AttributeList &Attr, Sema &S) { /* Diagnostics (if any) was emitted by Sema::ProcessFnAttr(). */ assert(Attr.isInvalid() == false); @@ -2361,6 +2377,7 @@ static void ProcessDeclAttribute(Scope *scope, Decl *D, case AttributeList::AT_hiding: HandleHidingAttr (D, Attr, S); break; case AttributeList::AT_mode: HandleModeAttr (D, Attr, S); break; case AttributeList::AT_malloc: HandleMallocAttr (D, Attr, S); break; + case AttributeList::AT_may_alias: HandleMayAliasAttr (D, Attr, S); break; case AttributeList::AT_nonnull: HandleNonNullAttr (D, Attr, S); break; case AttributeList::AT_ownership_returns: case AttributeList::AT_ownership_takes: