This is an archive of the discontinued LLVM Phabricator instance.

[SPIRV][NFC] fix build warning in SPIRVUtils.cpp
ClosedPublic

Authored by iliya-diyachkov on Jan 30 2023, 2:16 PM.

Details

Summary

This patch fixes the following build warning from gcc in SPIRVUtils.cpp after D142532 changes:

[ 83%] Building CXX object lib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVUtils.cpp.o
/storage/home/idyachkov/spirv/llvm-project/llvm/lib/Target/SPIRV/SPIRVUtils.cpp: In function \u2018llvm::SPIRV::MemorySemantics::MemorySemantics llvm::getMemSemantics(llvm::AtomicOrdering)\u2019:
/storage/home/idyachkov/spirv/llvm-project/llvm/lib/Target/SPIRV/SPIRVUtils.cpp:211:1: warning: control reaches end of non-void function [-Wreturn-type]
 }

The patched code is Ok with gcc and llvm, but I have not tested MSVC compiler.

Diff Detail

Event Timeline

iliya-diyachkov requested review of this revision.Jan 30 2023, 2:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 30 2023, 2:16 PM

@iliya-diyachkov Thanks! I will check with MSVC.

@iliya-diyachkov I updated Visual Studio and there seems to be many more problems with building with MSVC (table below). There are no warnings in SPIRVUtils.cpp.

SeverityCodeDescriptionProjectFileLineSuppression State
Error (active)E0266"llvm::SPIRV::InstructionSet" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp31
Error (active)E0266"llvm::SPIRV::InstructionSet" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp58
Error (active)E0266"llvm::SPIRV::InstructionSet" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp86
Error (active)E0266"llvm::SPIRV::BuiltIn" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp87
Error (active)E0266"llvm::SPIRV::InstructionSet" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp96
Error (active)E0266"llvm::SPIRV::InstructionSet" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp105
Error (active)E0266"llvm::SPIRV::FPRoundingMode" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp109
Error (active)E0266"llvm::SPIRV::FPRoundingMode" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp117
Error (active)E0266"llvm::SPIRV::InstructionSet" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp114
Error (active)E0266"llvm::SPIRV::AccessQualifier" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp1926
Error (active)E0266"llvm::SPIRV::Dim" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp1927
Error (active)E0266"llvm::SPIRV::ImageFormat" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp1932
Error (active)E0266"llvm::SPIRV::AccessQualifier" is ambiguousLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp1937
Error (active)E1776function "std::unique_ptr<_Ty, _Dx>::unique_ptr(const std::unique_ptr<_Ty, _Dx> &) [with _Ty=llvm::SPIRV::PipeType, _Dx=std::default_delete<llvm::SPIRV::PipeType>]" (declared at line 3256 of "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.34.31933\include\memory") cannot be referenced -- it is a deleted functionLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp2022
Error (active)E1776function "std::unique_ptr<_Ty, _Dx>::unique_ptr(const std::unique_ptr<_Ty, _Dx> &) [with _Ty=llvm::SPIRV::PipeType, _Dx=std::default_delete<llvm::SPIRV::PipeType>]" (declared at line 3256 of "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.34.31933\include\memory") cannot be referenced -- it is a deleted functionLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp2025
Error (active)E1776function "std::unique_ptr<_Ty, _Dx>::unique_ptr(const std::unique_ptr<_Ty, _Dx> &) [with _Ty=llvm::SPIRV::PipeType, _Dx=std::default_delete<llvm::SPIRV::PipeType>]" (declared at line 3256 of "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.34.31933\include\memory") cannot be referenced -- it is a deleted functionLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp2028
ErrorC2398Element '1': conversion from 'const llvm::SPIRV::FPRoundingMode::FPRoundingMode' to 'unsigned int' requires a narrowing conversionLLVMSPIRVCodeGenC:\Users\mpaszkow\Projects\llvm-project\llvm\lib\Target\SPIRV\SPIRVBuiltins.cpp1736
mpaszkowski added a comment.EditedFeb 1 2023, 8:03 AM

One (more important) note, only the last error "Element '1': conversion from 'const llvm::SPIRV::FPRoundingMode::FPRoundingMode' to 'unsigned int' requires a narrowing conversion" shows up during compilation and causes it to break. All the other errors show up only in IntelliSense in Visual Studio. This seems to be a known issue with Visual Studio.

Adding a cast to uint32_t in SPIRVBuiltins.cpp on line 1736, seems to fix all the build issues:

SPIRV::Decoration::FPRoundingMode, {(uint32_t)Builtin->RoundingMode});

This cast should be safe here. I think there is currently no option to change the type of TableGen generated enums to unsigned. @iliya-diyachkov Could you include this change in the patch?

Fix the MSVC build issue as suggested by Michal.

mpaszkowski accepted this revision.Feb 2 2023, 10:44 AM

Thank you! LGTM!

This revision is now accepted and ready to land.Feb 2 2023, 10:44 AM
This revision was automatically updated to reflect the committed changes.