bool type is represented as "_Bool" in the AST

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

bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
Dear Clang-developer community,
    I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior? 

    I don't get _Bool when dumping the ast except when I dump the QualType Node.

clang Version: 9.0
LLVM Version: 9.0

Regards,
Pradeep

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev

Are you compiling as C, or c++?  C++ should give you “bool”, since it is the type, however if you’re using C, “bool” is likely typedef’ed to “_Bool”, so that’s the type you’re getting.

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Pradeep Kumar via cfe-dev
Sent: Tuesday, July 23, 2019 7:47 AM
To: cfe-dev <[hidden email]>
Subject: [cfe-dev] bool type is represented as "_Bool" in the AST

 

Dear Clang-developer community,

    I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior? 

 

    I don't get _Bool when dumping the ast except when I dump the QualType Node.

 

clang Version: 9.0

LLVM Version: 9.0

 

Regards,

Pradeep


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
Dear Keane,
    I am running through CUDA code. The AST nodes as far as I can see is more like C++ like CXXRecordDecl and so on. I do pass C++ standard flag to the tool.

Regrads,
Pradeep

On Tue, Jul 23, 2019 at 8:21 PM Keane, Erich <[hidden email]> wrote:

Are you compiling as C, or c++?  C++ should give you “bool”, since it is the type, however if you’re using C, “bool” is likely typedef’ed to “_Bool”, so that’s the type you’re getting.

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Pradeep Kumar via cfe-dev
Sent: Tuesday, July 23, 2019 7:47 AM
To: cfe-dev <[hidden email]>
Subject: [cfe-dev] bool type is represented as "_Bool" in the AST

 

Dear Clang-developer community,

    I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior? 

 

    I don't get _Bool when dumping the ast except when I dump the QualType Node.

 

clang Version: 9.0

LLVM Version: 9.0

 

Regards,

Pradeep


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
In reply to this post by Sylvestre Ledru via cfe-dev
On Tue, Jul 23, 2019 at 10:47 AM Pradeep Kumar via cfe-dev
<[hidden email]> wrote:
>
> Dear Clang-developer community,
>     I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior?
>
>     I don't get _Bool when dumping the ast except when I dump the QualType Node.

The PrintingPolicy::Bool member dictates this behavior.

~Aaron

>
> clang Version: 9.0
> LLVM Version: 9.0
>
> Regards,
> Pradeep
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
Dear Aaron,
    Why is it set to "_Bool" by default? How do I change it?

Regards,
Pradeep

On Tue, Jul 23, 2019 at 8:32 PM Aaron Ballman <[hidden email]> wrote:
On Tue, Jul 23, 2019 at 10:47 AM Pradeep Kumar via cfe-dev
<[hidden email]> wrote:
>
> Dear Clang-developer community,
>     I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior?
>
>     I don't get _Bool when dumping the ast except when I dump the QualType Node.

The PrintingPolicy::Bool member dictates this behavior.

~Aaron

>
> clang Version: 9.0
> LLVM Version: 9.0
>
> Regards,
> Pradeep
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
On Tue, Jul 23, 2019 at 11:12 AM Pradeep Kumar <[hidden email]> wrote:
>
> Dear Aaron,
>     Why is it set to "_Bool" by default?

It seems to get its default value from LangOptions::Bool, which I
believe is set automatically by the language standard mode.

> How do I change it?

Usually you do this by making a copy of an existing PrintingPolicy
object and modifying it.

PrintingPolicy PP(WhateverPrintingPolicyYouWereUsing);
PP.Bool = 1;

Then pass PP into the call to getAsString().

~Aaron

>
> Regards,
> Pradeep
>
> On Tue, Jul 23, 2019 at 8:32 PM Aaron Ballman <[hidden email]> wrote:
>>
>> On Tue, Jul 23, 2019 at 10:47 AM Pradeep Kumar via cfe-dev
>> <[hidden email]> wrote:
>> >
>> > Dear Clang-developer community,
>> >     I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior?
>> >
>> >     I don't get _Bool when dumping the ast except when I dump the QualType Node.
>>
>> The PrintingPolicy::Bool member dictates this behavior.
>>
>> ~Aaron
>>
>> >
>> > clang Version: 9.0
>> > LLVM Version: 9.0
>> >
>> > Regards,
>> > Pradeep
>> > _______________________________________________
>> > cfe-dev mailing list
>> > [hidden email]
>> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
Dear Aaron,
   How do I set it from command line? I am remeber setting the language standard as -std=c++17 in the clangTool.

