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

[clang++ Bug] subobject of type 'unsigned int' is not initialized #98

Closed
AFN4096 opened this issue Jan 19, 2020 · 1 comment
Closed

Comments

@AFN4096
Copy link

AFN4096 commented Jan 19, 2020

The following code compiled successfully with MSVC, GCC(C++11), but failed with CLANG(C++11)

#include <iostream>
#include <stdexcept>
 
int main()
{
    union Reg{
        struct {
            unsigned int A1                           :  8;
            unsigned int                                : 24;
        } bits, bitfields;
    
        unsigned int u32All;
        signed int   i32All;
        float        f32All;
    };

    constexpr uint MaxTargets = 8;

    constexpr struct
    {
        Reg a[MaxTargets];
        Reg b[MaxTargets];
        Reg c[MaxTargets];
        Reg d[MaxTargets];
    } base = {};

    std::cout << base.a[0].f32All << std::endl;
}

Error Information:

main.cpp:25:7: error: constexpr variable 'base' must be initialized by a constant expression
    } base = {};
      ^      ~~
main.cpp:25:7: note: subobject of type 'unsigned int' is not initialized
1 error generated.

Could be workaround by following modification code

#include <iostream>
#include <stdexcept>
 
int main()
{
    union Reg{
        struct {
            unsigned int  A1                           :  8;
            unsigned int  A2                              : 24;
        } bits, bitfields;
    
        unsigned int u32All;
        signed int   i32All;
        float        f32All;
    };

    constexpr uint MaxTargets = 8;

    constexpr struct
    {
        Reg a[MaxTargets];
        Reg b[MaxTargets];
        Reg c[MaxTargets];
        Reg d[MaxTargets];
    } base = {};

    std::cout << base.a[0].f32All << std::endl;
}

and

#include <iostream>
#include <stdexcept>
 
int main()
{
    union Reg{
        unsigned int u32All;
        signed int   i32All;
        float        f32All;

        struct {
            unsigned int  A1                           :  8;
            unsigned int  A2                            : 24;
        } bits, bitfields;

    };

    constexpr uint MaxTargets = 8;

    constexpr struct
    {
        Reg a[MaxTargets];
        Reg b[MaxTargets];
        Reg c[MaxTargets];
        Reg d[MaxTargets];
    } base = {};

    std::cout << base.a[0].f32All << std::endl;
}

Could someone look into this issue? The problem exists in c++11/14/17.

@AFN4096
Copy link
Author

AFN4096 commented Jan 22, 2020

Ok, find the issue has been solved in >= clang 6.0.

@AFN4096 AFN4096 closed this as completed Jan 22, 2020
jamesmth pushed a commit to jamesmth/llvm-project that referenced this issue Dec 5, 2022
Removes the prototype builtin and intrinsic for i64x2.eq and implements that
instruction as well as the other i64x2 comparison instructions in the final SIMD
spec. Unsigned comparisons were not included in the final spec, so they still
need to be scalarized via a custom lowering.

Differential Revision: https://reviews.llvm.org/D99623

Co-authored-by: Thomas Lively <[email protected]>
searlmc1 referenced this issue in ROCm/llvm-project Aug 23, 2023
…-exclude-pattern

Move install directories inside the if statement
cuviper pushed a commit to cuviper/llvm-project that referenced this issue Aug 27, 2023
Removes the prototype builtin and intrinsic for i64x2.eq and implements that
instruction as well as the other i64x2 comparison instructions in the final SIMD
spec. Unsigned comparisons were not included in the final spec, so they still
need to be scalarized via a custom lowering.

Differential Revision: https://reviews.llvm.org/D99623

Co-authored-by: Thomas Lively <[email protected]>
mjklemm pushed a commit to mjklemm/llvm-project that referenced this issue Jun 27, 2024
usx95 added a commit that referenced this issue Jul 18, 2024
RevySR pushed a commit to revyos/llvm-project that referenced this issue Jul 27, 2024
* [LLVM][XTHeadVector] Implement 16.7-16.8 `viota/vid`

* [LLVM][XTHeadVector] Test 16.7-16.8 `viota/vid`
alexanderguy pushed a commit to alexanderguy/llvm-project that referenced this issue Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant