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] errno can't alias locals (PR 92412)


On 11/12/19 1:04 AM, Richard Biener wrote:
On Mon, Nov 11, 2019 at 11:38 PM Martin Sebor <msebor@gmail.com> wrote:

The conditional in default_ref_may_alias_errno has the function
return true even for local variables, implying that locals must
be assumed not to have been changed across calls to errno-setting
functions like malloc.  This leads to both worse code and also
false negatives in the strlen pass' detection of buffer overflow
across such calls.

The attached patch constrains the conditional to only consider
external declarations.

Tested on x86_64-linux.

OK.

This means a tentative definition for 'errno' is non-conforming?
(besides not working well in practice, of course)

Errno is a reserved name (just like all external identifiers)
so only an implementation can declare it at file scope.

But if you are asking if the patch changes the assumption GCC
makes about errno aliasing tentative definitions, I don't think
it does.  AFAICT, GCC has been making the assumption since 4.5.
Here's a slightly different test case than the one in pr92412
that makes it clearer:

  int errno;

  void* f (void)
  {
    int e = errno;
    void *p = __builtin_malloc (1);
    if (e != errno)   // eliminated
      __builtin_abort ();
    return p;
  }

But to be clear, my goal with the change is to let GCC (strlen
specifically) assume that errno doesn't alias local variables.

Martin


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