[clang] [TBAA] Refine pointer-tbaa for void pointers by pointer depth (PR #126047)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 10 11:47:39 PST 2025


================
@@ -80,6 +80,28 @@ llvm::MDNode *CodeGenTBAA::getChar() {
   return Char;
 }
 
+llvm::MDNode *CodeGenTBAA::getAnyPtr(unsigned PtrDepth) {
+  assert(PtrDepth >= 1 && "Pointer must have some depth");
+
+  // Populate at least PtrDepth elements in AnyPtrs. These are the type nodes
+  // for "any" pointers of increasing pointer depth, and are organized in the
+  // hierarchy: any pointer <- any p2 pointer <- any p3 pointer <- ...
----------------
rjmccall wrote:

```suggestion
  // hierarchy: any pointer > any p2 pointer > any p3 pointer > ...
  // These "any" types are used for void pointers, as well as some
  // cases where we're just being conservative. Essentially, the rule
  // we're using is that void** ought to be able to alias any type that
  // can unify with T** (where T is a variable), ignoring things like
  // qualifiers. This naturally makes each depth a subtype of the
  // previous depth, and thus transitively of all previous depths.
  //
  // Note that element idx of AnyPtrs is the node for pointer depth
  // (idx+1), since there's no node for pointer depth 0.
```

I'm suggesting `>` here rather than arrows because I think it expresses the subtype relationship more clearly, but I might be abnormally comfortable with subtyping lattices, so let me know what you think.

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


More information about the cfe-commits mailing list