trailofbits / pasta

Peter's Amazing Syntax Tree Analyzer
Apache License 2.0
123 stars 9 forks source link

SplitToken fails to identify `greater` or `less` token with stream in/out tokens #112

Open kumarak opened 9 months ago

kumarak commented 9 months ago

The pasta Split token fails to identify the less(<) or greater(>) token with stream in/out tokens (<<, or >>). This causes the end source location of the token be very high causing the assert.

template<typename T>
class Foo {};

template <typename X = Foo<int>>
class Bar {};

Bar<> x;

Backtrace:

* thread #52, stop reason = hit program assert
    frame #0: 0x00007ff811d287ce libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007ff811d60f30 libsystem_pthread.dylib`pthread_kill + 262
    frame #2: 0x00007ff811c7fa49 libsystem_c.dylib`abort + 126
    frame #3: 0x00007ff811c7ed30 libsystem_c.dylib`__assert_rtn + 314
  * frame #4: 0x00000001016c8a62 mx-index`pasta::ASTImpl::RawTokenAt(this=0x00007fa878008a18, loc=(ID = 2148446497)) at AST.cpp:163:5
    frame #5: 0x0000000101860a72 mx-index`pasta::(anonymous namespace)::DeclBoundsFinder::Expand(this=0x000070001cc87ec0, loc=(ID = 2148446497)) at Bounds.cpp:553:18
    frame #6: 0x0000000101860a28 mx-index`pasta::(anonymous namespace)::DeclBoundsFinder::Expand(this=0x000070001cc87ec0, loc=SourceRange @ 0x000070001cc87c98) at Bounds.cpp:559:5
    frame #7: 0x00000001018609d3 mx-index`pasta::(anonymous namespace)::DeclBoundsFinder::VisitDecl(this=0x000070001cc87ec0, decl=0x00007fa8781ecb00) at Bounds.cpp:613:5
    frame #8: 0x000000010186101d mx-index`clang::declvisitor::Base<std::__1::add_pointer, pasta::(anonymous namespace)::DeclBoundsFinder, void>::VisitNamedDecl(this=0x000070001cc87ec0, D=0x00007fa8781ecb00) at DeclNodes.inc:107:1
    frame #9: 0x0000000101861a1d mx-index`clang::declvisitor::Base<std::__1::add_pointer, pasta::(anonymous namespace)::DeclBoundsFinder, void>::VisitTypeDecl(this=0x000070001cc87ec0, D=0x00007fa8781ecb00) at DeclNodes.inc:277:1
    frame #10: 0x000000010185fb0d mx-index`clang::declvisitor::Base<std::__1::add_pointer, pasta::(anonymous namespace)::DeclBoundsFinder, void>::VisitTemplateTypeParmDecl(this=0x000070001cc87ec0, D=0x00007fa8781ecb00) at DeclNodes.inc:325:1
    frame #11: 0x000000010185d1a1 mx-index`clang::declvisitor::Base<std::__1::add_pointer, pasta::(anonymous namespace)::DeclBoundsFinder, void>::Visit(this=0x000070001cc87ec0, D=0x00007fa8781ecb00) at DeclNodes.inc:325:1
    frame #12: 0x000000010185bf33 mx-index`pasta::(anonymous namespace)::DeclBoundsFinder::Visit(this=0x000070001cc87ec0, decl=0x00007fa8781ecb00) at Bounds.cpp:591:24
    frame #13: 0x000000010185a46a mx-index`pasta::(anonymous namespace)::DeclBoundsFinder::GetBounds(this=0x000070001cc87ec0, decl=0x00007fa8781ecb00) at Bounds.cpp:1609:5
    frame #14: 0x000000010185a1a8 mx-index`pasta::ASTImpl::DeclBounds(this=0x00007fa878008a18, decl=0x00007fa8781ecb00) at Bounds.cpp:1682:33
    frame #15: 0x000000010185a80f mx-index`pasta::ASTImpl::DeclTokenRange(this=0x00007fa878008a18, decl_=0x00007fa8781ecb00, locker=unique_lock<std::__1::mutex> @ 0x000070001cc880c8) at Bounds.cpp:1689:28
    frame #16: 0x000000010185b765 mx-index`pasta::ASTImpl::DeclTokenRange(this=0x00007fa878008a18, decl_=0x00007fa8781ecb00) at Bounds.cpp:1706:10