[cfe-commits] r172626 - in /cfe/trunk: include/clang/Basic/Attr.td lib/CodeGen/TargetInfo.cpp lib/Sema/TargetAttributesSema.cpp test/Sema/mips16_attr_allowed.c test/Sema/mips16_attr_not_allowed.c

Reed Kotler rkotler at mips.com
Wed Jan 16 09:10:28 PST 2013


Author: rkotler
Date: Wed Jan 16 11:10:28 2013
New Revision: 172626

URL: http://llvm.org/viewvc/llvm-project?rev=172626&view=rev
Log:
First step in implementation of mips16 and nomips16 attributes.
Waiting for new llvm attribute code for the next step.


Added:
    cfe/trunk/test/Sema/mips16_attr_allowed.c
    cfe/trunk/test/Sema/mips16_attr_not_allowed.c
Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/lib/CodeGen/TargetInfo.cpp
    cfe/trunk/lib/Sema/TargetAttributesSema.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=172626&r1=172625&r2=172626&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Jan 16 11:10:28 2013
@@ -404,6 +404,11 @@
   let SemaHandler = 0;
 }
 
+def Mips16 : InheritableAttr {
+  let Spellings = [GNU<"mips16">, CXX11<"gnu", "mips16">];
+  let Subjects = [Function];
+}
+
 def Mode : Attr {
   let Spellings = [GNU<"mode">, CXX11<"gnu", "mode">];
   let Args = [IdentifierArgument<"Mode">];
@@ -442,6 +447,11 @@
   let Spellings = [GNU<"noinline">, CXX11<"gnu", "noinline">];
 }
 
+def NoMips16 : InheritableAttr {
+  let Spellings = [GNU<"nomips16">, CXX11<"gnu", "nomips16">];
+  let Subjects = [Function];
+}
+
 def NonNull : InheritableAttr {
   let Spellings = [GNU<"nonnull">, CXX11<"gnu", "nonnull">];
   let Args = [VariadicUnsignedArgument<"Args">];

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=172626&r1=172625&r2=172626&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Jan 16 11:10:28 2013
@@ -3884,6 +3884,13 @@
     return 29;
   }
 
+  void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+                           CodeGen::CodeGenModule &CGM) const {
+    //
+    // can fill this in when new attribute work in llvm is done.
+    // attributes mips16 and nomips16 need to be handled here.
+    //
+  }
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                llvm::Value *Address) const;
 

Modified: cfe/trunk/lib/Sema/TargetAttributesSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TargetAttributesSema.cpp?rev=172626&r1=172625&r2=172626&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TargetAttributesSema.cpp (original)
+++ cfe/trunk/lib/Sema/TargetAttributesSema.cpp Wed Jan 16 11:10:28 2013
@@ -262,6 +262,54 @@
   };
 }
 
+static void HandleMips16Attr(Decl *D, const AttributeList &Attr, Sema &S) {
+  // check the attribute arguments.
+  if (Attr.hasParameterOrArguments()) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+    return;
+  }
+  // Attribute can only be applied to function types.
+  if (!isa<FunctionDecl>(D)) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
+      << Attr.getName() << /* function */0;
+    return;
+  }
+  D->addAttr(::new (S.Context) Mips16Attr(Attr.getRange(), S.Context));
+}
+
+static void HandleNoMips16Attr(Decl *D, const AttributeList &Attr, Sema &S) {
+  // check the attribute arguments.
+  if (Attr.hasParameterOrArguments()) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+    return;
+  }
+  // Attribute can only be applied to function types.
+  if (!isa<FunctionDecl>(D)) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
+      << Attr.getName() << /* function */0;
+    return;
+  }
+  D->addAttr(::new (S.Context) NoMips16Attr(Attr.getRange(), S.Context));
+}
+
+namespace {
+  class MipsAttributesSema : public TargetAttributesSema {
+  public:
+    MipsAttributesSema() { }
+    bool ProcessDeclAttribute(Scope *scope, Decl *D, const AttributeList &Attr,
+                              Sema &S) const {
+      if (Attr.getName()->getName() == "mips16") {
+        HandleMips16Attr(D, Attr, S);
+        return true;
+      } else if (Attr.getName()->getName() == "nomips16") {
+        HandleNoMips16Attr(D, Attr, S);
+        return true;
+      }
+      return false;
+    }
+  };
+}
+
 const TargetAttributesSema &Sema::getTargetAttributesSema() const {
   if (TheTargetAttributesSema)
     return *TheTargetAttributesSema;
@@ -275,6 +323,9 @@
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
     return *(TheTargetAttributesSema = new X86AttributesSema);
+  case llvm::Triple::mips:
+  case llvm::Triple::mipsel:
+    return *(TheTargetAttributesSema = new MipsAttributesSema);
   default:
     return *(TheTargetAttributesSema = new TargetAttributesSema);
   }

Added: cfe/trunk/test/Sema/mips16_attr_allowed.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/mips16_attr_allowed.c?rev=172626&view=auto
==============================================================================
--- cfe/trunk/test/Sema/mips16_attr_allowed.c (added)
+++ cfe/trunk/test/Sema/mips16_attr_allowed.c Wed Jan 16 11:10:28 2013
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple mipsel-linux-gnu -fsyntax-only -verify %s
+
+void foo32();
+void foo16();
+void __attribute__((nomips16)) foo32(); 
+void __attribute__((mips16)) foo16(); 
+
+void __attribute__((nomips16)) foo32_(); 
+void __attribute__((mips16)) foo16_(); 
+void foo32_();
+void foo16_();
+
+void foo32__() __attribute__((nomips16)); 
+void foo32__() __attribute__((mips16)); 
+
+void foo32a() __attribute__((nomips16(xyz))) ; // expected-error {{attribute takes no arguments}}
+void __attribute__((mips16(xyz))) foo16a(); // expected-error {{attribute takes no arguments}}
+
+void __attribute__((nomips16(1, 2))) foo32b(); // expected-error {{attribute takes no arguments}}
+void __attribute__((mips16(1, 2))) foo16b(); // expected-error {{attribute takes no arguments}}
+
+
+__attribute((nomips16)) int a; // expected-error {{attribute only applies to functions}}
+
+__attribute((mips16)) int b; // expected-error {{attribute only applies to functions}}
+
+

Added: cfe/trunk/test/Sema/mips16_attr_not_allowed.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/mips16_attr_not_allowed.c?rev=172626&view=auto
==============================================================================
--- cfe/trunk/test/Sema/mips16_attr_not_allowed.c (added)
+++ cfe/trunk/test/Sema/mips16_attr_not_allowed.c Wed Jan 16 11:10:28 2013
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+
+void __attribute__((nomips16)) foo32(); // expected-warning {{unknown attribute 'nomips16' ignored}}
+void __attribute__((mips16)) foo16(); // expected-warning {{unknown attribute 'mips16' ignored}}
+
+
+





More information about the cfe-commits mailing list