This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Disallow inlining if static vars in that function contain addresses of that function's labels (PR tree-optimization/29484)


Jakub Jelinek wrote:
> On Wed, Dec 26, 2007 at 10:14:38AM -0800, Mark Mitchell wrote:
>> Even without a static variable, an addressed label should prevent
>> inlining, IMO.  For example, it's reasonable for users to compare the
>> addresses of two labels and to expect that the address of the same label
>> is always the same.
>>
>> I see that in c-common.c:finish_label_address_expr, we have:
>>
>>       /* The current function in not necessarily uninlinable.
>>
>>          Computed gotos are incompatible with inlining, but the value
>>
>>          here could be used only in a diagnostic, for example.  */
>>
>> I disagree with that comment.  We have no idea what the user is doing
>> with the pointer; hence, we must conservatively assume the worst.
> 
> That will IMHO pessimize a lot of projects, starting with glibc, Linux
> kernel, etc. and might even break projects which rely on inlining.

That's a compelling argument, if existing usage has been that nobody
cares about address quality.  If so, then the manual ought to explicitly
say that you cannot rely on the addresses of labels being the same, and
should not do comparison between them.  So, if you want to proceed with
your original patch, then I think it ought to come with a patch to the
manual as well.

I'd certainly have expected that code like this:

  void* f(void *p) {
    l:
    if (p != &&l)
      return &&l;
    return NULL;
  }

  void g() {
    void *p = f(NULL);
    assert (f(p) == NULL);
  }

would succeed.  Function pointers are guaranteed unique, and labels seem
quite similar at first blush, though I understand that they can only be
used from within the function itself.

Joseph, as a C maintainer, what do you think about this?

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]