Skip to content

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

Description

@onitake

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: digego/extempore#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); }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

buildIssues related to build and setup

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions