llvm / llvm/llvm-project

Clang rejects gcc extension of allowing vector reinterpret_cast in constant expressions

Open
#213,243 5 comments 0 reactions 0 assignees View on GitHub
clang:frontend constexpr diverges-from:gcc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

[Test case](https://compiler-explorer.com/z/Eh4erPMsq):

```c++
using V0 [[gnu::vector_size(16)]] = int;
using V1 [[gnu::vector_size(16)]] = float;

constexpr V0 x = reinterpret_cast(V1());
```

GCC set the precedent of bit-casting vectors via `reinterpret_cast`. It does so with additional semantic information (i.e. higher quality diagnostics on errors), which is why the libstdc++ std::simd implementation prefers `reinterpret_cast` over `std::bit_cast`. However, Clang rejects these casts in constant expressions, which is incompatible to GCC.

Proposed resolution: Allow "reinterpret-cast by value of GNU vectors" in constant expressions.

Contributor guide

Open the contributing guide

Research direction

Start with the linked Compiler Explorer test case and inspect Clang's constant-expression handling for GNU vector reinterpret_cast expressions. Compare the behavior with GCC and the stated libstdc++ std::simd use case. Done means the shown constexpr cast is accepted by Clang while invalid cases retain useful diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.