microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.08k stars 686 forks source link

Compilation with gcc 8.1 fails due to missing cast on unique_ptr #1692

Closed onitake closed 5 years ago

onitake commented 5 years ago

Title

Compilation with gcc 8.1 fails due to missing explicit cast on unique_ptr

Functional impact

It is not possible to build dxc on systems that use gcc 8.1 or newer (such as Debian testing).

Minimal repro steps

Attempt compilation with cmake 3.12.3 and gcc 8.2.0, although the issue is also present in gcc 8.1.

Expected result

Compilation succeeds.

Actual result

The following compilation error is thrown:

[ 24%] Building CXX object lib/HLSL/CMakeFiles/LLVMHLSL.dir/DxilLinker.cpp.o
In file included from /dxc/include/llvm/Transforms/Utils/Cloning.h:24,
                 from /dxc/lib/HLSL/DxilLinker.cpp:26:
/dxc/include/llvm/IR/ValueMap.h: In member function ‘bool llvm::ValueMap<KeyT, ValueT, Config>::hasMD() const’:
/dxc/include/llvm/IR/ValueMap.h:102:31: error: cannot convert ‘const std::unique_ptr<llvm::DenseMap<const llvm::Metadata*, llvm::TrackingMDRef> >’ to ‘bool’ in return
   bool hasMD() const { return MDMap; }

Further technical details

This is a known issue that has been reported and fixed elsewhere: https://github.com/digego/extempore/issues/318

The C++ standard specifies operator bool on unique_ptr as being explicit, so this is clearly a bug in the LLVM source code: https://en.cppreference.com/w/cpp/memory/unique_ptr/operator_bool

It can be fixed by adding an explicit cast:

bool hasMD() const { return bool(MDMap); }

or:

bool hasMD() const { return static_cast<bool>(MDMap); }
ehsannas commented 5 years ago

Thanks for reporting and detailed information :)