[cfe-dev] Implementing -Wunused-variables

Oscar Bonilla ob at bitmover.com
Sun Oct 4 18:04:23 PDT 2009


Hi,

So I'm trying to get my feet wet with clang, and I noticed that right  
now clang doesn't notice when you declare a variable but don't use it.  
I wrote this simple testcase and put it in

llvm/tools/clang/test/Sema/warning-unused-variables.c

---
// RUN: clang -fsyntax-only -Wunused-variables -verify %s

void f0(void) {
	int	a, b; // expected-warning{{unused-variable}}
	a = 10;
	return;
}
---

And sure enough:

$ clang-cc -Wunused-variables -fsyntax-only -verify warn-unused- 
variables.c
Warnings expected but not seen:
   Line 4: unused-variable
Warnings seen but not expected:
   Line 0: unknown warning option '-Wunused-variables'

Obviously there is no -Wunused-variables flag or unused variables  
warning yet because that's what I need to implement. So my question  
is, what's the best way start hacking on this? Is there a document  
that describes the AST and where the warnings are generated? What  
files should I start reading?

Thanks,

-Oscar




More information about the cfe-dev mailing list