Created attachment 22688 [details] Test program Hello, My system is Windows 10 with clang 9.0.0 (installed with https://releases.llvm.org/9.0.0/LLVM-9.0.0-win64.exe) and Microsoft Visual Studio Community 2019, Version 16.3.1. Under some circumstances a non-empty string passed into a function is seen by the function code as an empty string. The attached program reproduces the issue. It is expected to print 'abc' but prints '' if compiled with -O2 or -O3: > clang++ -std=c++2a test.cxx > a.exe 'abc' >clang++ -std=c++2a -O2 test.cxx >a.exe '' Note that the issue also reproduces if compile with clang-cl: > clang-cl /std:c++17 /EHsc test.cxx > test.exe 'abc' > clang-cl /std:c++17 /EHsc /O2 test.cxx > test.exe '' Also note that the attached program is not exactly trivial but I was unable to reduce it further.
This works for me at head, I see 'abc' with optimizations. The exception handling makes me suspect this is a duplicate of 43585, which has to do with preserving XMM callee saved registers. I haven't confirmed that to be the case. That bug is already fixed, but we never merged it to 9.0. I think we should: - merge r370005 to 9.0.1 branch (and revert r367088 from it) - rebuild 9.0 compiler - run this test case, see if it still repros - close the issue as a duplicate if that fixes it
Any progress on this? It would be really helpful if this were fixed in 9.0.1. Also, seeing that the problem is only triggered when an exception is thrown, this could be affecting a lot more code than we realize.
I did the following: - checked out and compiled the 9.0.1 candidate - confirmed that this bug affects the release candidate with the attached test - patched in 564fb58a32a808c34d809820d00e2f23c0307a71 and rebuilt - confirmed that the patch fixes the test (prints 'abc') - pushed an update to release/9.x: https://github.com/llvm/llvm-project/commit/9a9b6492a66c3f83e58f5b4e451797b6baf7f3ea
*** Bug 43900 has been marked as a duplicate of this bug. ***
We have managed to reproduce the issue with a single (though not exactly trivial) source file. Normally, the attached program creates a pipe, closes its ends and exits: c:\tmp>clang++ -g test.cxx c:\tmp>a.exe pipe: 3 4 fdclose: 4 fdclose: 3 exit However, when it is built optimized it tries to close the pipe input twice and crashes inside the _close() function: c:\tmp>clang++ -O3 -g test.cxx c:\tmp>a.exe pipe: 3 4 fdclose: 4 fdclose: 3 fdclose: 3 The last fdclose call is not expected to happen. The stack trace is attached.
Sorry, please disregard the last comment which is added to the wrong bug.