circle
circle copied to clipboard
Compiler segfaults on auto brace initialization
Given code that tries to brace initialize an auto variable with an empty brace, or multiple values (more than one), the compiler crashes with a segmentation fault. Reproducable with the latest build on both godbolt and locally.
auto a{};
auto a{1,2};
Attached local run inside of valgrind for context (Using the first example, the include related args are due to #124 :
~/code/circle ⵃ valgrind /opt/circle/circle --nostdinc \
-I/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/include \
-I/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/include/c++ \
-I/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/include/c++/x86_64-pc-linux-gnu main.cxx
==49507== Memcheck, a memory error detector
==49507== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==49507== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==49507== Command: /opt/circle/circle --nostdinc -I/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/include -I/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/include/c++ -I/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/include/c++/x86_64-pc-linux-gnu main.cxx
==49507==
==49507== Invalid read of size 4
==49507== at 0x51B649: sema::stmt_builder_t::object_init(sema::decl_object_t*, std::unique_ptr<sema::arg_t, std::default_delete<sema::arg_t> >, source_loc_t) (in /opt/circle/circle)
==49507== by 0x51C6B6: sema::stmt_builder_t::decl_init(sema::decl_t*, std::unique_ptr<sema::arg_t, std::default_delete<sema::arg_t> >, source_loc_t) (in /opt/circle/circle)
==49507== by 0x812726: fe::decl_builder_t::declare_objectlike(fe::decl_builder_t::parse_t&, fe::range_t&, bool&) (in /opt/circle/circle)
==49507== by 0x80F868: fe::decl_builder_t::process_declaration(fe::decl_builder_t::parse_t&, fe::range_t&, bool) (in /opt/circle/circle)
==49507== by 0x80DA66: fe::decl_builder_t::regular_declarations(fe::range_t, bool) (in /opt/circle/circle)
==49507== by 0x80820C: fe::decl_builder_t::parse(fe::range_t, bool) (in /opt/circle/circle)
==49507== by 0x818A6B: fe::grammar_t::simple_declaration(fe::range_t, bool, llvm::SmallVector<std::unique_ptr<sema::template_header_t, std::default_delete<sema::template_header_t> >, 1u>*) (in /opt/circle/circle)
==49507== by 0x8191AE: fe::grammar_t::declaration_statement(fe::range_t, bool, llvm::SmallVector<std::unique_ptr<sema::template_header_t, std::default_delete<sema::template_header_t> >, 1u>*) (in /opt/circle/circle)
==49507== by 0x7F7254: fe::grammar_t::generic_statement(fe::range_t, meta_prefix_t) (in /opt/circle/circle)
==49507== by 0x7F6EC4: fe::grammar_t::statement(fe::syntax_stmt_t*) (in /opt/circle/circle)
==49507== by 0x7F6C8C: fe::grammar_t::statements(llvm::SmallVector<std::unique_ptr<fe::syntax_stmt_t, std::default_delete<fe::syntax_stmt_t> >, 2u>&) (in /opt/circle/circle)
==49507== by 0x4433FF: main (in /opt/circle/circle)
==49507== Address 0x9 is not stack'd, malloc'd or (recently) free'd
==49507==
==49507==
==49507== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==49507== Access not within mapped region at address 0x9
==49507== at 0x51B649: sema::stmt_builder_t::object_init(sema::decl_object_t*, std::unique_ptr<sema::arg_t, std::default_delete<sema::arg_t> >, source_loc_t) (in /opt/circle/circle)
==49507== by 0x51C6B6: sema::stmt_builder_t::decl_init(sema::decl_t*, std::unique_ptr<sema::arg_t, std::default_delete<sema::arg_t> >, source_loc_t) (in /opt/circle/circle)
==49507== by 0x812726: fe::decl_builder_t::declare_objectlike(fe::decl_builder_t::parse_t&, fe::range_t&, bool&) (in /opt/circle/circle)
==49507== by 0x80F868: fe::decl_builder_t::process_declaration(fe::decl_builder_t::parse_t&, fe::range_t&, bool) (in /opt/circle/circle)
==49507== by 0x80DA66: fe::decl_builder_t::regular_declarations(fe::range_t, bool) (in /opt/circle/circle)
==49507== by 0x80820C: fe::decl_builder_t::parse(fe::range_t, bool) (in /opt/circle/circle)
==49507== by 0x818A6B: fe::grammar_t::simple_declaration(fe::range_t, bool, llvm::SmallVector<std::unique_ptr<sema::template_header_t, std::default_delete<sema::template_header_t> >, 1u>*) (in /opt/circle/circle)
==49507== by 0x8191AE: fe::grammar_t::declaration_statement(fe::range_t, bool, llvm::SmallVector<std::unique_ptr<sema::template_header_t, std::default_delete<sema::template_header_t> >, 1u>*) (in /opt/circle/circle)
==49507== by 0x7F7254: fe::grammar_t::generic_statement(fe::range_t, meta_prefix_t) (in /opt/circle/circle)
==49507== by 0x7F6EC4: fe::grammar_t::statement(fe::syntax_stmt_t*) (in /opt/circle/circle)
==49507== by 0x7F6C8C: fe::grammar_t::statements(llvm::SmallVector<std::unique_ptr<fe::syntax_stmt_t, std::default_delete<fe::syntax_stmt_t> >, 2u>&) (in /opt/circle/circle)
==49507== by 0x4433FF: main (in /opt/circle/circle)
==49507== If you believe this happened as a result of a stack
==49507== overflow in your program's main thread (unlikely but
==49507== possible), you can try to increase the size of the
==49507== main thread stack using the --main-stacksize= flag.
==49507== The main thread stack size used in this run was 8388608.
==49507==
==49507== HEAP SUMMARY:
==49507== in use at exit: 4,370,324 bytes in 24,898 blocks
==49507== total heap usage: 31,842 allocs, 6,944 frees, 7,369,409 bytes allocated
==49507==
==49507== LEAK SUMMARY:
==49507== definitely lost: 432 bytes in 3 blocks
==49507== indirectly lost: 0 bytes in 0 blocks
==49507== possibly lost: 4,608 bytes in 2 blocks
==49507== still reachable: 4,365,284 bytes in 24,893 blocks
==49507== of which reachable via heuristic:
==49507== newarray : 34,024 bytes in 5 blocks
==49507== multipleinheritance: 4,160 bytes in 44 blocks
==49507== suppressed: 0 bytes in 0 blocks
==49507== Rerun with --leak-check=full to see details of leaked memory
==49507==
==49507== For lists of detected and suppressed errors, rerun with: -s
==49507== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)