On 12/03/2014 07:01 AM, Jakub Jelinek wrote:
One more question. My current version of the patch adds one ubsan vptr instrumentation in each of the following functions:struct S { int s; virtual void foo (); S(); virtual ~S(); }; struct T : S {}; struct U { int u; S s[4]; }; struct V { U v; virtual void bar (); V(); virtual ~V(); }; V v; int f1 (V *p) { return p->v.u; } int f2 (V *p) { return p->v.s[2].s; } int f3 () { return v.v.u; } int f4 () { return v.v.s[2].s; } (in f1 and f3 verifies it for _ZTI1V, in f2 and f4 verifies it for _ZTI1S). Should I change it so that we get 2 instrumentations in f2 and f4 and one in f1/f3 (i.e. in f2/f4 check two vptrs, one _ZTI1S and one _ZTI1V), or do we care just about the outermost one?
I think so; it definitely is possible to clobber the vptr in a normal decl and the check would catch that. Though perhaps we want a separate mode that optimizes away the checks when we know the declared type of the object.
Note, latest clang has 1 instrumentation in f1 and f4, two in f2 and none in f3.
That sounds like they mean to avoid checking when there's a declared type but array-to-pointer decay is causing them to check the array members.
Jason
