[PATCH] D46441: [clang][CodeGenCXX] Noalias attr for copy/move constructor arguments

Anton Bikineev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 4 10:42:26 PDT 2018


AntonBikineev created this revision.
AntonBikineev added reviewers: rsmith, aaron.ballman.
AntonBikineev added a project: clang.

The patch addresses this bug <https://bugs.llvm.org/show_bug.cgi?id=37329>.

According to the Standard (taken from the bug description):
[class.ctor] paragraph 14:

"During the construction of an object, if the value of the object or any of its subobjects is accessed through a glvalue that is not obtained, directly or indirectly, from the constructor’s this pointer, the value of the object or subobject thus obtained is unspecified."


Repository:
  rC Clang

https://reviews.llvm.org/D46441

Files:
  lib/CodeGen/CGCXX.cpp


Index: lib/CodeGen/CGCXX.cpp
===================================================================
--- lib/CodeGen/CGCXX.cpp
+++ lib/CodeGen/CGCXX.cpp
@@ -224,6 +224,11 @@
   } else {
     const auto *CD = cast<CXXConstructorDecl>(MD);
     GD = GlobalDecl(CD, toCXXCtorType(Type));
+
+    // As long as `this` argument always comes first
+    // we hardcode the position of the `src` argument
+    if (CD->isCopyOrMoveConstructor())
+      Fn->addParamAttr(1, llvm::Attribute::NoAlias);
   }
 
   setFunctionLinkage(GD, Fn);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46441.145224.patch
Type: text/x-patch
Size: 524 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180504/85f06a16/attachment.bin>


More information about the cfe-commits mailing list