clang omits a part of the code

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

clang omits a part of the code

Nir Pluderman
Hello all,

I'm trying to get to the code inside a function body,
but clang doesn't print a part of the body for some reason.

here is the function I'm trying to get to:

    {
        FILE f;
        int* b1 = malloc(sizeof(int));
        return 0;
    }

and here is what clang prints out (the "malloc" in the second line is missing):

    {
        FILE f;
        int *b1;
        return 0;
    }


I'm currently using the ASTConsumer and DeclVisitor to print out the fucntion body.
I've attached 3 files to the mail:
   
    activation.cpp    -    this file which contains all the initilizations.
    GeneralConsumer.h - the class which inherits from ASTConsumer and DeclVisitor.
    test5.c           -    the test file containing the function.

I think the problem is in my configuration/initilizations,
    because when I change line 48 in the activation.cpp file
    from true to false: "headerSearchOpts->UseStandardIncludes = false;",

    I get the malloc, but now I don't get the "FILE f;" line in the fucntion body (This is the new output):
   
    {
        int *b1 = malloc(sizeof(int));
        return 0;
    }

Does anyone have any idea what I'm doing wrong?

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

activation.cpp (3K) Download Attachment
GeneralConsumer.h (1K) Download Attachment
test5.c (154 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: clang omits a part of the code

Peter Collingbourne
On Thu, Mar 24, 2011 at 01:38:52PM +0000, Nir Pluderman wrote:
>    Does anyone have any idea what I'm doing wrong?

Most likely one of your header files is causing an error diagnostic
to be emitted.  If a malformed input file is provided then Clang will
try to build as complete an AST as possible.

> diags->setSuppressAllDiagnostics(true);

If you remove this line then you should be able to see the
diagnostic(s).

Thanks,
--
Peter
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang omits a part of the code

Nir Pluderman
Thank you for your quick response Peter,

I did as you said, and this is the output I got:

    Stack dump:
    0.    /usr/include/stdio.h:34:3: current parser token 'include'
   
It's a standard library header which comes builtin in ubuntu.

Also,   
If I switch the order of the includes in the file from:
    #include <stdio.h>
    #include <stdlib.h>
   
to:
    #include <stdlib.h>
    #include <stdio.h>
   
I get the output:
   
    Stack dump:
    0.    /usr/include/stdlib.h:33:2: current parser token 'include'
   
Again, It's a standard library header.

Is there anything I can do about it?

note:
    In both cases the problematic line in these standard library headers is:
        #include <stddef.h>

----- Original Message -----
From: Peter Collingbourne <[hidden email]>
Date: Thursday, March 24, 2011 12:50
Subject: Re: [cfe-dev] clang omits a part of the code
To: Nir Pluderman <[hidden email]>
Cc: [hidden email]

> On Thu, Mar 24, 2011 at 01:38:52PM +0000, Nir Pluderman wrote:
> >    Does anyone have any idea what I'm doing wrong?
>
> Most likely one of your header files is causing an error diagnostic
> to be emitted.  If a malformed input file is provided then
> Clang will
> try to build as complete an AST as possible.
>
> >  diags->setSuppressAllDiagnostics(true);
>
> If you remove this line then you should be able to see the
> diagnostic(s).
>
> Thanks,
> --
> Peter
> ‎
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang omits a part of the code

Peter Collingbourne
On Fri, Mar 25, 2011 at 11:31:08AM +0000, Nir Pluderman wrote:
> Thank you for your quick response Peter,
>
> I did as you said, and this is the output I got:
>
>     Stack dump:
>     0.    /usr/include/stdio.h:34:3: current parser token 'include'

This is not a standard diagnostic but part of Clang's output if it
segfaults/asserts.  Since you received the segfault/assert at the point
where a diagnostic should be emitted, I suspect it is because you did
not create the Diagnostic object correctly.  This is how I normally
build a Diagnostic object and point it to a TextDiagnosticPrinter
(which should just print the diagnostics to standard error):

  clang::TextDiagnosticPrinter *DiagClient =
    new clang::TextDiagnosticPrinter(errs(), clang::DiagnosticOptions());
  IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(new clang::DiagnosticIDs());
  clang::Diagnostic *Diag = new clang::Diagnostic(DiagID, DiagClient);

> note:
>     In both cases the problematic line in these standard library headers is:
>         #include <stddef.h>

This means that Clang could not find its stddef.h header, because
HeaderSearchOptions::ResourceDir (i.e. headerSearchOpts->ResourceDir)
was not set correctly.  You should set it to something like

LLVM_PREFIX "/lib/clang/" CLANG_VERSION_STRING

where LLVM_PREFIX is your LLVM build directory and CLANG_VERSION_STRING
is a macro defined in clang/Basic/Version.h.

Thanks,
--
Peter
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang omits a part of the code

Nir Pluderman
Peter, your remark regarding the HeaderSearchOptions::ResourceDir solved the problem.

My ResourceDir was an empty string, I didn't know it had to be set,
    after doing so, clang found all the required files and the program ran fine,
    without omitting anything.

I also changed the diagnostics according to what you wrote,
    and it's working correctly now.
   
Thank you for all your help

    Nir.


----- Original Message -----
From: Peter Collingbourne <[hidden email]>
Date: Friday, March 25, 2011 9:51
Subject: Re: [cfe-dev] clang omits a part of the code
To: Nir Pluderman <[hidden email]>
Cc: [hidden email]

> On Fri, Mar 25, 2011 at 11:31:08AM +0000, Nir Pluderman wrote:
> > Thank you for your quick response Peter,
> >
> > I did as you said, and this is the output I got:
> >
> >     Stack dump:
> >     0.    /usr/include/stdio.h:34:3: current parser token 'include'
>
> This is not a standard diagnostic but part of Clang's output if it
> segfaults/asserts.  Since you received the segfault/assert
> at the point
> where a diagnostic should be emitted, I suspect it is because
> you did
> not create the Diagnostic object correctly.  This is how I
> normallybuild a Diagnostic object and point it to a
> TextDiagnosticPrinter(which should just print the diagnostics to
> standard error):
>
>   clang::TextDiagnosticPrinter *DiagClient =
>     new clang::TextDiagnosticPrinter(errs(),
> clang::DiagnosticOptions()); 
> IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(new
> clang::DiagnosticIDs());  clang::Diagnostic *Diag = new
> clang::Diagnostic(DiagID, DiagClient);
>
> > note:
> >     In both cases the problematic line in these standard
> library headers is:
> >         #include <stddef.h>
>
> This means that Clang could not find its stddef.h header, because
> HeaderSearchOptions::ResourceDir (i.e. headerSearchOpts->ResourceDir)
> was not set correctly.  You should set it to something like
>
> LLVM_PREFIX "/lib/clang/" CLANG_VERSION_STRING
>
> where LLVM_PREFIX is your LLVM build directory and
> CLANG_VERSION_STRINGis a macro defined in clang/Basic/Version.h.
>
> Thanks,
> --
> Peter
> ‎
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev