[PATCH] Warning for Out of bound access of Array of Structures/Unions not reported

Eli Friedman eli.friedman at gmail.com
Thu Sep 5 12:58:49 PDT 2013


memExpr->getBase() will never return null.

Nit: there are a bunch of extra newlines in your testcase.

-Eli


On Thu, Sep 5, 2013 at 7:27 AM, Karthik Bhat <blitz.opensource at gmail.com>wrote:

> Hi Jordan,Ted,Richard
> Any inputs on this patch?
> http://llvm-reviews.chandlerc.com/D1580
>
> Thanks
> Karthik Bhat
>
>
> On Tue, Sep 3, 2013 at 7:40 PM, Karthik Bhat <blitz.opensource at gmail.com>wrote:
>
>> Hi jordan_rose,
>>
>> Hi All,
>> Out of bound access of array of structures/unions are not reported. Added
>> a patch to handle the same.
>> Please let me know if it is good to commit.
>> Thanks
>> Karthik Bhat
>>
>> http://llvm-reviews.chandlerc.com/D1580
>>
>> Files:
>>   lib/Sema/SemaChecking.cpp
>>   test/SemaCXX/array-bounds.cpp
>>
>> Index: lib/Sema/SemaChecking.cpp
>> ===================================================================
>> --- lib/Sema/SemaChecking.cpp
>> +++ lib/Sema/SemaChecking.cpp
>> @@ -6373,6 +6373,12 @@
>>            CheckArrayAccess(rhs);
>>          return;
>>        }
>> +      case Stmt::MemberExprClass: {
>> +        const MemberExpr *memExpr = cast<MemberExpr>(expr);
>> +        if (const Expr *base = memExpr->getBase())
>> +          CheckArrayAccess(base);
>> +        return;
>> +      }
>>        default:
>>          return;
>>      }
>> Index: test/SemaCXX/array-bounds.cpp
>> ===================================================================
>> --- test/SemaCXX/array-bounds.cpp
>> +++ test/SemaCXX/array-bounds.cpp
>> @@ -253,3 +253,20 @@
>>         int a[128]; // expected-note {{array 'a' declared here}}
>>         a[(unsigned char)'\xA1'] = 1; // expected-warning {{array index
>> 161 is past the end of the array}}
>>  }
>> +
>> +typedef struct {
>> +    int a;
>> +} structTest;
>> +
>> +void
>> +test_arraystructOverflow() {
>> +  structTest data[2];  // expected-note 2 {{array 'data' declared here}}
>> +  if (!data[1].a && !data[2].a) {  // expected-warning {{array index 2
>> is past the end of the array (which contains 2 elements)}}
>> +    data[2].a = 1;  // expected-warning {{array index 2 is past the end
>> of the array (which contains 2 elements)}}
>> +  }
>> +  return;
>> +}
>> +
>> +
>> +
>> +
>>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130905/2efa52d1/attachment.html>


More information about the cfe-commits mailing list