Bug 24125 – ImportC: vector type initializer not understood

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-08-31T15:20:46Z
Last change time
2023-11-23T04:10:52Z
Keywords
ImportC, pull
Assigned to
Walter Bright
Creator
Steven Schveighoffer

Comments

Comment #0 by schveiguy — 2023-08-31T15:20:46Z
In GCC, an example of a vector type is declared like this: ```c typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__)); ``` And is used with an initializer/literal like this: ```c return (__m128){ 0.0f, 0.0f, 0.0f, 0.0f }; ``` ImportC doesn't recognize the type as an "brace"-initializable thing. Also note the error message (Error: unrecognized C initializer `{0.0F, 0.0F, 0.0F, 0.0F}`) is quite confusing, as it does look like a valid initializer in some contexts. It really should say "Error: C initializer `{0.0F, 0.0F, 0.0F, 0.0F}` cannot be use to initialize type `__m128`"
Comment #1 by bugzilla — 2023-09-12T06:09:27Z
A more complete example: --- typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__)); __m128 test() { return (__m128){ 0.0f, 0.0f, 0.0f, 0.0f }; } ---
Comment #2 by bugzilla — 2023-11-20T05:48:01Z
Looks like there are two problems. The first is: typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__)); This doesn't recognize __m128 as a vector. But this works: typedef float __attribute__ ((__vector_size__ (16), __may_alias__)) __m128; Now __m128 is recognized as a vector. Then it goes on to fail with: Error: cannot implicitly convert expression `[0.0F, 0.0F, 0.0F, 0.0F]` of type `float*` to `__vector(float[4])`
Comment #3 by schveiguy — 2023-11-20T14:11:42Z
(In reply to Walter Bright from comment #2) > Looks like there are two problems. The first is: > > typedef float __m128 __attribute__ ((__vector_size__ (16), > __may_alias__)); > > This doesn't recognize __m128 as a vector. But this works: > > typedef float __attribute__ ((__vector_size__ (16), __may_alias__)) > __m128; I may have copied the header code wrong... I'll double check. That does look more reasonable.
Comment #4 by schveiguy — 2023-11-20T14:16:56Z
Hm.. nope, that's the exact code. So that does still need addressing.
Comment #5 by dlang-bot — 2023-11-21T04:28:46Z
@WalterBright created dlang/dmd pull request #15838 "Fix Issue 24125 - ImportC: vector type initializer not understood" fixing this issue: - fix Issue 24125 - ImportC: vector type initializer not understood - fix Issue 24125 - ImportC: vector type initializer not understood https://github.com/dlang/dmd/pull/15838
Comment #6 by dlang-bot — 2023-11-23T04:10:52Z
dlang/dmd pull request #15838 "Fix Issue 24125 - ImportC: vector type initializer not understood" was merged into master: - 785a5a6dd2d87bba88a46d4ab8b5816309cef9f2 by Walter Bright: fix Issue 24125 - ImportC: vector type initializer not understood - eca6b07f424fe726a53596f31dc0a4860faec771 by Walter Bright: fix Issue 24125 - ImportC: vector type initializer not understood https://github.com/dlang/dmd/pull/15838