[clang] modified AST for SEI redemption project (PR #111705)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 17 05:39:10 PDT 2024


================
@@ -87,13 +100,44 @@ void JSONNodeDumper::Visit(const Type *T) {
                       T->containsUnexpandedParameterPack());
   attributeOnlyIfTrue("isImported", T->isFromAST());
   InnerTypeVisitor::Visit(T);
+  // SEI
+  VisitQualTypeDetails(T->getCanonicalTypeInternal());
 }
 
 void JSONNodeDumper::Visit(QualType T) {
-  JOS.attribute("id", createPointerRepresentation(T.getAsOpaquePtr()));
-  JOS.attribute("kind", "QualType");
-  JOS.attribute("type", createQualType(T));
-  JOS.attribute("qualifiers", T.split().Quals.getAsString());
+
+  // SEI: used AddChild to prevent qualType from being part added to a list
+  // JOS.attributeArray("qualTypes", [=] {
+
+  // SEI: force qualType into its own block, otherwise multiple Visits
+  // create a bunch of siblings, which is invalid JSON
+  JOS.attributeBegin("qualType");
+  JOS.objectBegin();
+
+  // SEI: cache visited addresses and add only its refId
+  // instead of the kind, type, quals, but leave the qual type details
+  // because those can differ among IDs
+  if (cacheAddress(T.getAsOpaquePtr())) {
+    JOS.attribute("refId", createPointerRepresentation(T.getAsOpaquePtr()));
+  } else {
+    JOS.attribute("id", createPointerRepresentation(T.getAsOpaquePtr()));
+    JOS.attribute("kind", "QualType");
+    JOS.attribute("type", createQualType(T));
+    JOS.attribute("qualifiers", T.split().Quals.getAsString());
+  }
+
+  // SEI: get add'l info required for redemption analysis
+  // the qual type details differ even among cached references
+  VisitQualTypeDetails(T);
+
+  // SEI: if this is a pointer type, then recursively call ourselves
+  // until it's not
+  if (T->isPointerType())
+    Visit(T->getPointeeType());
+
+  JOS.objectEnd();
+  JOS.attributeEnd();
+  //} );
----------------
AaronBallman wrote:

```suggestion
  JOS.attributeEnd();
```

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


More information about the cfe-commits mailing list