Semantic Predicate that returns false is giving segmentation fault (ANTLR4 C++ target)

152 views
Skip to first unread message

Cleverson Ledur

unread,
Oct 24, 2016, 3:42:32 PM10/24/16
to antlr-discussion
I am parsing C++ using ANTLR4 C++ target. Currently i am implementing some semantic predicates to enable a correct AST construction, but i am having some troubles when these return false.


First Attempt:


I did a very simple test with the following grammar rule:

simple_type_specifier
:
     
{false}? type_name
   
{
       
/* Actions */
   
}
   
| ...
;



I compile and when I run any example this gives a segmentation fault. GDB gives the following details:


Program received signal SIGSEGV, Segmentation fault.
0x0000000000fdf19b in antlr4::atn::ArrayPredictionContext::operator==(antlr4::atn::PredictionContext const&) const ()

Backtrace:

#0  0x0000000000fdf19b in antlr4::atn::ArrayPredictionContext::operator==(antlr4::atn::PredictionContext const&) const ()
#1  0x0000000000fa34ee in antlr4::atn::PredictionModeClass::getConflictingAltSubsets(antlr4::atn::ATNConfigSet*) ()
#2
 
0x0000000000fa3f8b in
antlr4
::atn::PredictionModeClass::hasSLLConflictTerminatingPrediction(antlr4::atn::PredictionMode,
 antlr4
::atn::ATNConfigSet*) ()
#3
 
0x0000000000f8ab77 in
antlr4
::atn::ParserATNSimulator::computeTargetState(antlr4::dfa::DFA&,
 antlr4
::dfa::DFAState*, long) ()
#4
 
0x0000000000f8eea4 in
antlr4
::atn::ParserATNSimulator::execATN(antlr4::dfa::DFA&,
antlr4
::dfa::DFAState*, antlr4::TokenStream*, unsigned long,
std
::shared_ptr<antlr4::ParserRuleContext>) ()
#5
 
0x0000000000f91ace in
antlr4
::atn::ParserATNSimulator::adaptivePredict(antlr4::TokenStream*,
int, std::shared_ptr<antlr4::ParserRuleContext> const&) ()
#6
 
0x0000000000c07dab in antlrcpptest::cincleParser::postfix_expression
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:2925
#7  0x0000000000c14f30 in antlrcpptest::cincleParser::unary_expression (this=0x7fffffffdd10) at generated/cincleParser.cpp:3912
#8  0x0000000000c251eb in antlrcpptest::cincleParser::cast_expression (this=0x7fffffffdd10) at generated/cincleParser.cpp:5429
#9
 
0x0000000000c261db in antlrcpptest::cincleParser::pm_expression
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:5531
#10
 
0x0000000000c27c08 in
antlrcpptest
::cincleParser::multiplicative_expression
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:5675
#11
 
0x0000000000c29d10 in antlrcpptest::cincleParser::additive_expression
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:5841
#12
 
0x0000000000c2b706 in antlrcpptest::cincleParser::shift_expression
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:5981
#13
 
0x0000000000c2d17c in antlrcpptest::cincleParser::relational_expression
 
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:6129
#14
 
0x0000000000c2f9a0 in antlrcpptest::cincleParser::equality_expression
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:6321
#15
 
0x0000000000c31356 in antlrcpptest::cincleParser::and_expression
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:6457
#16
 
0x0000000000c32570 in
antlrcpptest
::cincleParser::exclusive_or_expression
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:6559
#17
 
0x0000000000c3378a in
antlrcpptest
::cincleParser::inclusive_or_expression
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:6661
#18
 
0x0000000000c349a4 in
antlrcpptest
::cincleParser::logical_and_expression (this=0x7fffffffdd10,
 precedence
=0) at generated/cincleParser.cpp:6763
#19
 
0x0000000000c35bbe in antlrcpptest::cincleParser::logical_or_expression
 
(this=0x7fffffffdd10, precedence=0) at generated/cincleParser.cpp:6865
#20
 
0x0000000000c37a0c in
antlrcpptest
::cincleParser::conditional_expression (this=0x7fffffffdd10)
 at generated
/cincleParser.cpp:7045
#21
 
