[PATCH] D79230: [MLIR][crashfix] Fall back to malloc when alignment is 0 for align-alloc

Uday Bondhugula via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 1 01:11:45 PDT 2020


bondhugula requested changes to this revision.
bondhugula added inline comments.
This revision now requires changes to proceed.


================
Comment at: mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp:1524
     // Whether to use std lib function aligned_alloc that supports alignment.
-    bool useAlignedAlloc = allocationAlignment.hasValue();
+    bool useAlignedAlloc = allocationAlignment && *allocationAlignment != 0;
 
----------------
The alignment is actually required to be a power of two for aligned_alloc. The code above was written with the assumption that the alignment would be a power of two. Unfortunately, we don't document what a valid `alignment` on the AllocOp is. Unlike llvm's alloca where a 0 alignment is treated the same as not specifying an alignment, we could make the alloc op's verifier fail for non power of two alignments. This will fix this case as well - since zero is not a power of two. 

This fix will silently fall back to malloc for '0' alignment instead of trying to use aligned_alloc with elt size alignment (which is what happens if no alignment is set). If we wanted to handle this case, the right fix would be to check for a non-power of two alignment (in `getAllocationAlignment`), and use the default elt size based alignment while still using aligned_alloc. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79230





More information about the llvm-commits mailing list