This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix msvc 17.3 build.
ClosedPublic

Authored by Meinersbur on Aug 24 2022, 12:38 PM.

Details

Summary

Compile fix for Microsoft Visual Studio 17.3 (msvc 14.33.31629) which regressed from 17.1.

The compile error is:

llvm-project\flang\lib\Evaluate\fold-integer.cpp(802,41): error C2672: 'invoke': no matching overloaded function found
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\type_traits(1552,19): message : could be 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 &&...) noexcept(<expr>)'
llvm-project\flang\lib\Evaluate\fold-integer.cpp(802,41): message : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 &&...) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\type_traits(1552): message : see declaration of 'std::invoke'
llvm-project\flang\lib\Evaluate\fold-integer.cpp(490,1): message : With the following template arguments:
llvm-project\flang\lib\Evaluate\fold-integer.cpp(490,1): message : '_Callable=int (__cdecl Fortran::evaluate::value::Integer<16,true,16,unsigned short,unsigned int>::* &)(void) const'
llvm-project\flang\lib\Evaluate\fold-integer.cpp(490,1): message : '_Ty1=const Fortran::evaluate::value::Integer<8,true,8,unsigned char,unsigned short> &'
llvm-project\flang\lib\Evaluate\fold-integer.cpp(490,1): message : '_Types2={}'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\type_traits(1546,19): message : or       'unknown-type std::invoke(_Callable &&) noexcept(<expr>)'
C:\Users\meinersbur\src\llvm-project\flang\lib\Evaluate\fold-integer.cpp(802,41): message : 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)': expects 1 arguments - 2 provided

For some reason, msvc thinks that the lambda argument is Scalar<T> instead of Scalar<TI> as declared. This only happens in nested closures, using a lambda without [] arguments makes the problem disappear. Using auto instead to automatically derive the type fixes the problem.

I recently updated the version of Visual Studio on flang-x86_64-windows buildbot which since then fails because of this problem. It occasionally failed with 'fatal error C1001: Internal compiler error." internal error which I hoped to fix with an update.

Diff Detail

Event Timeline

Meinersbur created this revision.Aug 24 2022, 12:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2022, 12:38 PM
Meinersbur requested review of this revision.Aug 24 2022, 12:38 PM
klausler accepted this revision.Aug 24 2022, 12:44 PM
klausler added inline comments.
flang/lib/Evaluate/fold-integer.cpp
804

Please add a comment that this unexpected usage is meant to work around a particular compiler problem, as has been done at other code sites where workarounds have been needed. It helps explain why the code is more general than necessary, and can also be a valuable assist to programmers confronted with similar C++ compiler bugs in newer code.

This revision is now accepted and ready to land.Aug 24 2022, 12:44 PM

Add source comment explaining this is a workaround

This revision was landed with ongoing or failed builds.Aug 24 2022, 2:48 PM
This revision was automatically updated to reflect the committed changes.

Microsoft's bugtracker indicates that this was fixed in msvc 19.34.31933 / VS17.4