================
@@ -184,13 +199,24 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
     return getChar();
 
   // Handle pointers and references.
-  // TODO: Implement C++'s type "similarity" and consider dis-"similar"
-  // pointers distinct.
-  if (Ty->isPointerType() || Ty->isReferenceType())
-    return createScalarTypeNode("any pointer", getChar(), Size);
+  // Pointer types never alias if their pointee type is distinct.
----------------
dybv-sc wrote:

I agree that this may be a little bit too strict, but, as far as I could 
understand, according to C11 standard `void*` and `char*` are not the same 
(correct me if I am wrong):

>From section 6.5 point 7:
> an object shall have its stored value accessed only by an lvalue expression 
> that has one of
> the following types:88)
> — a type compatible with the effective type of the object,
> — a qualified version of a type compatible with the effective type of the 
> object,
> — a type that is the signed or unsigned type corresponding to the effective 
> type of the
> object,
> — a type that is the signed or unsigned type corresponding to a qualified 
> version of the
> effective type of the object,
> — an aggregate or union type that includes one of the aforementioned types 
> among its
> members (including, recursively, a member of a subaggregate or contained 
> union), or
> — a character type.

>From all of above, the only way `void*` and `char*` alias if they are 
>compatible, but they are not:

>From section 6.2.7:
> Two types have compatible type if their types are the same. Additional rules 
> for
> determining whether two types are compatible are described in 6.7.2 for type 
> specifiers,
> in 6.7.3 for type qualifiers, and in 6.7.6 for declarators.

And from section 6.7.6.1 for pointer declarators:

> For two pointer types to be compatible, both shall be identically qualified 
> and both shall
> be pointers to compatible types.

`void` and `char` types are not compatible, because they are not the same. That 
means that `void*` and `char*` are not compatible and thus shall not alias.

So, from what I see in standard, pointer types to incompatible types should not 
alias. May be I got something wrong, so let's discuss it.

Also, now after I revisited standard, I see that getPointeeName is really not 
so accurate - it should consider type compatibility better(not only by exact 
match).

https://github.com/llvm/llvm-project/pull/75177
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to