Bug 1185188 - Support multiple clang-plugin annotations; r=ehsan

This commit is contained in:
Michael Layzell 2015-07-18 00:11:31 -04:00 committed by Ehsan Akhgari
parent 818972d2a3
commit b2987686b9
3 changed files with 28 additions and 5 deletions

View File

@ -232,12 +232,17 @@ public:
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) {

View File

@ -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'}}
}

View File

@ -9,6 +9,7 @@ SOURCES += [
'TestCustomHeap.cpp',
'TestExplicitOperatorBool.cpp',
'TestGlobalClass.cpp',
'TestMultipleAnnotations.cpp',
'TestMustOverride.cpp',
'TestMustUse.cpp',
'TestNANTestingExpr.cpp',