[clang] [AST] Only dump desugared type when visibly different (PR #65214)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 07:01:31 PDT 2023


================
@@ -315,12 +315,16 @@ std::string JSONNodeDumper::createPointerRepresentation(const void *Ptr) {
 
 llvm::json::Object JSONNodeDumper::createQualType(QualType QT, bool Desugar) {
   SplitQualType SQT = QT.split();
-  llvm::json::Object Ret{{"qualType", QualType::getAsString(SQT, PrintPolicy)}};
+  std::string SQTS = QualType::getAsString(SQT, PrintPolicy);
+  llvm::json::Object Ret{{"qualType", SQTS}};
 
   if (Desugar && !QT.isNull()) {
     SplitQualType DSQT = QT.getSplitDesugaredType();
-    if (DSQT != SQT)
-      Ret["desugaredQualType"] = QualType::getAsString(DSQT, PrintPolicy);
+    if (DSQT != SQT) {
+      std::string DSQTS = QualType::getAsString(DSQT, PrintPolicy);
+      if (DSQTS != SQTS)
+        Ret["desugaredQualType"] = DSQTS;
+    }
----------------
AaronBallman wrote:

The aim with the original code was "if the desugared type and the given qual type are the same thing, only print one if we've been asked to print desugared", and this keeps that same aim, so I think this is reasonable.

That said, I agree with @cor3ntin that this needs a release note because there is a change in behavior that may break downstream consumers who expect the `desugaredQualType` field that's no longer going to show up for them. I don't expect it to be significantly disruptive in practice, but we should explicitly communicate that sort of change to users.

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


More information about the cfe-commits mailing list