question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

C++ crashes on new test ParserExec/ListLabelsOnRuleRefStartOfAlt.txt

See original GitHub issue

Looks like there’s an issue in ArrayPredictionContext::equals() exposed by this test from this Test.cpp line:

  tree::ParseTree *tree = parser.expression();

Run

$ cd ~/antlr/code/antlr4/runtime/Cpp
$ cmake . -DTRACE_ATN=ON -DCMAKE_BUILD_TYPE=Debug

Then from test dir we get :

$ cat input
a and b
$ ln -s /Users/parrt/antlr/code/antlr4/runtime/Cpp/dist/libantlr4-runtime.dylib 
$ clang++ -g -std=c++17 -I /Users/parrt/antlr/code/antlr4/runtime/Cpp/runtime/src -L. -lantlr4-runtime *.cpp
$ ./a.out input
Segmentation fault: 11

and see from lldb (with Debug mode for cmake build of lib):

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001013167e4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::operator==(lhs=0x0000000000000000, rhs=0x0000000000000000) at PredictionContext.h:206:16
   203 	  };
   204 	
   205 	  inline bool operator==(const PredictionContext &lhs, const PredictionContext &rhs) {
-> 206 	    return lhs.equals(rhs);
   207 	  }
   208 	
   209 	  inline bool operator!=(const PredictionContext &lhs, const PredictionContext &rhs) {

and trace:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00000001013167e4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::operator==(lhs=0x0000000000000000, rhs=0x0000000000000000) at PredictionContext.h:206:16
    frame #1: 0x0000000101346c10 libantlr4-runtime.4.10.1.dylib`(anonymous namespace)::predictionContextEqual(lhs=nullptr, rhs=nullptr) at ArrayPredictionContext.cpp:25:17
    frame #2: 0x0000000101346b80 libantlr4-runtime.4.10.1.dylib`bool std::__1::equal<std::__1::__wrap_iter<std::__1::shared_ptr<antlr4::atn::PredictionContext const> const*>, std::__1::__wrap_iter<std::__1::shared_ptr<antlr4::atn::PredictionContext const> const*>, bool (*)(std::__1::shared_ptr<antlr4::atn::PredictionContext const> const&, std::__1::shared_ptr<antlr4::atn::PredictionContext const> const&)>(__first1=__wrap_iter<const std::__1::shared_ptr<const antlr4::atn::PredictionContext> *> @ 0x000000016fdfb6a0, __last1=__wrap_iter<const std::__1::shared_ptr<const antlr4::atn::PredictionContext> *> @ 0x000000016fdfb698, __first2=__wrap_iter<const std::__1::shared_ptr<const antlr4::atn::PredictionContext> *> @ 0x000000016fdfb690, __pred=(libantlr4-runtime.4.10.1.dylib`(anonymous namespace)::predictionContextEqual(std::__1::shared_ptr<antlr4::atn::PredictionContext const> const&, std::__1::shared_ptr<antlr4::atn::PredictionContext const> const&) at ArrayPredictionContext.cpp:24))(std::__1::shared_ptr<antlr4::atn::PredictionContext const> const&, std::__1::shared_ptr<antlr4::atn::PredictionContext const> const&)) at equal.h:31:10
    frame #3: 0x0000000101346994 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ArrayPredictionContext::equals(this=0x000000016fdfba68, other=0x00006000026058d8) const at ArrayPredictionContext.cpp:82:10
    frame #4: 0x00000001013167f0 libantlr4-runtime.4.10.1.dylib`antlr4::atn::operator==(lhs=0x000000016fdfba68, rhs=0x00006000026058d8) at PredictionContext.h:206:16
    frame #5: 0x0000000101395120 libantlr4-runtime.4.10.1.dylib`antlr4::atn::PredictionContext::mergeArrays(a=std::__1::shared_ptr<const antlr4::atn::ArrayPredictionContext>::element_type @ 0x00006000026058d8 strong=4 weak=1, b=std::__1::shared_ptr<const antlr4::atn::ArrayPredictionContext>::element_type @ 0x0000600002605b78 strong=1 weak=1, rootIsWildcard=false, mergeCache=0x0000600003504028) at PredictionContext.cpp:411:9
    frame #6: 0x0000000101393320 libantlr4-runtime.4.10.1.dylib`antlr4::atn::PredictionContext::merge(a=std::__1::shared_ptr<const antlr4::atn::PredictionContext>::element_type @ 0x00006000026058d8 strong=4 weak=1, b=std::__1::shared_ptr<const antlr4::atn::PredictionContext>::element_type @ 0x0000600002104068 strong=45 weak=1, rootIsWildcard=false, mergeCache=0x0000600003504028) at PredictionContext.cpp:210:10
    frame #7: 0x0000000101318564 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ATNConfigSet::add(this=0x0000000100405be0, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605b18 strong=1 weak=1, mergeCache=0x0000600003504028) at ATNConfigSet.cpp:64:41
    frame #8: 0x00000001013799b4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605b18 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:890:14
    frame #9: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605b18 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #10: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605ab8 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #11: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605ab8 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #12: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605a58 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #13: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605a58 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #14: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x00006000026059f8 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #15: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x00006000026059f8 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #16: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605998 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #17: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605998 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #18: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605938 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #19: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605938 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #20: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605878 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #21: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605878 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #22: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605818 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #23: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605818 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #24: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x00006000026057b8 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #25: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x00006000026057b8 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #26: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605638 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #27: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605638 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=-1, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #28: 0x0000000101379734 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605578 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=0, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:868:9
    frame #29: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605518 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=0, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #30: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605518 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=0, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #31: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x00006000026053f8 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=0, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #32: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x00006000026053f8 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=0, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #33: 0x0000000101379e3c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure_(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605218 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=0, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:959:7
    frame #34: 0x00000001013797d4 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closureCheckingStopState(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605218 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, depth=0, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:880:3
    frame #35: 0x000000010137939c libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::closure(this=0x0000600003504000, config=std::__1::shared_ptr<antlr4::atn::ATNConfig>::element_type @ 0x0000600002605218 strong=1 weak=1, configs=0x0000000100405be0, closureBusy=size=0, collectPredicates=false, fullCtx=true, treatEofAsEpsilon=false) at ParserATNSimulator.cpp:825:3
    frame #36: 0x00000001013777b8 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::computeReachSet(this=0x0000600003504000, closure_=0x00000001004058e0, t=4, fullCtx=true) at ParserATNSimulator.cpp:523:7
    frame #37: 0x0000000101376dd8 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::execATNWithFullContext(this=0x0000600003504000, dfa=0x00000001004048b0, D=0x00006000029055e0, s0=0x0000000100405460, input=0x000000016fdfece0, startIndex=1, outerContext=0x0000600002c08200) at ParserATNSimulator.cpp:355:13
    frame #38: 0x0000000101375be8 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::execATN(this=0x0000600003504000, dfa=0x00000001004048b0, s0=0x0000600002905570, input=0x000000016fdfece0, startIndex=1, outerContext=0x0000600002c08200) at ParserATNSimulator.cpp:238:20
    frame #39: 0x0000000101374f20 libantlr4-runtime.4.10.1.dylib`antlr4::atn::ParserATNSimulator::adaptivePredict(this=0x0000600003504000, input=0x000000016fdfece0, decision=4, outerContext=0x0000600002c08200) at ParserATNSimulator.cpp:155:16
    frame #40: 0x0000000100009c28 a.out`TestParser::expression(this=0x000000016fdfedb0, precedence=0) at TestParser.cpp:227:54
    frame #41: 0x0000000100009904 a.out`TestParser::expression(this=0x000000016fdfedb0) at TestParser.cpp:179:11
    frame #42: 0x0000000100001758 a.out`main(argc=2, argv=0x000000016fdff148) at Test.cpp:31:34
    frame #43: 0x000000010006908c dyld`start + 520

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mike-lischkecommented, Aug 29, 2022

Right, null is not expected in predictionContextEqual. It could be changed to do so, but IMO the correct solution is to check if parents is empty, something like:

bool ArrayPredictionContext::equals(const PredictionContext &other) const {//
  if (this == std::addressof(other)) {
    return true;
  }
  if (getContextType() != other.getContextType()) {
    return false;
  }
  const auto &array = downCast<const ArrayPredictionContext&>(other);
  return returnStates.size() == array.returnStates.size() &&
         parents.size() == array.parents.size() &&
         cachedHashCodeEqual(cachedHashCode(), array.cachedHashCode()) &&
         std::memcmp(returnStates.data(), array.returnStates.data(), returnStates.size() * sizeof(decltype(returnStates)::value_type)) == 0 &&
         (parents.size() == 0 || std::equal(parents.begin(), parents.end(), array.parents.begin(), predictionContextEqual));
}

Also, splitting this large set of tests into individual lines would increase readability significantly.

0reactions
parrtcommented, Nov 14, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash affecting iOS 15/15.1 on iPad | Apple Developer Forums
But we see a lot of crashes in the appstoreconnect analytics data. There were no reports of crashes from users. This bug cannot...
Read more >
Test instrumentation process crashed - where is the .txt file?
If you are working with an emulator, in A.S open Device File Explorer and go to: /data/user_de/0/android.support.test.orchestrator/files/, ...
Read more >
Adobe Photoshop Crashes when using Text Tool
Solved: Hi There, When using Adobe Photoshop CC 2017, when we I use the text tool after I enter the text a few...
Read more >
Detect and diagnose crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by ... locally reproduce the crash, either by manually testing the app or ......
Read more >
Game crashes or closes unexpectedly - Microsoft Support
Symptoms of the problem · Method 1: Check for the latest update for the game · Method 2: Restart the computer by using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found