[PATCH] D100879: [Clang] Propagate guaranteed alignment for malloc and others

Dávid Bolvanský via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 20 11:55:15 PDT 2021


xbolva00 updated this revision to Diff 338950.
xbolva00 added a reviewer: jdoerfert.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100879/new/

https://reviews.llvm.org/D100879

Files:
  clang/lib/CodeGen/CGCall.cpp


Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2048,6 +2048,22 @@
       // allows it to work on indirect virtual function calls.
       if (AttrOnCallSite && TargetDecl->hasAttr<NoMergeAttr>())
         FuncAttrs.addAttribute(llvm::Attribute::NoMerge);
+
+      // Add known guaranteed alignment for allocation functions
+      if (unsigned BuiltinID = Fn->getBuiltinID()) {
+        switch (BuiltinID) {
+        case Builtin::BImalloc:
+        case Builtin::BIcalloc:
+        case Builtin::BIrealloc:
+        case Builtin::BIstrdup:
+        case Builtin::BIstrndup:
+          RetAttrs.addAlignmentAttr(Context.getTargetInfo().getNewAlign() /
+                                    Context.getTargetInfo().getCharWidth());
+          break;
+        default:
+          break;
+        }
+      }
     }
 
     // 'const', 'pure' and 'noalias' attributed functions are also nounwind.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100879.338950.patch
Type: text/x-patch
Size: 1016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210420/f6acb3b6/attachment.bin>


More information about the cfe-commits mailing list