[cfe-dev] Compile time Array Bounds Analysis in LLVM

Friedman, Eli via cfe-dev cfe-dev at lists.llvm.org
Wed Dec 20 11:22:23 PST 2017


On 12/19/2017 8:51 PM, Mahesh Attarde via cfe-dev wrote:
> Hi
>  I am working on analyzing arrays for dimensions and inferring 
> iteration space.
> While going through this i found example
>
> intfunct(){
> inta[6][6][6];
> returna[8][0][0];
> }
>
> https://godbolt.org/g/S9pKqq
>
> Compiler did not warn about extended index in first dimension. 
> Considering arrays are decayed
> into pointer,  Will issuing this as error be false positive?

No; a[8] is equivalent to *(a+8), and "a+8" is undefined behavior 
because it points outside the array.  -fsanitize=undefined will catch 
this at runtime.

> By looking at this it looks like easy problem to solve at AST level. 
> What is challenge in this analysis?

Probably just an oversight in the checking code.  Briefly looking at it, 
it looks like there's a missing call to Sema::CheckArrayAccess?

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171220/1f2b8b45/attachment.html>


More information about the cfe-dev mailing list