[clang] [Clang][RFC] Resugar attributed type alias (PR #143143)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 6 07:32:22 PDT 2025


================
@@ -6998,6 +7007,31 @@ namespace {
         else
           return C.getRValueReferenceType(New);
       }
+      case Elaborated: {
+        auto *ET = cast<ElaboratedType>(Old);
+        return C.getElaboratedType(ET->getKeyword(), ET->getQualifier(),
+                                   wrap(C, ET->getNamedType(), I));
+      }
+      case TypeAlias: {
+        auto *ET = cast<TypedefType>(Old);
+        QualType Underlying = wrap(C, ET->desugar(), I);
+        TypedefNameDecl *Typedef;
+        if (auto *TD = dyn_cast<TypedefDecl>(ET->getDecl())) {
+          Typedef = TypedefDecl::Create(C, TD->getDeclContext(),
+                                        TD->getBeginLoc(), TD->getLocation(),
+                                        TD->getIdentifier(), nullptr);
+          Typedef->setModedTypeSourceInfo(TD->getTypeSourceInfo(), Underlying);
+        } else {
+          auto *Alias = cast<TypeAliasDecl>(ET->getDecl());
+          Typedef = TypedefDecl::Create(
+              C, Alias->getDeclContext(), Alias->getBeginLoc(),
+              Alias->getLocation(), Alias->getIdentifier(), nullptr);
+          Typedef->setModedTypeSourceInfo(Alias->getTypeSourceInfo(),
+                                          Underlying);
+        }
+        Typedef->setPreviousDecl(ET->getDecl());
+        return C.getTypedefType(Typedef, Underlying);
----------------
zyn0217 wrote:

The context of this resugar is to find the FunctionType and add an attribute (by creating a new function type) on it.

The resugarer tries to add back anything it gets rid of, like the TypedefType in this case.

Or do you know if there's other way around to avoid copying the function type?

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


More information about the cfe-commits mailing list