llvm/llvm-project

[clang] Bitcasts from vectors to integers not supported at compile time

Open

#159.905 geöffnet am 20. Sept. 2025

Auf GitHub ansehen
 (14 Kommentare) (0 Reaktionen) (1 zugewiesene Person)C++ (10.782 Forks)batch import
clang:frontendconstexprgood first issue

Repository-Metriken

Stars
 (26.378 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 1T 2h) (1.000 gemergte PRs in 30 T)

Beschreibung

I have test case that seems to regressed for latest constexpr changes.

#include<immintrin.h>
constexpr
__m64 foo(__m64 a, int b){
    return (__m64)(long long)a << b;
}
int main(){
    foo((__m64){5},1);
    return 0;
}

gcc-trunk works fine. clang-trunk errors out.

<source>:3:7: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
    3 | __m64 foo(__m64 a, int b){
      |       ^~~
<source>:4:19: note: subexpression not valid in a constant expression
    4 |     return (__m64)(long long)a << b;

Following change passed

#include<immintrin.h>
constexpr
__m64 foo(__m64 a, int b){
    if(b > 63)
        return (__m64){0};
    return (__m64)(long long)a << b;
}
int main(){
    foo((__m64){5},1);
    return 0;
}

here is repro https://godbolt.org/z/d7obEcb57 Does anyone know what may be trouble here?

Contributor Guide