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

consteval union constants result in IR containing incorrectly-typed stores #46711

Open
llvmbot opened this issue Aug 31, 2020 · 3 comments
Open
Labels
bugzilla Issues migrated from bugzilla c++20 consteval C++20 consteval

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 31, 2020

Bugzilla Link 47367
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

Works in clang-10.0.1 but not in clang trunk.

code example:
https://godbolt.org/z/j4bGxx

Furthermore this slight variation works:
https://godbolt.org/z/beMvE9

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Sep 1, 2020

Reduced:

template<typename T, typename U>
struct variant {
union { T t; U u; };
constexpr variant(T t) : t(t) {}
constexpr U &get() { return u; }
};

struct Sum {};
struct Value {
int value;
};

consteval auto foo() {
variant<Sum, Value> result = Sum{};
return result;
}

int main() {
auto result = foo();
return result.get().value;
}

The generated IR (https://godbolt.org/z/vq4jhq) looks OK to me; the only slightly unusual thing here is an FCA store of undef:

store { %struct.Sum, [3 x i8] } undef, %union.anon* %4, align 4

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Sep 1, 2020

This version crashes in Clang's IR generation instead, but only when using libstdc++ (with libc++ it crashes in InstCombine like the other testcases): https://godbolt.org/z/xzK9Pr

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Sep 1, 2020

... actually, the store in comment#1 is clearly bogus: the type being stored is different from the type of the destination pointer. (I'm a little surprised that doesn't fail the verifier.)

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@usx95 usx95 added the consteval C++20 consteval label Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++20 consteval C++20 consteval
Projects
Status: No status
Development

No branches or pull requests

2 participants