Regards,
Pradeep

On Tue, Jul 23, 2019 at 8:48 PM Aaron Ballman <[hidden email]> wrote:
On Tue, Jul 23, 2019 at 11:12 AM Pradeep Kumar <[hidden email]> wrote:
>
> Dear Aaron,
>     Why is it set to "_Bool" by default?

It seems to get its default value from LangOptions::Bool, which I
believe is set automatically by the language standard mode.

> How do I change it?

Usually you do this by making a copy of an existing PrintingPolicy
object and modifying it.

PrintingPolicy PP(WhateverPrintingPolicyYouWereUsing);
PP.Bool = 1;

Then pass PP into the call to getAsString().

~Aaron

>
> Regards,
> Pradeep
>
> On Tue, Jul 23, 2019 at 8:32 PM Aaron Ballman <[hidden email]> wrote:
>>
>> On Tue, Jul 23, 2019 at 10:47 AM Pradeep Kumar via cfe-dev
>> <[hidden email]> wrote:
>> >
>> > Dear Clang-developer community,
>> >     I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior?
>> >
>> >     I don't get _Bool when dumping the ast except when I dump the QualType Node.
>>
>> The PrintingPolicy::Bool member dictates this behavior.
>>
>> ~Aaron
>>
>> >
>> > clang Version: 9.0
>> > LLVM Version: 9.0
>> >
>> > Regards,
>> > Pradeep
>> > _______________________________________________
>> > cfe-dev mailing list
>> > [hidden email]
>> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
On Tue, Jul 23, 2019 at 12:24 PM Pradeep Kumar <[hidden email]> wrote:
>
> Dear Aaron,
>    How do I set it from command line? I am remeber setting the language standard as -std=c++17 in the clangTool.

You don't change it via the command line. If you set the language mode
to C++ in Clang, it should always print as bool automatically. See
CompilerInvocation::setLangDefaults(), where it sets the values for
the LangOptions object used to make printing policies. If you're not
executing Clang, we need more information about how you are setting up
the tool to be able to help.

~Aaron

>
> Regards,
> Pradeep
>
> On Tue, Jul 23, 2019 at 8:48 PM Aaron Ballman <[hidden email]> wrote:
>>
>> On Tue, Jul 23, 2019 at 11:12 AM Pradeep Kumar <[hidden email]> wrote:
>> >
>> > Dear Aaron,
>> >     Why is it set to "_Bool" by default?
>>
>> It seems to get its default value from LangOptions::Bool, which I
>> believe is set automatically by the language standard mode.
>>
>> > How do I change it?
>>
>> Usually you do this by making a copy of an existing PrintingPolicy
>> object and modifying it.
>>
>> PrintingPolicy PP(WhateverPrintingPolicyYouWereUsing);
>> PP.Bool = 1;
>>
>> Then pass PP into the call to getAsString().
>>
>> ~Aaron
>>
>> >
>> > Regards,
>> > Pradeep
>> >
>> > On Tue, Jul 23, 2019 at 8:32 PM Aaron Ballman <[hidden email]> wrote:
>> >>
>> >> On Tue, Jul 23, 2019 at 10:47 AM Pradeep Kumar via cfe-dev
>> >> <[hidden email]> wrote:
>> >> >
>> >> > Dear Clang-developer community,
>> >> >     I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior?
>> >> >
>> >> >     I don't get _Bool when dumping the ast except when I dump the QualType Node.
>> >>
>> >> The PrintingPolicy::Bool member dictates this behavior.
>> >>
>> >> ~Aaron
>> >>
>> >> >
>> >> > clang Version: 9.0
>> >> > LLVM Version: 9.0
>> >> >
>> >> > Regards,
>> >> > Pradeep
>> >> > _______________________________________________
>> >> > cfe-dev mailing list
>> >> > [hidden email]
>> >> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
In reply to this post by Sylvestre Ledru via cfe-dev

