[clang] 28b8207 - [clang][Interp] Support ImplicitValueInitExpr for complex types
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 6 23:35:17 PST 2024
Author: Timm Bäder
Date: 2024-02-07T08:26:47+01:00
New Revision: 28b82075ff3e58ba9c6959a585d3d0fc5d0325e5
URL: https://github.com/llvm/llvm-project/commit/28b82075ff3e58ba9c6959a585d3d0fc5d0325e5
DIFF: https://github.com/llvm/llvm-project/commit/28b82075ff3e58ba9c6959a585d3d0fc5d0325e5.diff
LOG: [clang][Interp] Support ImplicitValueInitExpr for complex types
Initialize both elements to 0, once again.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/complex.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 49f9878d42480..38b2d6fad043c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -820,6 +820,19 @@ bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueIni
return true;
}
+ if (QT->isAnyComplexType()) {
+ assert(Initializing);
+ QualType ElemQT = QT->getAs<ComplexType>()->getElementType();
+ PrimType ElemT = classifyPrim(ElemQT);
+ for (unsigned I = 0; I < 2; ++I) {
+ if (!this->visitZeroInitializer(ElemT, ElemQT, E))
+ return false;
+ if (!this->emitInitElem(ElemT, I, E))
+ return false;
+ }
+ return true;
+ }
+
return false;
}
diff --git a/clang/test/AST/Interp/complex.cpp b/clang/test/AST/Interp/complex.cpp
index 20c00b8e1ba3f..7d625ab1f378e 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -102,6 +102,16 @@ static_assert(__imag(I3) == 0, "");
// constexpr _Complex _BitInt(8) A = 0;// = {4};
+constexpr _Complex double Doubles[4] = {{1.0, 2.0}};
+static_assert(__real(Doubles[0]) == 1.0, "");
+static_assert(__imag(Doubles[0]) == 2.0, "");
+static_assert(__real(Doubles[1]) == 0.0, "");
+static_assert(__imag(Doubles[1]) == 0.0, "");
+static_assert(__real(Doubles[2]) == 0.0, "");
+static_assert(__imag(Doubles[2]) == 0.0, "");
+static_assert(__real(Doubles[3]) == 0.0, "");
+static_assert(__imag(Doubles[3]) == 0.0, "");
+
void func(void) {
__complex__ int arr;
_Complex int result;
More information about the cfe-commits
mailing list