[PATCH] D134286: [C2x] implement typeof and typeof_unqual

Matheus Izvekov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 20 10:36:08 PDT 2022


mizvekov added inline comments.


================
Comment at: clang/include/clang/AST/Type.h:4537
   Expr *TOExpr;
+  bool IsUnqual;
 
----------------
You can use the Type Bitfields in order to avoid bumping the size of the node.



================
Comment at: clang/lib/AST/ASTContext.cpp:12910-12916
+    // FIXME:: is this assumption correct or do we need to do work here to find
+    // the common type sugar regarding the stripped qualifiers if only one side
+    // is unqual?
+    assert(cast<TypeOfType>(X)->isUnqual() == cast<TypeOfType>(Y)->isUnqual() &&
+           "typeof vs typeof_unqual mismatch?");
+    return Ctx.getTypeOfType(Ctx.getQualifiedType(Underlying),
+                             cast<TypeOfType>(X)->isUnqual());
----------------
erichkeane wrote:
> I'm unfamiliar with this function, but I would expect you MIGHT need to?  If only because they are the same AST node.  Should 'unqual' version be its own node?  I'm on the fence, as it is a LOT of code to do so, but also ends up being simpler in many places.
A qualified and an unqualified typeof could have the same underlying type, so this assert can trip.

I think what makes most sense is to unify them to a qualified typeof in case they differ, as that holds the underlying type unchanged:
```
    return Ctx.getTypeOfType(Ctx.getQualifiedType(Underlying),
                             cast<TypeOfType>(X)->isUnqual() && cast<TypeOfType>(Y)->isUnqual());
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134286/new/

https://reviews.llvm.org/D134286



More information about the cfe-commits mailing list