[cfe-dev] AST bug parsing tags.cpp file?

Billy Araujo via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 30 03:54:29 PDT 2020


Hi Dave,

Thanks for your reply. I don't think it is a cxxMemberCallExpr().
I think it is parsing issue because this is what happens:

class ColorTag()
{
public:
   ColorTag():
   ~ColorTag();
}

ColorTag()::ColorTag() {
  //...
}

ColorTag::~ColorTag() {}

It is interpreted as: CXXMemberCallExpr() as if ColorTag::~ColorTag() was
called inside the constructor. You can see below in the AST output
cxxMemberCallExpr parent is CXXConstructorDecl.

`-CXXConstructorDecl 0x2e76988 parent 0x2e60608 prev 0x2e61578 <line:238:1,
line:434:2> line:238:11 ColorTag 'void (const ColorTag &)'
  |-ParmVarDecl 0x2e768f8 <col:20, col:36> col:36 used tag 'const ColorTag
&'
  |-CXXCtorInitializer 'PliObjectTag'
  | `-CXXConstructExpr 0x2e76b10 <line:239:7, col:39> 'PliObjectTag' 'void
(const PliTag::Type)'
  |   `-DeclRefExpr 0x2e76ab0 <col:20, col:28> 'PliTag::Type' EnumConstant
0x2e579e8 'COLOR_NGOBJ' 'PliTag::Type'
  |-CXXCtorInitializer Field 0x2e60e88 'm_style' 'ColorTag::styleType'
  | `-ImplicitCastExpr 0x2e76bd8 <line:240:15, col:19>
'ColorTag::styleType' <LValueToRValue>
  |   `-MemberExpr 0x2e76b88 <col:15, col:19> 'const ColorTag::styleType'
lvalue .m_style 0x2e60e88
  |     `-DeclRefExpr 0x2e76b68 <col:15> 'const ColorTag' lvalue ParmVar
0x2e768f8 'tag' 'const ColorTag &'
  |-CXXCtorInitializer Field 0x2e60ee8 'm_attribute'
'ColorTag::attributeType'
  | `-ImplicitCastExpr 0x2e76c88 <line:241:19, col:23>
'ColorTag::attributeType' <LValueToRValue>
  |   `-MemberExpr 0x2e76c38 <col:19, col:23> 'const
ColorTag::attributeType' lvalue .m_attribute 0x2e60ee8
  |     `-DeclRefExpr 0x2e76c18 <col:19> 'const ColorTag' lvalue ParmVar
0x2e768f8 'tag' 'const ColorTag &'
  `-CompoundStmt 0x2e76fb0 <line:242:36, line:434:2>
    |-IfStmt 0x2e76d98 <line:243:3, line:249:1>
    | |-OpaqueValueExpr 0x2e76d80 <<invalid sloc>> 'bool'
    | `-CompoundStmt 0x2e76d70 <line:243:28, line:249:1>
    |-CXXMemberCallExpr 0x2e76e68 <line:251:1, col:21> 'void'
    | `-MemberExpr 0x2e76e20 <col:1, col:12> '<bound member function type>'
->~ColorTag 0x2e61670
    |   `-CXXThisExpr 0x2e76e10 <col:11> 'ColorTag *' implicit this

So this:

class ColorTag()
{
public:
   ColorTag():
   ~ColorTag();
}

ColorTag()::ColorTag() {
  //...
}

ColorTag::~ColorTag() {}

Is interpreted like this:

class ColorTag()
{
public:
   ColorTag():
   ~ColorTag();
}

ColorTag()::ColorTag() {
  //...
 ColorTag::~ColorTag() {}
}

Regards,

Billy.




On Thu, Jul 30, 2020 at 1:27 AM David Rector <davrecthreads at gmail.com>
wrote:

> I think you are not distinguishing properly between the declaration of the
> destructor and its usage (via a CXXMemberCallExpr) within the
> implementation/"body" of some other method declaration (this body should be
> enclosed in a "CompoundStmt").
>
> For example, the dump of
>
> ```
> struct ColorTag {
>   ~ColorTag() {}
>   void destroy() {
>     ColorTag::~ColorTag();
>   }
> };
> ```
>
> looks like this:
>
> ```
> TranslationUnitDecl
> `-CXXRecordDecl <line:1:1, line:5:1> line:1:8 struct ColorTag definition
>   ...(Definition data, implicitly-generated declarations)...
>   |-CXXDestructorDecl <line:2:5, col:18> col:5 used ~ColorTag 'void ()
> noexcept'
>   |-CXXMethodDecl <line:2:5, line:4:5> line:2:10 destroy 'void ()'
>   | `-CompoundStmt <col:20, line:4:5>
>   |   `-CXXMemberCallExpr <line:3:9, col:29> 'void'
>   |     `-MemberExpr <col:9, col:20> '<bound member function
> type>' ->~ColorTag 0x55790cbbaa40
>   |       `-CXXThisExpr <col:19> 'ColorTag *' implicit this
>   ...
> ```
>
> Hope that helps, good luck,
>
> Dave
>
> On Jul 29, 2020, at 10:40 AM, Billy Araujo via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
> Hi,
>
> On project opentoonz there is a file called:
> opentoonz/toonz/sources/image/pli/tags.cp
>
> If I run clang-check, the AST it builds seems wrong.
>
> clang-check -ast-dump /home/opentoonz/toonz/sources/image/pli/tags.cpp |
> grep -B 1 -A 1 "~ColorTag"
>
>     |-CXXMemberCallExpr 0x22893e8 <line:253:1, col:21> 'void'
>     | `-MemberExpr 0x22893a0 <col:1, col:12> '<bound member function
> type>' ->~ColorTag 0x2274c00
>     |   `-CXXThisExpr 0x2289390 <col:11> 'ColorTag *' implicit this
>
> Line 253 appears as a CXXMemberCallExpr instead of a CXXDestructorDecl.
>
> So the AST thinks it is calling an explicit destructor method call
> although it is a destructor implementation.
>
> clang-check --version
> LLVM (http://llvm.org/):
>   LLVM version 10.0.0
>
>   Optimized build.
>   Default target: x86_64-pc-linux-gnu
>   Host CPU: nehalem
>
> Is this a bug or am I missing something?
>
> Regards,
>
> Billy.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://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/20200730/2fac80b3/attachment.html>


More information about the cfe-dev mailing list