Bug 1185188 - Support multiple clang-plugin annotations; r=ehsan
authorMichael Layzell <michael@thelayzells.com>
Sat, 18 Jul 2015 00:11:31 -0400
changeset 254585 78ab441fb9c88314a488dca7f7fc9692e66497d7
parent 254584 e6bee0b58b9e0e3647b3a3f4a9984a2d1d8b1cc2
child 254586 b8991390305ee6f350b0c4f72131d94d74691a9c
push id29108
push userryanvm@gmail.com
push dateMon, 27 Jul 2015 14:12:01 +0000
treeherdermozilla-central@27ae736ef960 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1185188
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1185188 - Support multiple clang-plugin annotations; r=ehsan
build/clang-plugin/clang-plugin.cpp
build/clang-plugin/tests/TestMultipleAnnotations.cpp
build/clang-plugin/tests/moz.build
--- a/build/clang-plugin/clang-plugin.cpp
+++ b/build/clang-plugin/clang-plugin.cpp
@@ -227,22 +227,27 @@ public:
   ASTConsumerPtr getOtherConsumer() {
     return matcher.makeASTConsumer();
   }
 
   virtual void HandleTranslationUnit(ASTContext &ctx) {
     TraverseDecl(ctx.getTranslationUnitDecl());
   }
 
-  static bool hasCustomAnnotation(const Decl *d, const char *spelling) {
-    AnnotateAttr *attr = d->getAttr<AnnotateAttr>();
-    if (!attr)
-      return false;
+  static bool hasCustomAnnotation(const Decl *D, const char *Spelling) {
+    iterator_range<specific_attr_iterator<AnnotateAttr> > Attrs =
+      D->specific_attrs<AnnotateAttr>();
 
-    return attr->getAnnotation() == spelling;
+    for (AnnotateAttr *Attr : Attrs) {
+      if (Attr->getAnnotation() == Spelling) {
+        return true;
+      }
+    }
+
+    return false;
   }
 
   void HandleUnusedExprResult(const Stmt *stmt) {
     const Expr* E = dyn_cast_or_null<Expr>(stmt);
     if (E) {
       // XXX It would be nice if we could use getAsTagDecl,
       // but our version of clang is too old.
       // (getAsTagDecl would also cover enums etc.)
new file mode 100644
--- /dev/null
+++ b/build/clang-plugin/tests/TestMultipleAnnotations.cpp
@@ -0,0 +1,17 @@
+#define MOZ_MUST_USE __attribute__((annotate("moz_must_use")))
+#define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class")))
+
+class MOZ_MUST_USE MOZ_STACK_CLASS TestClass {};
+
+TestClass foo; // expected-error {{variable of type 'TestClass' only valid on the stack}}
+
+TestClass f()
+{
+  TestClass bar;
+  return bar;
+}
+
+void g()
+{
+  f(); // expected-error {{Unused MOZ_MUST_USE value of type 'TestClass'}}
+}
--- a/build/clang-plugin/tests/moz.build
+++ b/build/clang-plugin/tests/moz.build
@@ -4,16 +4,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 SOURCES += [
     'TestBadImplicitConversionCtor.cpp',
     'TestCustomHeap.cpp',
     'TestExplicitOperatorBool.cpp',
     'TestGlobalClass.cpp',
+    'TestMultipleAnnotations.cpp',
     'TestMustOverride.cpp',
     'TestMustUse.cpp',
     'TestNANTestingExpr.cpp',
     'TestNANTestingExprC.c',
     'TestNoAddRefReleaseOnReturn.cpp',
     'TestNoArithmeticExprInArgument.cpp',
     'TestNonHeapClass.cpp',
     'TestNoRefcountedInsideLambdas.cpp',