]> granicus.if.org Git - clang/commitdiff
Front-end support for __attribute__((may_alias)). This is not
authorDan Gohman <gohman@apple.com>
Wed, 17 Nov 2010 00:03:07 +0000 (00:03 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 17 Nov 2010 00:03:07 +0000 (00:03 +0000)
yet hooked up to anything yet.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119407 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Attr.td
include/clang/Sema/AttributeList.h
lib/Sema/AttributeList.cpp
lib/Sema/SemaDeclAttr.cpp

index 506f76f004d9a044bf405b9b898b8a2600e3a6e5..b01a6b1a7d62f72488385ea203c150b06ab5f597 100644 (file)
@@ -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">];
index 577b7edc89ed6e6e185bc7c0c6246e621a29ad5f..bdb756b329c220aa5bef3ef35f6f693b93bd5923 100644 (file)
@@ -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.
index 87639e017eedc7ec069c98c5b287067d9c9dad7f..4faa67223c36253a8cbbb7ac57a0d24648b10c8e 100644 (file)
@@ -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)
index 439ce531e64a6068619db2f6fe946b69342ffc0e..d66ae0a554b6bcc483c0ce963f93f38e1e8fba5e 100644 (file)
@@ -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<TypeDecl>(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: