[llvm-bugs] [Bug 45021] New: Destructor called for a stack object never constructed

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 25 04:47:55 PST 2020


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

            Bug ID: 45021
           Summary: Destructor called for a stack object never constructed
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: boris at codesynthesis.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

We have a program that crashes in a destructor called for a stack object
that appears to have never been constructed. The destructor is called
during stack unwinding caused by throwing (and catching) an exception.

This only happens with Clang targeting MSVC and only when the program
is compiled with optimization (-O3) and linked statically (but still
using the DLL msvcrt). This affects Clang 9.0.1 and 10.0.0-rc2.

So far we were unable to create a small reproducer and I am not very
hopeful that we will since the issue appears to be specific to the
code setup/path that we have. However, I would be happy to provide
instructions on how to reproduce the issue under a debugger in the
program directly (it is open source). Below I am also including extra
details in case they may help.

You can see the two complete build logs that only differ in the static
linking bit here (this is using Clang 9.0.1):

https://stage.build2.org/?builds=build2&cf=windows_10-clang_9.0_llvm_msvc_16.4-*O3

In particular, the C++ compiler invocations are the same sans a few
macros that setup DLL importing in the shared case.

Below is a stack trace. The debugger attaches the the following message
to the "b.exe!butl::fdclose(int fd) Line 1482 C++" line:

"Unhandled exception at 0x00007FFCCC24D5B8 (ucrtbase.dll) in b.exe: An
invalid parameter was passed to a function that considers invalid
parameters fatal."

The crash happens when an exception is thrown at line 1250[1] trying to
destroy the fdpipe object. The only fdpipe object that could possibly
be being destroyed here is constructed *below* at line 1520[2]. So it
feels like something is wrong with the exception handing tables.

[1]
https://github.com/build2/build2/blob/master/libbuild2/test/script/runner.cxx#L1250
[2]
https://github.com/build2/build2/blob/master/libbuild2/test/script/runner.cxx#L1520

  ucrtbase.dll!00007ffccc24d5b8()       Unknown
  ucrtbase.dll!00007ffccc24d481()       Unknown
  ucrtbase.dll!00007ffccc24d559()       Unknown
  ucrtbase.dll!00007ffccc226d33()       Unknown
  b.exe!butl::fdclose(int fd) Line 1482 C++
  [Inline Frame] b.exe!butl::auto_fd::reset(int fd) Line 12     C++
  [Inline Frame] b.exe!butl::auto_fd::~auto_fd() Line 27        C++
  [Inline Frame] b.exe!butl::fdpipe::~fdpipe() Line 821 C++
  b.exe!build2::test::script::run_pipe(build2::test::script::scope & sp,
std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<build2::test::script::command>>>
bc,
std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<build2::test::script::command>>>
ec, butl::auto_fd ifd, unsigned __int64 ci, unsigned __int64 li, const
build2::location & ll, bool diag) Line 1994       C++
  [External Code]
  [Inline Frame]
b.exe!build2::fail_mark_base::fail_mark_base::<unnamed-tag>::operator()(const
butl::diag_record & r) Line 447  C++
  b.exe!build2::fail_mark_base::fail_mark_base::<unnamed-tag>::__invoke(const
butl::diag_record & r) Line 443   C++
  [Inline Frame] b.exe!butl::diag_record::flush() Line 192      C++
  b.exe!butl::diag_record::~diag_record() Line 206      C++
  b.exe!build2::test::script::run_pipe(build2::test::script::scope & sp,
std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<build2::test::script::command>>>
bc,
std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<build2::test::script::command>>>
ec, butl::auto_fd ifd, unsigned __int64 ci, unsigned __int64 li, const
build2::location & ll, bool diag) Line 1250       C++
  b.exe!build2::test::script::run_pipe(build2::test::script::scope & sp,
std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<build2::test::script::command>>>
bc,
std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<build2::test::script::command>>>
ec, butl::auto_fd ifd, unsigned __int64 ci, unsigned __int64 li, const
build2::location & ll, bool diag) Line 1820       C++
  b.exe!build2::test::script::run_expr(build2::test::script::scope & sp, const
std::vector<build2::test::script::expr_term,std::allocator<build2::test::script::expr_term>>
& expr, unsigned __int64 li, const build2::location & ll, bool diag) Line 2049 
    C++
  b.exe!build2::test::script::default_runner::run(build2::test::script::scope &
sp, const
std::vector<build2::test::script::expr_term,std::allocator<build2::test::script::expr_term>>
& expr, build2::test::script::command_type ct, unsigned __int64 li, const
build2::location & ll) Line 2084       C++
 
b.exe!build2::test::script::parser::exec_lines(std::_Vector_iterator<std::_Vector_val<std::_Simple_types<build2::test::script::line>>>
i,
std::_Vector_iterator<std::_Vector_val<std::_Simple_types<build2::test::script::line>>>
e, unsigned __int64 & li, build2::test::script::command_type ct) Line 3210  C++
  b.exe!build2::test::script::parser::exec_scope_body() Line 3115       C++
  [Inline Frame]
b.exe!build2::test::script::parser::execute(build2::test::script::scope & sc,
build2::test::script::script & s, build2::test::script::runner & r) Line 2910  
 C++
  b.exe!build2::test::script::execute_impl(build2::test::script::scope & s,
build2::test::script::script & scr, build2::test::script::runner & r) Line 2920
    C++
  [Inline Frame]
b.exe!build2::test::script::parser::exec_scope_body::<unnamed-tag>::operator()(const
build2::diag_frame * ds, build2::test::script::scope & s,
build2::test::script::script & scr, build2::test::script::runner & r) Line 3075
C++
  b.exe!build2::scheduler::async<`lambda at
C:\temp\cfg\build2-0.13.0-a.0.20200224125633.f749aab34924\libbuild2\test\script\parser.cxx:3069:39',const
build2::diag_frame
*&,std::reference_wrapper<build2::test::script::scope>,std::reference_wrapper<build2::test::script::script>,std::reference_wrapper<build2::test::script::runner>>(unsigned
__int64 start_count, std::atomic<unsigned long long> & task_count,
build2::test::script::parser::exec_scope_body::<unnamed-tag> && f, const
build2::diag_frame * & a, std::reference_wrapper<build2::test::script::scope>
&& a, std::reference_wrapper<build2::test::script::script> && a,
std::reference_wrapper<build2::test::script::runner> && a) Line 25       C++
  [Inline Frame] b.exe!build2::scheduler::async(std::atomic<unsigned long long>
& task_count, build2::test::script::parser::exec_scope_body::<unnamed-tag> &&
f, const build2::diag_frame * & a,
std::reference_wrapper<build2::test::script::scope> && a,
std::reference_wrapper<build2::test::script::script> && a,
std::reference_wrapper<build2::test::script::runner> && a) Line 85        C++
  b.exe!build2::test::script::parser::exec_scope_body() Line 3068       C++
  [Inline Frame]
b.exe!build2::test::script::parser::execute(build2::test::script::scope & sc,
build2::test::script::script & s, build2::test::script::runner & r) Line 2910  
 C++
  b.exe!build2::test::script::parser::execute(build2::test::script::script & s,
build2::test::script::runner & r) Line 2890     C++
  [Inline Frame] b.exe!build2::test::perform_script_impl(const build2::target &
t, const build2::test::testscript & ts, const
butl::basic_path<char,butl::dir_path_kind<char>> & wd, const
build2::test::common & c) Line 370   C++
  b.exe!build2::test::rule::perform_script::<unnamed-tag>::operator()(const
build2::diag_frame * ds, build2::test::script::scope_state & r, const
build2::target & t, const build2::test::testscript & ts, const
butl::basic_path<char,butl::dir_path_kind<char>> & wd) Line 553        C++
  [Inline Frame] b.exe!build2::scheduler::async(unsigned __int64 start_count,
std::atomic<unsigned long long> & task_count,
build2::test::rule::perform_script::<unnamed-tag> && f, const
build2::diag_frame * && a,
std::reference_wrapper<build2::test::script::scope_state> && a,
std::reference_wrapper<const build2::target> && a, std::reference_wrapper<const
build2::test::testscript> && a, std::reference_wrapper<const
butl::basic_path<char,butl::dir_path_kind<char>>> && a) Line 25       C++
  b.exe!build2::test::rule::perform_script(build2::action a, const
build2::target & t, unsigned __int64 pass_n) Line 544        C++
  [External Code]
  [Inline Frame]
b.exe!std::_Func_class<build2::target_state,build2::action,const build2::target
&>::operator()(build2::action _Args, const build2::target & _Args) Line 969   
C++
  b.exe!build2::execute_recipe(build2::action t, build2::target & r, const
std::function<build2::target_state (build2::action, const build2::target &)> &)
Line 1020    C++
  b.exe!build2::execute_impl(build2::action t, build2::target &) Line 1583     
C++
  [Inline Frame] b.exe!build2::execute::<unnamed-tag>::operator()(const
build2::diag_frame * ds, build2::target & t) Line 1696  C++
  [Inline Frame] b.exe!build2::scheduler::async(unsigned __int64 start_count,
std::atomic<unsigned long long> & task_count, build2::execute::<unnamed-tag> &&
f, const build2::diag_frame * && a, std::reference_wrapper<build2::target> &&
a) Line 25  C++
  b.exe!build2::execute(build2::action a, const build2::target & ct, unsigned
__int64 start_count, std::atomic<unsigned long long> * task_count) Line 1691   
  C++
  [Inline Frame] b.exe!build2::execute_async(build2::action a, const
build2::target & t, unsigned __int64 sc, std::atomic<unsigned long long> & tc,
bool fail) Line 561 C++
  b.exe!build2::execute(const butl::small_vector<build2::value,1> &,
build2::action a, build2::action_targets & ts, unsigned short diag, bool prog)
Line 349    C++
  b.exe!build2::main(int argc, char * * argv) Line 1595 C++
  [External Code]

-- 
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/20200225/a9c2aff7/attachment.html>


More information about the llvm-bugs mailing list