This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add limits.h
ClosedPublic

Authored by alfredfo on Aug 2 2023, 7:40 PM.

Details

Summary

This header contains implementation specific constants.

The compiler already provides its own limits.h with numerical limits
conforming to freestanding ISO C. But it is missing extensions like
POSIX, and does for example not include <linux/limits.h> which is
expected on a Linux system, therefore, an LLVM libc implementation of
limits.h is needed for hosted (STDC_HOSTED) environments.

Diff Detail

Event Timeline

alfredfo created this revision.Aug 2 2023, 7:40 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 2 2023, 7:40 PM
alfredfo requested review of this revision.Aug 2 2023, 7:40 PM

The limits.h header is provided by the compiler, so us providing it will just cause problems

The limits.h header is provided by the compiler, so us providing it will just cause problems

Hmm, are you sure? I thought Clang headers and libc headers were both supposed to be used. Also, Clang headers only have standard C things, no POSIX/GNU extensions... etc.
I know SSIZE_MAX isn't there, also PATH_MAX is not available so it does not include <linux/limits.h> like musl and glibc.

Yeah prob should be provided by both :)

/* System headers include a number of constants from POSIX in <limits.h>.
   Include it if we're hosted. */
#if __STDC_HOSTED__ && __has_include_next(<limits.h>)
#include_next <limits.h>
#endif

https://github.com/llvm/llvm-project/blob/eac78fdf68f58e113b2cf18a14baccb8f5ebcf50/clang/lib/Headers/limits.h#L18

michaelrj accepted this revision.Aug 4 2023, 10:45 AM

Ah! In that case, this looks good.

This revision is now accepted and ready to land.Aug 4 2023, 10:45 AM
michaelrj added inline comments.Aug 4 2023, 1:56 PM
libc/include/llvm-libc-macros/limits-macros.h
10

as an added thing, can we make it so that we only define these if they aren't already defined?

sivachandra added inline comments.
libc/include/llvm-libc-macros/limits-macros.h
15

Considering LONG_MAX is already defined in the freestanding limits.h, may be all you need is:

#define SSIZE_MAX __LONG_MAX__
alfredfo updated this revision to Diff 549193.Aug 10 2023, 4:08 PM

remove PATH_MAX definition

alfredfo added inline comments.Aug 10 2023, 4:15 PM
libc/include/llvm-libc-macros/limits-macros.h
10

Sure, will fix tomorrow

15

Yes, done

alfredfo updated this revision to Diff 549195.Aug 10 2023, 4:17 PM

only define SSIZE_MAX if not already defined

alfredfo updated this revision to Diff 549762.Aug 13 2023, 5:08 PM

update msg

alfredfo updated this revision to Diff 549763.Aug 13 2023, 5:29 PM

arc broken moment

alfredfo updated this revision to Diff 549765.Aug 13 2023, 5:35 PM
alfredfo edited the summary of this revision. (Show Details)

update message

This revision was landed with ongoing or failed builds.Aug 13 2023, 5:37 PM
Closed by commit rG0fb3066873fd: [libc] Add limits.h (authored by alfredfo, committed by thesamesam). · Explain Why
This revision was automatically updated to reflect the committed changes.