[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 21 01:14:59 PDT 2023
================
@@ -140,11 +140,12 @@ void g28(void) {
typedef short v12i16 __attribute((vector_size(24)));
typedef long double v2f80 __attribute((vector_size(24)));
// CHECK: @g28.a = internal global <1 x i64> <i64 10>
- // CHECK: @g28.b = internal global <12 x i16> <i16 0, i16 0, i16 0, i16 -32768, i16 16383, i16 0, i16 0, i16 0, i16 0, i16 -32768, i16 16384, i16 0>
- // CHECK: @g28.c = internal global <2 x x86_fp80> <x86_fp80 0xK3FFF8000000000000000, x86_fp80 0xK40008000000000000000>, align 32
+ // @g28.b = internal global <12 x i16> <i16 0, i16 0, i16 0, i16 -32768, i16 16383, i16 0, i16 0, i16 0, i16 0, i16 -32768, i16 16384, i16 0>
+ // @g28.c = internal global <2 x x86_fp80> <x86_fp80 0xK3FFF8000000000000000, x86_fp80 0xK40008000000000000000>, align 32
static v1i64 a = (v1i64)10LL;
- static v12i16 b = (v12i16)(v2f80){1,2};
- static v2f80 c = (v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
+ //FIXME: support constant bitcast between vectors of x86_fp80
+ //static v12i16 b = (v12i16)(v2f80){1,2};
+ //static v2f80 c = (v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
----------------
DaMatrix wrote:
So, on further investigation, it looks like the diagnostic isn't being emitted at all because the constant evaluation code is called with an `EvalInfo` which has diagnostics disabled, and is never called again.
https://github.com/llvm/llvm-project/blob/72f63b695c9ebd9c7032c4b754ff7965c28fad5c/clang/lib/AST/Expr.cpp#L3486
https://github.com/llvm/llvm-project/blob/72f63b695c9ebd9c7032c4b754ff7965c28fad5c/clang/lib/AST/ExprConstant.cpp#L15483-L15485
And once it's been evaluted with no diagnostic, an `diag::err_init_element_not_constant` is emitted which triggers an error and so it never gets evaluated again with diagnostics enabled.
https://github.com/llvm/llvm-project/blob/72f63b695c9ebd9c7032c4b754ff7965c28fad5c/clang/lib/Sema/SemaDecl.cpp#L12510-L12514
What should I do here? This feels like a weakness of the code in Sema; any changes I make here are going to break a bunch of tests which expect no diagnostics to be output in these cases.
https://github.com/llvm/llvm-project/pull/66894
More information about the cfe-commits
mailing list