[clang] [clang][Interp] Handle casts between complex types (PR #79269)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 31 05:53:41 PST 2024


================
@@ -234,8 +234,14 @@ class Pointer {
 
   /// Returns the type of the innermost field.
   QualType getType() const {
-    if (inPrimitiveArray() && Offset != Base)
-      return getFieldDesc()->getType()->getAsArrayTypeUnsafe()->getElementType();
+    if (inPrimitiveArray() && Offset != Base) {
+      // Unfortunately, complex types are not array types in clang, but they are
+      // for us.
+      if (const auto *AT = getFieldDesc()->getType()->getAsArrayTypeUnsafe())
+        return AT->getElementType();
+      if (const auto *CT = getFieldDesc()->getType()->castAs<ComplexType>())
----------------
AaronBallman wrote:

```suggestion
      if (const auto *CT = getFieldDesc()->getType()->getAs<ComplexType>())
```
Otherwise you wouldn't need the `if` at all because we'd assert if the type was wrong.

https://github.com/llvm/llvm-project/pull/79269


More information about the cfe-commits mailing list