[PATCH] D21594: [esan|cfrag] Add counters for struct array accesses

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 1 15:57:05 PDT 2016


On Fri, Jul 1, 2016 at 3:34 PM, Qin Zhao <zhaoqin at google.com> wrote:

> zhaoqin added a comment.
>
> In http://reviews.llvm.org/D21594#472524, @dberlin wrote:
>
> > You are right. What will happen is it will not look like a structure
> field
> >  access, and will use i8 or something so it can do the calculation.
> >  I'll paste a clang generated example in a bit
>
>
> I just tried a manual test example as below:
>
> %struct.RT = type { i8, [10 x [20 x i32]], i8 }
> %struct.ST = type { i32, double, %struct.RT }
>
> define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
> entry:
>
>   %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 0,
> i32 -1
>   ret i32* %arrayidx
>
> }
>
> which I tried gep on struct.ST with a negative field.
> And I get the error that invalid getelementptr indices:
>

Right, as I said, i was wrong, you can only get negative indices on pointer
and array types.

However, you have a worse situation - not every field access is going to
look like an access through a structure type ;)

Clang will happily generate code like this:
  %20 = load %struct.A*, %struct.A** %3, align 8
  %21 = bitcast %struct.A* %20 to i8*
  %22 = getelementptr inbounds i8, i8* %21, i64 %19

....


> $
> /usr/local/google/home/zhaoqin/Workspace/LLVM/builds/build_x64_rel.git/./bin/opt
> <
> /usr/local/google/home/zhaoqin/Workspace/LLVM/llvm.git/test/Instrumentation/EfficiencySanitizer/struct_field_gep.ll
> -esan -esan-cache-frag -S
> /usr/local/google/home/zhaoqin/Workspace/LLVM/builds/build_x64_rel.git/./bin/opt:
> <stdin>:28:50: error: invalid getelementptr indices
>
>   %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 0,
> i32 -1
>
>        ^
>
>
> http://reviews.llvm.org/D21594
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160701/0ecd112c/attachment.html>


More information about the llvm-commits mailing list