I noticed that too recently:


$ cat f.cmds

set print-matcher true

m functionDecl(returns(asString("int")))

m functionDecl(returns(asString("bool")))

m functionDecl(returns(asString("_Bool")))
$ cat foo.cpp

int foo();

bool bar();
$ clang-query -f f.cmds foo.cpp -- -std=c++17

   Matcher: functionDecl(returns(asString("int")))
   ===============================================

Match #1:

foo.cpp:2:1: note: "root" binds here
int foo();
^~~~~~~~~

1 match.

   Matcher: functionDecl(returns(asString("bool")))
   ================================================
0 matches.

   Matcher: functionDecl(returns(asString("_Bool")))
   =================================================

Match #1:

foo.cpp:4:1: note: "root" binds here
bool bar();
^~~~~~~~~~

1 match.

$


I don't know any more than that.

Thanks,

Stephen.

On 23/07/2019 15:47, Pradeep Kumar via cfe-dev wrote:

> Dear Clang-developer community,
>      I am using libTooling to query information about the source. While
> querying the string representation of the bool type, I get "_Bool"
> string. I got the string from QualType::getAsString(). Should I be using
> another function to query the actual type or is it an expected behavior?
>
>      I don't get _Bool when dumping the ast except when I dump the
> QualType Node.
>
> clang Version: 9.0
> LLVM Version: 9.0
>
> Regards,
> Pradeep
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
In reply to this post by Sylvestre Ledru via cfe-dev
Dear Aaron,
   For the sake of clarity, I have detailed about the case in here. I just want to know is this the expected behavior from the tool.

Regards,
Pradeep



On Tue, Jul 23, 2019 at 10:01 PM Aaron Ballman <[hidden email]> wrote:
On Tue, Jul 23, 2019 at 12:24 PM Pradeep Kumar <[hidden email]> wrote:
>
> Dear Aaron,
>    How do I set it from command line? I am remeber setting the language standard as -std=c++17 in the clangTool.

You don't change it via the command line. If you set the language mode
to C++ in Clang, it should always print as bool automatically. See
CompilerInvocation::setLangDefaults(), where it sets the values for
the LangOptions object used to make printing policies. If you're not
executing Clang, we need more information about how you are setting up
the tool to be able to help.

~Aaron

>
> Regards,
> Pradeep
>
> On Tue, Jul 23, 2019 at 8:48 PM Aaron Ballman <[hidden email]> wrote:
>>
>> On Tue, Jul 23, 2019 at 11:12 AM Pradeep Kumar <[hidden email]> wrote:
>> >
>> > Dear Aaron,
>> >     Why is it set to "_Bool" by default?
>>
>> It seems to get its default value from LangOptions::Bool, which I
>> believe is set automatically by the language standard mode.
>>
>> > How do I change it?
>>
>> Usually you do this by making a copy of an existing PrintingPolicy
>> object and modifying it.
>>
>> PrintingPolicy PP(WhateverPrintingPolicyYouWereUsing);
>> PP.Bool = 1;
>>
>> Then pass PP into the call to getAsString().
>>
>> ~Aaron
>>
>> >
>> > Regards,
>> > Pradeep
>> >
>> > On Tue, Jul 23, 2019 at 8:32 PM Aaron Ballman <[hidden email]> wrote:
>> >>
>> >> On Tue, Jul 23, 2019 at 10:47 AM Pradeep Kumar via cfe-dev
>> >> <[hidden email]> wrote:
>> >> >
>> >> > Dear Clang-developer community,
>> >> >     I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior?
>> >> >
>> >> >     I don't get _Bool when dumping the ast except when I dump the QualType Node.
>> >>
>> >> The PrintingPolicy::Bool member dictates this behavior.
>> >>
>> >> ~Aaron
>> >>
>> >> >
>> >> > clang Version: 9.0
>> >> > LLVM Version: 9.0
>> >> >
>> >> > Regards,
>> >> > Pradeep
>> >> > _______________________________________________
>> >> > cfe-dev mailing list
>> >> > [hidden email]
>> >> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bool type is represented as "_Bool" in the AST

