https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/174764
Fix real/imag when taking a primitive parameter _and_ being discarded, and fix the case where their subexpression can't be classified. Fixes https://github.com/llvm/llvm-project/issues/174668 >From d1bb6ebd90eb015832d3d82abedad4eb6204da6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Wed, 7 Jan 2026 13:51:14 +0100 Subject: [PATCH] [clang][bytecode] Fix some imag/real corner cases Fix real/imag when taking a primitive parameter _and_ being discarded, and fix the case where their subexpression can't be classified. Fixes https://github.com/llvm/llvm-project/issues/174668 --- clang/lib/AST/ByteCode/Compiler.cpp | 10 +++++++--- clang/test/AST/ByteCode/complex.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index b4449def1c6f0..a539f31db0ca6 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -6792,13 +6792,17 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { return false; return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E); case UO_Real: // __real x - assert(T); + if (!T) + return false; return this->delegate(SubExpr); case UO_Imag: { // __imag x - assert(T); + if (!T) + return false; if (!this->discard(SubExpr)) return false; - return this->visitZeroInitializer(*T, SubExpr->getType(), SubExpr); + return DiscardResult + ? true + : this->visitZeroInitializer(*T, SubExpr->getType(), SubExpr); } case UO_Extension: return this->delegate(SubExpr); diff --git a/clang/test/AST/ByteCode/complex.cpp b/clang/test/AST/ByteCode/complex.cpp index be10b3cfa53da..182162d251ece 100644 --- a/clang/test/AST/ByteCode/complex.cpp +++ b/clang/test/AST/ByteCode/complex.cpp @@ -410,3 +410,29 @@ namespace ComplexConstexpr { static_assert(__imag test6 == 6, ""); static_assert(&__imag test6 == &__real test6 + 1, ""); } + +namespace Discard { + constexpr int test1() { + __imag(0); + __imag(0.0); + __real(0); + __real(0.0); + + return 10; + } + static_assert(test1() == 10, ""); + + constexpr int test2() { + __imag(bar()); // both-error {{use of undeclared identifier}} + return 10; + } + static_assert(test2() == 10, ""); // both-error {{not an integral constant expression}} + + constexpr int test3() { + __real(barz()); // both-error {{use of undeclared identifier}} + return 10; + } + static_assert(test3() == 10, ""); // both-error {{not an integral constant expression}} + + +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