0x0000000000c38ab4 in antlrcpptest::cincleParser::assignment_expression
 
(this=0x7fffffffdd10) at generated/cincleParser.cpp:7146
#22
 
0x0000000000cbdea5 in antlrcpptest::cincleParser::initializer_clause
(this=0x7fffffffdd10) at generated/cincleParser.cpp:20051
#23
 
0x0000000000cbd202 in
antlrcpptest
::cincleParser::brace_or_equal_initializer
(this=0x7fffffffdd10) at generated/cincleParser.cpp:19973
#24 0x0000000000cbc329 in antlrcpptest::cincleParser::initializer (this=0x7fffffffdd10) at generated/cincleParser.cpp:19884
#25 0x0000000000c9c67a in antlrcpptest::cincleParser::init_declarator (this=0x7fffffffdd10) at generated/cincleParser.cpp:16573



Second Attempt:


I also tried to move the semantic predicate for the right resulting in the following rule:

simple_type_specifier
:
     type_name
{false}?   
    {
       
/* Actions */
   
}
   
| ...
;


Then this gives me the following errors:

File or directory not found

Backtrace:

Program received signal SIGSEGV, Segmentation fault.
malloc_consolidate
(av=av@entry=0x7ffff7334b00 <main_arena>) at malloc.c:4216
4216    malloc.c: File or directory not found.
(gdb) backtrace
#0  malloc_consolidate (av=av@entry=0x7ffff7334b00 <main_arena>) at malloc.c:4216
#1  0x00007ffff7014cea in _int_malloc (av=av@entry=0x7ffff7334b00 <main_arena>, bytes=bytes@entry=1592) at malloc.c:3485
#2  0x00007ffff7016d94 in __GI___libc_malloc (bytes=1592) at malloc.c:2925
#3  0x00007ffff78e3798 in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x0000000000f7f98c in std::_Hashtable<std::shared_ptr<antlr4::atn::ATNConfig>, std::shared_ptr<antlr4::atn::ATNConfig>, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> >, std::__detail::_Identity, antlr4::atn::ATNConfig::Comparer, antlr4::atn::ATNConfig::Hasher, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, true, true> >::_M_insert_unique_node(unsigned long, unsigned long, std::__detail::_Hash_node<std::shared_ptr<antlr4::atn::ATNConfig>, true>*) ()
#5  0x0000000000f7e681 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#6  0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#7  0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#8  0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#9  0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#10 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#11 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#12 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#13 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#14 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<st---Type <return> to continue, or q <return> to quit---
d
::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#15 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#16 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#17 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#18 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#19 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#20 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#21 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#22 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#23 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#24 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#25 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#26 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#27 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<st---Type <return> to continue, or q <return> to quit---
d
::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#28 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#29 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#30 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#31 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#32 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#33 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#34 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#35 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#36 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#37 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#38 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#39 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#40 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<st---Type <return> to continue, or q <return> to quit---
d
::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#41 0x0000000000f7ecda in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#42 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#43 0x0000000000f7ede1 in antlr4::atn::LL1Analyzer::_LOOK(antlr4::atn::ATNState*, antlr4::atn::ATNState*, std::shared_ptr<antlr4::atn::PredictionContext> const&, antlr4::misc::IntervalSet&, std::unordered_set<std::shared_ptr<antlr4::atn::ATNConfig>, antlr4::atn::ATNConfig::Hasher, antlr4::atn::ATNConfig::Comparer, std::allocator<std::shared_ptr<antlr4::atn::ATNConfig> > >&, antlrcpp::BitSet&, bool, bool) const ()
#44 0x0000000000f7de07 in antlr4::atn::LL1Analyzer::LOOK(antlr4::atn::ATNState*, std::shared_ptr<antlr4::RuleContext> const&) const ()
#45 0x0000000000f74bda in antlr4::atn::ATN::nextTokens(antlr4::atn::ATNState*) const ()
#46 0x0000000000fd11b2 in antlr4::DefaultErrorStrategy::sync(antlr4::Parser*) ()

