[libc-commits] [PATCH] D71094: [libc] Add implementation of errno and define the other macros of errno.h.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Dec 6 00:59:40 PST 2019


sivachandra marked an inline comment as done.
sivachandra added inline comments.


================
Comment at: libc/config/linux/api.td:34
+    extern int *__errno_location();
+    #define errno *__errno_location()
+  }];
----------------
MaskRay wrote:
> sivachandra wrote:
> > MaskRay wrote:
> > > `()`
> > > 
> > > Otherwise `errno[0]` is incorrect.
> > We don't want to put it in parenthesis because we want to error on uses like `errno[0]`. `errno` is supposed to be an lvalue of int type and allowing `errno[0]` actually amounts to leaking implementation detail.
> I know errno[0] will be an error anyway.
> 
> However, this breaks grouping: `*__errno_location()[0]`
> 
> You also don't want `3 errno` to be treated as `3*__errno_location()`, do you?
To be clear here, I do not really have an opinion and I am OK to put it in parenthesis. Other libcs have chosen not to enclose in parenthesis which I thought was to prevent some form of abuse. But, I do see your point that either way it can be abused. If @stanshebs does not tell us anything interesting, I will put it in parenthesis.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71094/new/

https://reviews.llvm.org/D71094





More information about the libc-commits mailing list