[llvm-bugs] [Bug 37327] New: Stmt::IgnoreImplicit() should ignore non-trailing ImplicitCastExpr

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 3 09:16:17 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37327

            Bug ID: 37327
           Summary: Stmt::IgnoreImplicit() should ignore non-trailing
                    ImplicitCastExpr
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: steveire at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The implementation of Stmt::IgnoreImplicit() should ignore ImplicitCastExpr
which appear after MaterializeTemporaryExpr. Currently it does not, meaning I
have to nest two ignoringImplicit() calls when using AST matchers:

C:\dev\src\playground\cpp>type clang_impl.cpp

struct OtherType;

struct SomeType
{
    SomeType() {}
    SomeType(const OtherType&) {}
    SomeType& operator=(OtherType const&) { return *this; }
};

struct OtherType
{
    OtherType() {}
    ~OtherType() {}
};

OtherType something()
{
    return {};
}

int main()
{
    SomeType i = something();
}



C:\dev\src\llvm\build\releaseprefix\bin\clang-query.exe clang_impl.cpp --

clang-query> m varDecl(hasName("i"),
hasInitializer(exprWithCleanups(has(cxxConstructExpr(has(expr(ignoringImplicit(cxxConstructExpr().bind("e")))))))))

Match #1:

Binding for "e":
CXXConstructExpr 0x2c4ab85a588 <C:\dev\src\playground\cpp\clang_impl.cpp:24:18,
col:28> 'struct SomeType' 'void (const struct OtherType &)'
`-MaterializeTemporaryExpr 0x2c4ab85a570 <col:18, col:28> 'const struct
OtherType' lvalue
  `-ImplicitCastExpr 0x2c4ab85a558 <col:18, col:28> 'const struct OtherType'
<NoOp>
    `-CXXBindTemporaryExpr 0x2c4ab85a1a0 <col:18, col:28> 'struct OtherType'
(CXXTemporary 0x2c4ab85a198)
      `-CallExpr 0x2c4ab85a170 <col:18, col:28> 'struct OtherType'
        `-ImplicitCastExpr 0x2c4ab85a158 <col:18> 'struct OtherType (*)(void)'
<FunctionToPointerDecay>
          `-DeclRefExpr 0x2c4ab85a100 <col:18> 'struct OtherType (void)' lvalue
Function 0x2c4ab84fd00 'something' 'struct OtherType (void)'

Binding for "root":
VarDecl 0x2c4ab85a040 <C:\dev\src\playground\cpp\clang_impl.cpp:24:5, col:28>
col:14 i 'SomeType' cinit
`-ExprWithCleanups 0x2c4ab85a760 <col:14, col:28> 'SomeType'
  `-CXXConstructExpr 0x2c4ab85a728 <col:14, col:28> 'SomeType' 'void (SomeType
&&) noexcept' elidable
    `-MaterializeTemporaryExpr 0x2c4ab85a6c8 <col:18, col:28> 'SomeType' xvalue
      `-ImplicitCastExpr 0x2c4ab85a5c0 <col:18, col:28> 'SomeType'
<ConstructorConversion>
        `-CXXConstructExpr 0x2c4ab85a588 <col:18, col:28> 'SomeType' 'void
(const OtherType &)'
          `-MaterializeTemporaryExpr 0x2c4ab85a570 <col:18, col:28> 'const
OtherType' lvalue
            `-ImplicitCastExpr 0x2c4ab85a558 <col:18, col:28> 'const OtherType'
<NoOp>
              `-CXXBindTemporaryExpr 0x2c4ab85a1a0 <col:18, col:28> 'OtherType'
(CXXTemporary 0x2c4ab85a198)
                `-CallExpr 0x2c4ab85a170 <col:18, col:28> 'OtherType'
                  `-ImplicitCastExpr 0x2c4ab85a158 <col:18> 'OtherType (*)()'
<FunctionToPointerDecay>
                    `-DeclRefExpr 0x2c4ab85a100 <col:18> 'OtherType ()' lvalue
Function 0x2c4ab84fd00 'something' 'OtherType ()'

1 match.
clang-query> m varDecl(hasName("i"),
hasInitializer(exprWithCleanups(has(cxxConstructExpr(has(expr(ignoringImplicit(cxxConstructExpr(has(expr(ignoringImplicit(callExpr())))).bind("e")))))))))
0 matches.
clang-query> m varDecl(hasName("i"),
hasInitializer(exprWithCleanups(has(cxxConstructExpr(has(expr(ignoringImplicit(cxxConstructExpr(has(expr(ignoringImplicit(cxxBindTemporaryExpr())))).bind("e")))))))))

Match #1:

Binding for "e":
CXXConstructExpr 0x2c4ab85a588 <C:\dev\src\playground\cpp\clang_impl.cpp:24:18,
col:28> 'struct SomeType' 'void (const struct OtherType &)'
`-MaterializeTemporaryExpr 0x2c4ab85a570 <col:18, col:28> 'const struct
OtherType' lvalue
  `-ImplicitCastExpr 0x2c4ab85a558 <col:18, col:28> 'const struct OtherType'
<NoOp>
    `-CXXBindTemporaryExpr 0x2c4ab85a1a0 <col:18, col:28> 'struct OtherType'