#47 0x0000000000c54502 in antlrcpptest::cincleParser::declaration_seq (this=0x7fffffffdd10) at generated/cincleParser.cpp:9615
#48 0x0000000000be8e87 in antlrcpptest::cincleParser::translation_unit (this=0x7fffffffdd10) at generated/cincleParser.cpp:102


The question is: Am i using the semantic predicates correctly? My objective is to call a function inside the semantic predicate that receives the token text and performs verifications using declaration information of previously parsed things.

Thank you.

Mike Lischke

unread,
Oct 24, 2016, 3:55:39 PM10/24/16
to antlr-di...@googlegroups.com
Hi Cleverson,

I am parsing C++ using ANTLR4 C++ target. Currently i am implementing some semantic predicates to enable a correct AST construction, but i am having some troubles when these return false.


First Attempt:


I did a very simple test with the following grammar rule:

simple_type_specifier
:
     
{false}? type_name
   
{
       
/* Actions */
   
}
   
| ...
;


That sounds like the problem we discussed here: https://groups.google.com/forum/#!topic/antlr-discussion/yn38o1QCK9Q. The predicate is false which in turn throws a recognition exception which does a double free. See if this patch: https://github.com/DanMcLaughlin/antlr4/commit/014070de66de68e943bb159779372e63da5e4849 helps you.

Cleverson Ledur

unread,
Oct 25, 2016, 1:11:54 PM10/25/16
to antlr-discussion
Hi Mike,

I tried the patch in RecognitionException.h but the error keeps the same.

