LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 43710 - clang++ miscompiles against MSVC standard library with -O2
Summary: clang++ miscompiles against MSVC standard library with -O2
Status: RESOLVED FIXED
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: 9.0
Hardware: PC other
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
: 43900 (view as bug list)
Depends on:
Blocks: release-9.0.1
  Show dependency tree
 
Reported: 2019-10-18 05:57 PDT by Karen Arutyunov
Modified: 2020-02-28 05:37 PST (History)
7 users (show)

See Also:
Fixed By Commit(s): 564fb58a32a8 9a9b6492a66c


Attachments
Test program (593 bytes, text/x-c++src)
2019-10-18 05:57 PDT, Karen Arutyunov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Karen Arutyunov 2019-10-18 05:57:31 PDT
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.
Comment 1 Reid Kleckner 2019-10-18 11:15:07 PDT
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
Comment 2 Boris Kolpackov 2019-11-04 23:03:19 PST
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.
Comment 3 Reid Kleckner 2019-11-05 12:59:26 PST
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
Comment 4 Reid Kleckner 2019-11-05 14:33:55 PST
*** Bug 43900 has been marked as a duplicate of this bug. ***
Comment 5 Karen Arutyunov 2020-02-28 05:28:53 PST Comment hidden (obsolete)
Comment 6 Karen Arutyunov 2020-02-28 05:37:08 PST Comment hidden (obsolete)