(CXXTemporary 0x2c4ab85a198)
      `-CallExpr 0x2c4ab85a170 <col:18, col:28> 'struct OtherType'
        `-ImplicitCastExpr 0x2c4ab85a158 <col:18> 'struct OtherType (*)(void)'
<FunctionToPointerDecay>
          `-DeclRefExpr 0x2c4ab85a100 <col:18> 'struct OtherType (void)' lvalue
Function 0x2c4ab84fd00 'something' 'struct OtherType (void)'

Binding for "root":
VarDecl 0x2c4ab85a040 <C:\dev\src\playground\cpp\clang_impl.cpp:24:5, col:28>
col:14 i 'SomeType' cinit
`-ExprWithCleanups 0x2c4ab85a760 <col:14, col:28> 'SomeType'
  `-CXXConstructExpr 0x2c4ab85a728 <col:14, col:28> 'SomeType' 'void (SomeType
&&) noexcept' elidable
    `-MaterializeTemporaryExpr 0x2c4ab85a6c8 <col:18, col:28> 'SomeType' xvalue
      `-ImplicitCastExpr 0x2c4ab85a5c0 <col:18, col:28> 'SomeType'
<ConstructorConversion>
        `-CXXConstructExpr 0x2c4ab85a588 <col:18, col:28> 'SomeType' 'void
(const OtherType &)'
          `-MaterializeTemporaryExpr 0x2c4ab85a570 <col:18, col:28> 'const
OtherType' lvalue
            `-ImplicitCastExpr 0x2c4ab85a558 <col:18, col:28> 'const OtherType'
<NoOp>
              `-CXXBindTemporaryExpr 0x2c4ab85a1a0 <col:18, col:28> 'OtherType'
(CXXTemporary 0x2c4ab85a198)
                `-CallExpr 0x2c4ab85a170 <col:18, col:28> 'OtherType'
                  `-ImplicitCastExpr 0x2c4ab85a158 <col:18> 'OtherType (*)()'
<FunctionToPointerDecay>
                    `-DeclRefExpr 0x2c4ab85a100 <col:18> 'OtherType ()' lvalue
Function 0x2c4ab84fd00 'something' 'OtherType ()'

1 match.
clang-query> m varDecl(hasName("i"),
hasInitializer(exprWithCleanups(has(cxxConstructExpr(has(expr(ignoringImplicit(cxxConstructExpr(has(expr(ignoringImplicit(ignoringImplicit(callExpr()))))).bind("e")))))))))

Match #1:

Binding for "e":
CXXConstructExpr 0x2c4ab85a588 <C:\dev\src\playground\cpp\clang_impl.cpp:24:18,
col:28> 'struct SomeType' 'void (const struct OtherType &)'
`-MaterializeTemporaryExpr 0x2c4ab85a570 <col:18, col:28> 'const struct
OtherType' lvalue
  `-ImplicitCastExpr 0x2c4ab85a558 <col:18, col:28> 'const struct OtherType'
<NoOp>
    `-CXXBindTemporaryExpr 0x2c4ab85a1a0 <col:18, col:28> 'struct OtherType'
(CXXTemporary 0x2c4ab85a198)
      `-CallExpr 0x2c4ab85a170 <col:18, col:28> 'struct OtherType'
        `-ImplicitCastExpr 0x2c4ab85a158 <col:18> 'struct OtherType (*)(void)'
<FunctionToPointerDecay>
          `-DeclRefExpr 0x2c4ab85a100 <col:18> 'struct OtherType (void)' lvalue
Function 0x2c4ab84fd00 'something' 'struct OtherType (void)'

Binding for "root":
VarDecl 0x2c4ab85a040 <C:\dev\src\playground\cpp\clang_impl.cpp:24:5, col:28>
col:14 i 'SomeType' cinit
`-ExprWithCleanups 0x2c4ab85a760 <col:14, col:28> 'SomeType'
  `-CXXConstructExpr 0x2c4ab85a728 <col:14, col:28> 'SomeType' 'void (SomeType
&&) noexcept' elidable
    `-MaterializeTemporaryExpr 0x2c4ab85a6c8 <col:18, col:28> 'SomeType' xvalue
      `-ImplicitCastExpr 0x2c4ab85a5c0 <col:18, col:28> 'SomeType'
<ConstructorConversion>
        `-CXXConstructExpr 0x2c4ab85a588 <col:18, col:28> 'SomeType' 'void
(const OtherType &)'
          `-MaterializeTemporaryExpr 0x2c4ab85a570 <col:18, col:28> 'const
OtherType' lvalue
            `-ImplicitCastExpr 0x2c4ab85a558 <col:18, col:28> 'const OtherType'
<NoOp>
              `-CXXBindTemporaryExpr 0x2c4ab85a1a0 <col:18, col:28> 'OtherType'
(CXXTemporary 0x2c4ab85a198)
                `-CallExpr 0x2c4ab85a170 <col:18, col:28> 'OtherType'
                  `-ImplicitCastExpr 0x2c4ab85a158 <col:18> 'OtherType (*)()'
<FunctionToPointerDecay>
                    `-DeclRefExpr 0x2c4ab85a100 <col:18> 'OtherType ()' lvalue
Function 0x2c4ab84fd00 'something' 'OtherType ()'

1 match.
clang-query>

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180503/e640e43d/attachment-0001.html>


More information about the llvm-bugs mailing list