Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
onitake opened this issue Nov 12, 2018 · 1 comment · Fixed by #1720
Closed

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

onitake opened this issue Nov 12, 2018 · 1 comment · Fixed by #1720
Assignees
Labels
build Issues related to build and setup

Comments

@onitake
Copy link

onitake commented Nov 12, 2018

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); }
@hekota hekota added the build Issues related to build and setup label Nov 12, 2018
@ehsannas
Copy link
Contributor

Thanks for reporting and detailed information :)

@tristanlabelle tristanlabelle self-assigned this Nov 19, 2018
mfwitten added a commit to mfwitten/SPIRV-LLVM that referenced this issue Sep 21, 2019
The aging LLVM code is converting an object of type `unique_ptr` to an
object of type `bool`, but is doing so implicitly, thereby causing a
compile-time error with modern, standards-compliant compilers.

This is explained well here:

    microsoft/DirectXShaderCompiler#1692

In particular:

> 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

This commit merely makes the conversion explicit, allowing
the code to be built by GCC version 9.1.0.

This bug was fixed by the LLVM project proper as part of
the following commit (more than 4 years ago):

    69341e6abca92f7f118ee7bd99be0cdfc649386f
    llvm/llvm-project@69341e6
mfwitten added a commit to mfwitten/SPIRV-LLVM that referenced this issue Sep 21, 2019
The aging LLVM code is converting  an object of type `unique_ptr` to
an object  of type  `bool`; this is  being done  implicitly, thereby
causing  a compile-time  error  with  a modern,  standards-compliant
compiler.

This is explained well here:

    microsoft/DirectXShaderCompiler#1692

In particular:

> 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

This commit merely makes the  conversion explicit, allowing the code
to be built by GCC version 9.1.0.

This  bug was  fixed  by the  LLVM  project proper  as  part of  the
following commit:

    69341e6abca92f7f118ee7bd99be0cdfc649386f
    2016-04-08
    llvm/llvm-project@69341e6
pikamonvvs referenced this issue in frasercrmck/llvm-leg Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues related to build and setup
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants