[cfe-dev] Clang ASTVisitor Extern Variable usage

mats petersson via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 13 04:37:44 PST 2016


I believe the short answer is "no".

AST is per "compilation unit", and as such, test.c and Main.c is two
compilation units. You will need to write some code of your own to analyze
the total set of AST's from all your compilation units to determine that.
Which may not be so hard for this simple example, but gets quite complex if
you start having many and large compilation units - and want to determine
ALL global variables are initialized [and of course, "not initializing"
global variables is well-defined by the C and C++ specifications - in other
words, `int var;` and `int var = 0;` are equivalent constructs].

I'm interpreting the legal terms of your footer of your email to mean that
you intended to send this to the clang mailing list, and as such I am an
intended recipient and have been authorized by KPIT Technologies Ltd, to
read and retain your email. If this is not a correct interpretation, please
destroy this email.

--
Mats

On 12 December 2016 at 13:54, Sunny Billava via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hello All,
>
> For a clang tool based on RecursiveASTVisitor, would like to detect the
> definition of an extern variable.
>
> For the below code file samples, while traversing the Main.c, can we
> detect the “var” is defined & initialized in test.c
>
>
>
>
>
> Below are the file definition
>
>
>
> *<<<<Main.c>>>>*
>
> #include "h1.h"
>
> int main()
>
> {
>
>         var = 10;
>
> }
>
>
>
> *<<<<h1.h>>>>*
>
> extern int var;
>
>
>
> *<<<<test.c>>>>*
>
> #include "h1.h"
>
> int var = 11;
>
>
> This message contains information that may be privileged or confidential
> and is the property of the KPIT Technologies Ltd. It is intended only for
> the person to whom it is addressed. If you are not the intended recipient,
> you are not authorized to read, print, retain copy, disseminate,
> distribute, or use this message or any part thereof. If you receive this
> message in error, please notify the sender immediately and delete all
> copies of this message. KPIT Technologies Ltd. does not accept any
> liability for virus infected mails.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161213/fae3e1a6/attachment.html>


More information about the cfe-dev mailing list