[PATCH] Implement variable-sized alloca instrumentation.

Kostya Serebryany kcc at google.com
Tue Nov 18 13:06:31 PST 2014


================
Comment at: lib/Transforms/Instrumentation/AddressSanitizer.cpp:656
@@ +655,3 @@
+                                                       Int32PtrTy);
+    // if (PartialSize) {
+    //   PartialRzMagic = calculatePartialRzMagic(PartialSize);
----------------
m.ostepenko wrote:
> kcc wrote:
> > instead of creating a new BB for partial RZ, I would do this: 
> > make sure that PartialSize is never zero, i.e. instead of being in 0..31 it is in 1..32
> > This is better as we will not need to keep both pointers (PartialRz and RightRz) alive throughout the procedure. 
> Yes, this is a good idea to avoid new BB creation. But we still need both PartialRz and RightRz, because in case of PartialSize == 32 PartialRz points the same address as RightRz, otherwise RightRz == PartialSize + 32, isn't it?
> 
> Or maybe I've misunderstood something?
>>But we still need both PartialRz and RightRz, because in case of PartialSize == 32 PartialRz points the same address as RightRz, otherwise RightRz == PartialSize + 32, isn't it?
There are two ways to implement this: 

1. in case of PartialSize == 32 PartialRz points the same address as RightRz, otherwise RightRz == PartialSize + 32
In this case, we need to poison both PartialRz and RightRz and we need to keep this value in the register for the entire function. 

2. PartialRz is always strictly before RightRz. 
In this case we always unpoison RightRz and RightRz-32 and so we don't need to keep PartialRz around. 

It's hard to tell which is better w/o measuring on a good benchmark, also there is a memory-vs-cpu tradeoff (larger redzones vs larger register pressure). 
But the second way sounds slightly better to me.

http://reviews.llvm.org/D6055






More information about the llvm-commits mailing list