Skip to content

Commit 95f1de3

Browse files
committed
Headers: Add support for ISO9899:2011 rsize_t.
llvm-svn: 179427
1 parent b0e2848 commit 95f1de3

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

clang/lib/Headers/stddef.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
4242
typedef __SIZE_TYPE__ size_t;
4343
#endif
4444

45+
/* ISO9899:2011 7.20 (C11 Annex K): Define risze_t if __STDC_WANT_LIB_EXT1__ is
46+
* enabled. */
47+
#if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 && \
48+
!defined(_RSIZE_T)) || __has_feature(modules)
49+
/* Always define rsize_t when modules are available. */
50+
#if !__has_feature(modules)
51+
#define _RSIZE_T
52+
#endif
53+
typedef __SIZE_TYPE__ rsize_t;
54+
#endif
55+
4556
#ifndef __cplusplus
4657
/* Always define wchar_t when modules are available. */
4758
#if !defined(_WCHAR_T) || __has_feature(modules)

clang/lib/Headers/stdint.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,12 @@ typedef __UINTMAX_TYPE__ uintmax_t;
667667
#define PTRDIFF_MAX __INTN_MAX(__PTRDIFF_WIDTH__)
668668
#define SIZE_MAX __UINTN_MAX(__SIZE_WIDTH__)
669669

670+
/* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__
671+
* is enabled. */
672+
#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
673+
#define RSIZE_MAX (SIZE_MAX >> 1)
674+
#endif
675+
670676
/* C99 7.18.2.5 Limits of greatest-width integer types. */
671677
#define INTMAX_MIN __INTN_MIN(__INTMAX_WIDTH__)
672678
#define INTMAX_MAX __INTN_MAX(__INTMAX_WIDTH__)

clang/test/Headers/c11.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ _Static_assert(__alignas_is_defined, "");
1717
_Static_assert(__alignof_is_defined, "");
1818
alignas(alignof(int)) char c[4];
1919
_Static_assert(__alignof(c) == 4, "");
20+
21+
#define __STDC_WANT_LIB_EXT1__ 1
22+
#include <stddef.h>
23+
#include <stdint.h>
24+
rsize_t x = RSIZE_MAX;

0 commit comments

Comments
 (0)