[clang] [clang] Add value_type attr, use it to add noalias when pass-by-value. (PR #95004)
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 17 01:33:46 PDT 2025
================
@@ -9242,3 +9242,15 @@ Declares that a function potentially allocates heap memory, and prevents any pot
of ``nonallocating`` by the compiler.
}];
}
+
+def ValueTypeDocs : Documentation {
+ let Category = DocCatDecl;
+ let Content = [{
+The ``value_type`` attribute can be used to mark user-defined types as 'value
+types'. When objects of value types are passed value to functions, the objects
+are always considered to be formally copied into a new object. This means the
+argument itself must be the only value referencing the passed object. This
----------------
rjmccall wrote:
If the argument satisfies the formal conditions for being passed in registers, the implementation is allowed to introduce a copy despite NRVO, which might be enough to make any escaped/self pointers formally invalid even if we don't actually copy. But yeah, NRVO might mean we're out of luck for an arbitrary type to which that doesn't apply.
We could probably talk to the C++ committee about this if we can show that we could do useful optimizations except for some contrived and dangerous code pattern like escaping the address of a copyable class value prior to returning it via NRVO.
https://github.com/llvm/llvm-project/pull/95004
More information about the cfe-commits
mailing list