On Thu, Nov 16, 2017 at 06:14:35PM -0700, Jeff Law wrote: > > However, this routine currently miss a very obvious case as the following: > > > > char s[100] = {'a','b','c','d’}; > > > > __builtin_strcmp(s, "abc") != 0 > > > > So, I have to change this routine to include such common case. > > > > do you think using this routine is good? or do you have other > > suggestions (since I am still not very familiar with the internals of > > GCC, might not find the best available one now…) > The range information attached to an SSA_NAME is global data. ie, it > must hold at all locations where the object in question might be > referenced. This implies that it will sometimes (often?) be less > precise than you might like. > > I am currently working towards an embeddable context sensitive range > analyzer that in theory could be used within tree-ssa-strlen pass to > give more precise range information. I'm hoping to wrap that work up in > the next day or so so that folks can use it in gcc-8.
Well, one thing is a range of integral SSA_NAME at a certain point, the other is the length of the C string pointed by a certain pointer (that is something the strlen pass tracks), and another case is the content of that string, which you'd presumably need to optimize the strcmp at compile time. I think current strlen pass ought to find out that strlen (s) is 4 at that point, if it doesn't, please file a PR with a testcase. Jakub