Also, I tested using another grammar (https://github.com/antlr/grammars-v4/tree/master/cpp) just to be sure it is not my grammar is causing this, but I am having the same problem. I just inserted a semantic predication
{false}? in a rule and this gives me a segmentation fault error.

Do you have any other suggestion?

Thank you

Mike Lischke

unread,
Oct 26, 2016, 6:10:22 AM10/26/16
to antlr-di...@googlegroups.com
> I tried the patch in RecognitionException.h but the error keeps the same.
>
> Also, I tested using another grammar (https://github.com/antlr/grammars-v4/tree/master/cpp) just to be sure it is not my grammar is causing this, but I am having the same problem. I just inserted a semantic predication {false}? in a rule and this gives me a segmentation fault error.

Well, this problem is not a grammar issue. If ANTLR accepts the grammar then there is no issue on this side.

>
> Do you have any other suggestion?

I cannot reproduce this problem locally, so it seems as if that has been fixed already. I plan to push my recent changes over the weekend and create new packages for download. After that you can try again and hopefully it's also gone for you.

Mike
--
www.soft-gems.net

Cleverson Ledur

unread,
Oct 31, 2016, 7:26:37 AM10/31/16
to antlr-discussion
Hi Mike,

Ok, I will wait the new packages for download to test again.

Thank you very much.

Cleverson Ledur

Mike Lischke

unread,
Nov 5, 2016, 11:17:08 AM11/5/16
to antlr-di...@googlegroups.com
Hi Cleverson,

Ok, I will wait the new packages for download to test again.

I just updated all files on my homepage. See if that now solves your issue.

Cleverson Ledur

unread,
Nov 6, 2016, 11:49:11 AM11/6/16
to antlr-discussion
Hi Mike,

I tested using the updated files but the problem keeps. Now I am getting the following error just inserting the {false}? before the identifier:

Program received signal SIGSEGV, Segmentation fault.
0x000055555576291b in antlr4::atn::ArrayPredictionContext::operator==(antlr4::atn::PredictionContext const&) const ()
(gdb) backtrace
#0  0x000055555576291b in antlr4::atn::ArrayPredictionContext::operator==(antlr4::atn::PredictionContext const&) const ()
#1  0x000055555572cbb6 in antlr4::atn::PredictionModeClass::getConflictingAltSubsets(antlr4::atn::ATNConfigSet*) ()
#2  0x000055555572d68d in antlr4::atn::PredictionModeClass::hasSLLConflictTerminatingPrediction(antlr4::atn::PredictionMode, antlr4::atn::ATNConfigSet*) ()
#3  0x0000555555714682 in antlr4::atn::ParserATNSimulator::computeTargetState(antlr4::dfa::DFA&, antlr4::dfa::DFAState*, unsigned long) ()
#4  0x000055555571706c in antlr4::atn::ParserATNSimulator::execATN(antlr4::dfa::DFA&, antlr4::dfa::DFAState*, antlr4::TokenStream*, unsigned long, antlr4::ParserRuleContext*) ()
#5  0x000055555571adc6 in antlr4::atn::ParserATNSimulator::adaptivePredict(antlr4::TokenStream*, unsigned long, antlr4::ParserRuleContext*) ()
#6  0x0000555555661454 in antlrcpptest::CPPParser::condition (this=0x7fffffffdb80) at generated/CPPParser.cpp:4725
#7  0x0000555555662023 in antlrcpptest::CPPParser::iterationstatement (this=0x7fffffffdb80) at generated/CPPParser.cpp:4898
#8  0x000055555565ef6e in antlrcpptest::CPPParser::statement (this=0x7fffffffdb80) at generated/CPPParser.cpp:4212
#9  0x00005555556607ee in antlrcpptest::CPPParser::statementseq (this=0x7fffffffdb80, precedence=0) at generated/CPPParser.cpp:4556
#10 0x00005555556601b6 in antlrcpptest::CPPParser::compoundstatement (this=0x7fffffffdb80) at generated/CPPParser.cpp:4480
#11 0x000055555567eec9 in antlrcpptest::CPPParser::functionbody (this=0x7fffffffdb80) at generated/CPPParser.cpp:11312
#12 0x000055555567e9d2 in antlrcpptest::CPPParser::functiondefinition (this=0x7fffffffdb80) at generated/CPPParser.cpp:11243
#13 0x00005555556645fe in antlrcpptest::CPPParser::declaration (this=0x7fffffffdb80) at generated/CPPParser.cpp:5430
#14 0x0000555555664048 in antlrcpptest::CPPParser::declarationseq (this=0x7fffffffdb80, precedence=0) at generated/CPPParser.cpp:5346
#15 0x000055555564a932 in antlrcpptest::CPPParser::translationunit (this=0x7fffffffdb80) at generated/CPPParser.cpp:69
#16 0x000055555563aec7 in main (argc=2, argv=0x7fffffffe1a8) at generated/main.cpp:64


This is the grammar that is giving this error:

type_name
:
   
{false}? classname
   
| enumname
   
| typedefname
   
| simpletemplateid
;

Just for understanding. The actions for each rule are executed only if the semantic predication is true, right?

Cleverson Ledur

unread,
Nov 29, 2016, 11:06:59 AM11/29/16
to antlr-discussion
Hi Mike,


Do you have any other suggestion?

Thanks



Em segunda-feira, 24 de outubro de 2016 17:42:32 UTC-2, Cleverson Ledur escreveu:

Mike Lischke

unread,
Nov 29, 2016, 11:27:08 AM11/29/16
to antlr-di...@googlegroups.com
Hi Cleverson,

> Do you have any other suggestion?


Unfortunately, I haven't come around looking at that. Long e-mail backlog :-( I'll do as soon as I can.

Mike
--
www.soft-gems.net

Mike Lischke

unread,
Dec 10, 2016, 9:02:19 AM12/10/16
to antlr-di...@googlegroups.com
HI Cleverson,

Do you have any other suggestion?

I have a hard time to reproduce this problem. I simply can't. I'm using predicates a lot and haver never seen this problem in grammars either. Maybe it just doesn't show up on Mac or Win. Maybe you could create a simple demo app that exhibits the problem, but I have not much hope it will help. The only other option I see is that you try to debug what's going on there. When it crashes there that usually means the prediction context is no longer valid. The question is: is it freed prematurely or why is it invalid?


Thanks


Em segunda-feira, 24 de outubro de 2016 17:42:32 UTC-2, Cleverson Ledur escreveu:
I am parsing C++ using ANTLR4 C++ target. Currently i am implementing some semantic predicates to enable a correct AST construction, but i am having some troubles when these return false.


First Attempt:


I did a very simple test with the following grammar rule:

simple_type_specifier
:
     
{false}? type_name
   
{
       
/* Actions */
   
}
   
| ...
;


Reply all
Reply to author
Forward
0 new messages