Sylvestre Ledru via cfe-dev
On Tue, Jul 23, 2019 at 7:59 PM Pradeep Kumar <[hidden email]> wrote:
>
> Dear Aaron,
>    For the sake of clarity, I have detailed about the case in here. I just want to know is this the expected behavior from the tool.

Expected: no. Explainable: yes.

var_decl->getType().dump(); calls the default dumper on QualType. This
creates an ASTDumper object from llvm::errs() and two null pointers
(see ASTDumper.cpp:164). This ASTDumper constructor constructs a
PrintingPolicy object from a default-constructed LangOptions object
rather than using the one from the ASTContext (see ASTDumper.h:32),
which is why you're getting the behavior you are.

There is no QualType::dump() interface that lets you pass in a
printing policy. I would have expected the QualType dumper to use the
correct printing policy, like the Decl dumper does, which is why I
think this is unexpected.

~Aaron

>
> Regards,
> Pradeep
>
>
> Gist link: https://gist.github.com/schwarzschild-radius/8986bd5dc734183727291b3f3aae4c53
>
> On Tue, Jul 23, 2019 at 10:01 PM Aaron Ballman <[hidden email]> wrote:
>>
>> On Tue, Jul 23, 2019 at 12:24 PM Pradeep Kumar <[hidden email]> wrote:
>> >
>> > Dear Aaron,
>> >    How do I set it from command line? I am remeber setting the language standard as -std=c++17 in the clangTool.
>>
>> You don't change it via the command line. If you set the language mode
>> to C++ in Clang, it should always print as bool automatically. See
>> CompilerInvocation::setLangDefaults(), where it sets the values for
>> the LangOptions object used to make printing policies. If you're not
>> executing Clang, we need more information about how you are setting up
>> the tool to be able to help.
>>
>> ~Aaron
>>
>> >
>> > Regards,
>> > Pradeep
>> >
>> > On Tue, Jul 23, 2019 at 8:48 PM Aaron Ballman <[hidden email]> wrote:
>> >>
>> >> On Tue, Jul 23, 2019 at 11:12 AM Pradeep Kumar <[hidden email]> wrote:
>> >> >
>> >> > Dear Aaron,
>> >> >     Why is it set to "_Bool" by default?
>> >>
>> >> It seems to get its default value from LangOptions::Bool, which I
>> >> believe is set automatically by the language standard mode.
>> >>
>> >> > How do I change it?
>> >>
>> >> Usually you do this by making a copy of an existing PrintingPolicy
>> >> object and modifying it.
>> >>
>> >> PrintingPolicy PP(WhateverPrintingPolicyYouWereUsing);
>> >> PP.Bool = 1;
>> >>
>> >> Then pass PP into the call to getAsString().
>> >>
>> >> ~Aaron
>> >>
>> >> >
>> >> > Regards,
>> >> > Pradeep
>> >> >
>> >> > On Tue, Jul 23, 2019 at 8:32 PM Aaron Ballman <[hidden email]> wrote:
>> >> >>
>> >> >> On Tue, Jul 23, 2019 at 10:47 AM Pradeep Kumar via cfe-dev
>> >> >> <[hidden email]> wrote:
>> >> >> >
>> >> >> > Dear Clang-developer community,
>> >> >> >     I am using libTooling to query information about the source. While querying the string representation of the bool type, I get "_Bool" string. I got the string from QualType::getAsString(). Should I be using another function to query the actual type or is it an expected behavior?
>> >> >> >
>> >> >> >     I don't get _Bool when dumping the ast except when I dump the QualType Node.
>> >> >>
>> >> >> The PrintingPolicy::Bool member dictates this behavior.
>> >> >>
>> >> >> ~Aaron
>> >> >>
>> >> >> >
>> >> >> > clang Version: 9.0
>> >> >> > LLVM Version: 9.0
>> >> >> >
>> >> >> > Regards,
>> >> >> > Pradeep
>> >> >> > _______________________________________________
>> >> >> > cfe-dev mailing list
>> >> >> > [hidden email]
>> >> >> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev