[PATCH] D150661: [clang][Interp] Allow evaluating standalone composite expressions
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 16 05:52:17 PDT 2023
tbaeder updated this revision to Diff 522563.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150661/new/
https://reviews.llvm.org/D150661
Files:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/complex.cpp
Index: clang/test/AST/Interp/complex.cpp
===================================================================
--- clang/test/AST/Interp/complex.cpp
+++ clang/test/AST/Interp/complex.cpp
@@ -38,6 +38,10 @@
static_assert(__imag(I2) == 0, "");
+/// Standalone complex expressions.
+static_assert(__real((_Complex float){1.0, 3.0}) == 1.0, "");
+
+
#if 0
/// FIXME: This should work in the new interpreter.
constexpr _Complex double D2 = {12};
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1887,9 +1887,16 @@
// Expressions with a composite return type.
// For us, that means everything we don't
// have a PrimType for.
- if (!visit(E))
- return false;
- return this->emitRetValue(E);
+ if (std::optional<unsigned> LocalOffset = this->allocateLocal(E)) {
+ if (!this->visitLocalInitializer(E, *LocalOffset))
+ return false;
+
+ if (!this->emitGetPtrLocal(*LocalOffset, E))
+ return false;
+ return this->emitRetValue(E);
+ }
+
+ return false;
}
/// Toplevel visitDecl().
@@ -2269,7 +2276,14 @@
return false;
if (!this->emitConstUint8(0, E))
return false;
- return this->emitArrayElemPtrPopUint8(E);
+ if (!this->emitArrayElemPtrPopUint8(E))
+ return false;
+
+ // Since our _Complex implementation does not map to a primitive type,
+ // we sometimes have to do the lvalue-to-rvalue conversion here manually.
+ if (!SubExpr->isLValue())
+ return this->emitLoadPop(classifyPrim(E->getType()), E);
+ return true;
}
case UO_Imag: { // __imag x
assert(!T);
@@ -2277,7 +2291,14 @@
return false;
if (!this->emitConstUint8(1, E))
return false;
- return this->emitArrayElemPtrPopUint8(E);
+ if (!this->emitArrayElemPtrPopUint8(E))
+ return false;
+
+ // Since our _Complex implementation does not map to a primitive type,
+ // we sometimes have to do the lvalue-to-rvalue conversion here manually.
+ if (!SubExpr->isLValue())
+ return this->emitLoadPop(classifyPrim(E->getType()), E);
+ return true;
}
case UO_Extension:
if (DiscardResult)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150661.522563.patch
Type: text/x-patch
Size: 2254 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230516/a82a29d3/attachment-0001.bin>
More information about the cfe-commits
mailing list