[cfe-users] LibTooling for rewriting sign-conversion code
David Blaikie
dblaikie at gmail.com
Tue Dec 4 09:54:57 PST 2012
On Tue, Dec 4, 2012 at 9:49 AM, Brian Cole <coleb at eyesopen.com> wrote:
> 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?
AST nodes themselves don't have warning logic, that's built into Sema.
You can look at the code there, but, no, the warning machinery doesn't
know about AST nodes so it doesn't have a "report nodes instead of
names" feature.
What you probably want to do is -ast-dump to look at what sort of node
types are in your example & try to match on those.
More information about the cfe-users
mailing list