<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84315>84315</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Assigning to `__real` or `__imag` of an uninitialized local complex variable at compile time asserts
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
constexpr
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tbaederr
</td>
</tr>
</table>
<pre>
This code:
```c++
constexpr bool b() {
_Complex float A;// = {3.0, 3.0};
_Complex float B = {4.0, 2.0};
__real(A) = 4.0;
__imag(A) = 2.0;
return A == B;
}
static_assert(b());
```
https://godbolt.org/z/v59jxqMhE
asserts:
```
clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:3828: typename SubobjectHandler::result_type findSubobject({anonymous}::EvalInfo&, const clang::Expr*, const {anonymous}::CompleteObject&, const {anonymous}::SubobjectDesignator&, SubobjectHandler&) [with SubobjectHandler = {anonymous}::ModifySubobjectHandler; typename SubobjectHandler::result_type = bool]: Assertion `O->isComplexFloat()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1. <source>:11:1: current parser token 'static_assert'
2. <source>:2:20: parsing function body 'b'
#0 0x00000000038e30c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38e30c8)
#1 0x00000000038e0dac llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38e0dac)
#2 0x0000000003829088 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007fded1642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007fded16969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007fded1642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007fded16287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007fded162871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007fded1639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000073782cc handleAssignment((anonymous namespace)::EvalInfo&, clang::Expr const*, (anonymous namespace)::LValue const&, clang::QualType, clang::APValue&) ExprConstant.cpp:0:0
#10 0x00000000073a92c2 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#11 0x00000000073a99cd EvaluateLValue(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) ExprConstant.cpp:0:0
#12 0x0000000007380b8e Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#13 0x00000000073818af EvaluateIgnoredValue((anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#14 0x00000000073a166c EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) (.part.0) ExprConstant.cpp:0:0
#15 0x00000000073a18a8 EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) (.part.0) ExprConstant.cpp:0:0
#16 0x00000000073a6d6b HandleFunctionCall(clang::SourceLocation, clang::FunctionDecl const*, (anonymous namespace)::LValue const*, clang::Expr const*, llvm::ArrayRef<clang::Expr const*>, (anonymous namespace)::CallRef, clang::Stmt const*, (anonymous namespace)::EvalInfo&, clang::APValue&, (anonymous namespace)::LValue const*) ExprConstant.cpp:0:0
#17 0x00000000073ed8b6 clang::Expr::isPotentialConstantExpr(clang::FunctionDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73ed8b6)
#18 0x000000000658203f clang::Sema::CheckConstexprFunctionDefinition(clang::FunctionDecl const*, clang::Sema::CheckConstexprKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x658203f)
#19 0x00000000064d205b clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64d205b)
#20 0x000000000624a08f clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x624a08f)
#21 0x0000000006165f51 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6165f51)
[...]
```
The problem goes away when `A` is initialized before the call to `__imag` or `__real`..
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWFtz26oW_jXkhZFHRrIuD37wJZ7TOdnTnCbTVw9CyGYHgQ6gxN6__sxC8kV22jrd7XnYHceVxeJjfYuPxQJqrdgozqdoMkeT5R1t3VabqSsoL7kxd4Uu99PnrbCY6ZKjaIbCJQoP30nYfRgic_j4t0wr6_iuMbjQWuICkQyRHKO0b8d4vdB1I_kOV1JTh2comiOyQmSFUbQEw2gUIrLA8F-6hNb3O84P9nFnT4b2x15rw6lEJJt5P6IlBvsj6notaro5byZnzQcQw11rFJ6BAdjMTxbpsnuwjjrB1tRabhwiWc8cPkfbQ8S6n1vnGgtB9ew3uiy0dCNtNois_kJk9TrJ_9z994_t_bkvHb49zcUQk0mqNv18RDOMyMpo7RBZSflaB43R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