[cfe-dev] Implementing -Wunused-variables
Oscar Bonilla
ob at bitmover.com
Tue Oct 6 10:15:25 PDT 2009
On Oct 6, 2009, at 9:12 AM, Oscar Bonilla wrote:
> On Oct 5, 2009, at 11:37 PM, Oscar Bonilla wrote:
>
>> On Oct 5, 2009, at 9:46 PM, Oscar Bonilla wrote:
>>
>>> Is this any better?
>>
>> Still not quite right:
>
> Ok, this one seems to do the trick:
>
> <ob.patch>
>
> Testcases:
>
> <warn-unused-variables.c><warn-unused-variables.cpp>
>
> I ran "make test" and only got one failure:
>
> FAIL: Clang::Index/c-index-api-test.m (646 of 1636)
>
> which seems unrelated. I also compiled Adium with it and didn't get
> any obvious false positives or false negatives.
>
Would it be better to write the if in SemaDecl.cpp
if (isa<VarDecl>(D) && !isa<ParmVarDecl>(D) && !
isa<ImplicitParamDecl>(D) &&
D->getDeclContext()->isFunctionOrMethod() &&
!D->isUsed() && !D->hasAttr<UnusedAttr>()) {
Diag(D->getLocation(), diag::warn_unused_variable) << D-
>getDeclName();
}
as
if (!D->isUsed() && !D->hasAttr<UnusedAttr>() &&
isa<VarDecl>(D) && !isa<ParmVarDecl>(D) && !isa<ImplicitParamDecl>(D)
&&
D->getDeclContext()->isFunctionOrMethod()) {
Diag(D->getLocation(), diag::warn_unused_variable) << D-
>getDeclName();
}
i.e. move the "not used and no unused attr" to the beginning to take
advantage of short-circuit logic?
or is this kind of micro-optimizing frowned upon? :)
Cheers,
-Oscar
More information about the cfe-dev
mailing list