[cfe-users] LibTooling for rewriting sign-conversion code

Brian Cole coleb at eyesopen.com
Tue Dec 4 09:49:06 PST 2012


I'm a clang newbie trying to follow the example of the remove-cstr-calls example and write my own tool to rewrite implicit sign conversion casts like the following: 

int x = 1; 
unsigned int y = x;

I want to wrap this cast in our own internal cast checking function that checks whether the cast is valid in debug mode. The resulting code would then look like:

int x = 1; 
unsigned int y = Cast<unsigned int>(x);

The Cast function is a neat little bit of code to determine if the cast is "safe" at runtime. But anyway, I'm having a hard time writing an implicit cast expression that will find the AST nodes that force the following warning to be thrown: 

warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]

Is there any way to directly access the AST nodes throwing warnings? 

Thanks, 
Brian



More information about the cfe-users mailing list