Compile error:unreachable code #1038

Closed
opened 2025-05-22 04:24:06 -05:00 by mi2think · 3 comments
mi2think commented 2025-05-22 04:24:06 -05:00 (Migrated from github.com)

I got wired complile error with VS2022, any solutions?

1>I:\vcpkg\installed\x64-windows-static\include\xxhash.h(3169): error C2220: the following warning is treated as an error
1>I:\vcpkg\installed\x64-windows-static\include\xxhash.h(3169): warning C4702: unreachable code

3169 line is h32 = XXH32_mergeAccs(acc); in function XXH32_endian_align

Anyone has same error?

I got wired complile error with VS2022, any solutions? ``` 1>I:\vcpkg\installed\x64-windows-static\include\xxhash.h(3169): error C2220: the following warning is treated as an error 1>I:\vcpkg\installed\x64-windows-static\include\xxhash.h(3169): warning C4702: unreachable code ``` 3169 line is `h32 = XXH32_mergeAccs(acc);` in function `XXH32_endian_align ` Anyone has same error?
t-mat commented 2025-05-22 05:58:08 -05:00 (Migrated from github.com)

Hi @mi2think,

We need further details of your issue/project. Could you provide how to reproduce your issue?


It seems you're using vcpkg. At least in my environment, I don't hit any issue with genuine VS2022 + MSVC + xxhash from vcpkg.
Please check the following project and command:

  • Open new terminal with : Windows Start Button > Developer Command Prompt for VS 2022.
  • Input the following commands in the developer command prompt:
cd /d "%PUBLIC%"
mkdir xxhash-issue-1038
cd    xxhash-issue-1038
curl.exe -JOL https://github.com/user-attachments/files/20390302/xxhash-issue-1038-msvc-project.zip
tar.exe xvf xxhash-issue-1038-msvc-project.zip
msbuild.exe .\xxhash-issue-1038.sln /p:Configuration="Release" /p:Platform="x64"
.\x64\Release\xxhash-issue-1038.exe

msbuild doesn't report any error. And the output is:

XXH_versionNumber=803

xxhash-issue-1038-msvc-project.zip

Hi @mi2think, We need further details of your issue/project. Could you provide how to reproduce your issue? ---- It seems you're using vcpkg. At least in my environment, I don't hit any issue with genuine VS2022 + MSVC + xxhash from vcpkg. Please check the following project and command: - Open new terminal with : Windows Start Button > Developer Command Prompt for VS 2022. - Input the following commands in the developer command prompt: ``` cd /d "%PUBLIC%" mkdir xxhash-issue-1038 cd xxhash-issue-1038 curl.exe -JOL https://github.com/user-attachments/files/20390302/xxhash-issue-1038-msvc-project.zip tar.exe xvf xxhash-issue-1038-msvc-project.zip msbuild.exe .\xxhash-issue-1038.sln /p:Configuration="Release" /p:Platform="x64" .\x64\Release\xxhash-issue-1038.exe ``` `msbuild` doesn't report any error. And the output is: ``` XXH_versionNumber=803 ``` [xxhash-issue-1038-msvc-project.zip](https://github.com/user-attachments/files/20390302/xxhash-issue-1038-msvc-project.zip)
mi2think commented 2025-05-22 20:10:02 -05:00 (Migrated from github.com)

Thanks for your replay. After done as you saied, it output 0 errors & 0 warnings, and XXH_versionNumber=803. So it's a wired error.

I'm compiling zen server project . In linking stage, detail error as below:

------ Build started: Project: zenserver, Configuration: release x64 ------
$xmake config -y  -P . -p windows -m release -a x64 -o "build"
$xmake build -y  -P .  "zenserver"
[ 99%]: linking.release zenserver.exe
EXEC : error : LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
Generating code
I:\vcpkg\installed\x64-windows-static\include\xxhash.h(3169): error C2220: the following warning is treated as an error
I:\vcpkg\installed\x64-windows-static\include\xxhash.h(3169): warning C4702: unreachable code
LINK : fatal error LNK1257: code generation failed

VS2022 version is : 17.14.1 and after switch to 17.8.21 same error.

Thanks for your replay. After done as you saied, it output 0 errors & 0 warnings, and `XXH_versionNumber=803`. So it's a wired error. I'm compiling [zen server project](https://github.com/EpicGames/zen) . In linking stage, detail error as below: ``` ------ Build started: Project: zenserver, Configuration: release x64 ------ $xmake config -y -P . -p windows -m release -a x64 -o "build" $xmake build -y -P . "zenserver" [ 99%]: linking.release zenserver.exe EXEC : error : LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library Generating code I:\vcpkg\installed\x64-windows-static\include\xxhash.h(3169): error C2220: the following warning is treated as an error I:\vcpkg\installed\x64-windows-static\include\xxhash.h(3169): warning C4702: unreachable code LINK : fatal error LNK1257: code generation failed ``` VS2022 version is : `17.14.1` and after switch to `17.8.21` same error.
Cyan4973 commented 2026-09-16 18:44:51 -05:00 (Migrated from github.com)

The issue has been reproduced and fixed in ##1139.

I can't understand why MSVC complains about that,
the code becomes unreachable as a result of its own optimization due to constant propagation at LTO time,
which is actually a good thing (the optimizer is right), hence no reason to complain about it.

Fixed by disabling C4702 locally.

The issue has been reproduced and fixed in ##1139. I can't understand why MSVC complains about that, the code becomes unreachable *as a result of its own optimization* due to constant propagation at LTO time, which is actually a good thing (the optimizer is right), hence no reason to complain about it. Fixed by disabling `C4702` locally.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Cyan4973/xxHash#1038
No description provided.