Skip to content

Commit de50580

Browse files
Ensure proper NULL macro definition for system include files.
The C standard allows for at least 2 valid definitions of a null pointer constant and mandates that several standard headers files define the macro NULL to be a null pointer constant. Ensure that definitions of NULL are consistent across the various C header files.
1 parent 3a6ef8b commit de50580

File tree

14 files changed

+406
-0
lines changed

14 files changed

+406
-0
lines changed

clang/lib/Headers/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ set(core_files
3939
varargs.h
4040
)
4141

42+
set(aix_wrapper_files
43+
dbm.h
44+
stdio.h
45+
stdlib.h
46+
string.h
47+
time.h
48+
unistd.h
49+
wchar.h
50+
)
51+
set(aix_sys_subdir_wrapper_files
52+
sys/dir.h
53+
sys/param.h
54+
sys/types.h
55+
)
56+
set(aix_files
57+
${aix_wrapper_files}
58+
${aix_sys_subdir_wrapper_files}
59+
)
60+
4261
set(arm_common_files
4362
# Headers shared by Arm and AArch64
4463
arm_acle.h
@@ -312,6 +331,7 @@ set(utility_files
312331

313332
set(files
314333
${core_files}
334+
${aix_files}
315335
${arm_common_files}
316336
${arm_only_files}
317337
${aarch64_only_files}
@@ -529,6 +549,7 @@ set_target_properties("clang-resource-headers" PROPERTIES
529549
RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
530550
add_dependencies("clang-resource-headers"
531551
"core-resource-headers"
552+
"aix-resource-headers"
532553
"arm-common-resource-headers"
533554
"arm-resource-headers"
534555
"aarch64-resource-headers"
@@ -557,6 +578,7 @@ add_header_target("core-resource-headers" ${core_files})
557578
add_header_target("arm-common-resource-headers" "${arm_common_files};${arm_common_generated_files}")
558579

559580
# Architecture/platform specific targets
581+
add_header_target("aix-resource-headers" "${aix_files}")
560582
add_header_target("arm-resource-headers" "${arm_only_files};${arm_only_generated_files}")
561583
add_header_target("aarch64-resource-headers" "${aarch64_only_files};${aarch64_only_generated_files}")
562584
add_header_target("cuda-resource-headers" "${cuda_files};${cuda_wrapper_files};${cuda_wrapper_bits_files};${cuda_wrapper_utility_files}")
@@ -644,6 +666,18 @@ install(
644666
EXCLUDE_FROM_ALL
645667
COMPONENT core-resource-headers)
646668

669+
install(
670+
FILES ${aix_wrapper_files}
671+
DESTINATION ${header_install_dir}
672+
EXCLUDE_FROM_ALL
673+
COMPONENT aix-resource-headers)
674+
675+
install(
676+
FILES ${aix_sys_subdir_wrapper_files}
677+
DESTINATION ${header_install_dir}/sys
678+
EXCLUDE_FROM_ALL
679+
COMPONENT aix-resource-headers)
680+
647681
install(
648682
FILES ${arm_common_files} ${arm_common_generated_files}
649683
DESTINATION ${header_install_dir}
@@ -837,6 +871,9 @@ if (NOT LLVM_ENABLE_IDE)
837871
add_llvm_install_targets(install-core-resource-headers
838872
DEPENDS core-resource-headers
839873
COMPONENT core-resource-headers)
874+
add_llvm_install_targets(install-aix-resource-headers
875+
DEPENDS aix-resource-headers
876+
COMPONENT aix-resource-headers)
840877
add_llvm_install_targets(install-arm-common-resource-headers
841878
DEPENDS arm-common-resource-headers
842879
COMPONENT arm-common-resource-headers)

clang/lib/Headers/dbm.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*===---- dbm.h - BSD header for database management ----------------------===*\
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
// Although technically correct according to the standard, NULL defined as 0
10+
// may be problematic since it may result in a different size object than a
11+
// pointer (eg 64 bit mode on AIX). Therefore, re-define the macro to
12+
// ((void*)0) for consistency where needed.
13+
14+
// Limit the effects to those platforms that have this as a system header.
15+
#if defined(_AIX)
16+
17+
// Ensure that the definition of NULL (if present) is correct since it might
18+
// not be redefined if it is already defined. This ensures any use of NULL is
19+
// correct while processing the include_next.
20+
#define __need_NULL
21+
#include <stddef.h>
22+
23+
#endif
24+
25+
// Always include_next the file so that it will be included when requested.
26+
// This will trigger an error on platforms where it is not found unless
27+
// system include paths find it, which is the correct behaviour.
28+
29+
#include_next <dbm.h>
30+
31+
// Limit the effects to those platforms that have this as a system header.
32+
#if defined(_AIX) && defined(NULL)
33+
34+
// Ensure that the definition of NULL (if present) is consistent with what
35+
// is expected, regardless of where it came from.
36+
#define __need_NULL
37+
#include <stddef.h>
38+
39+
#endif

clang/lib/Headers/locale.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*===---- locale.h - Standard header for localization ---------------------===*\
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
// Although technically correct according to the standard, NULL defined as 0
10+
// may be problematic since it may result in a different size object than a
11+
// pointer (eg 64 bit mode on AIX). Therefore, re-define the macro to
12+
// ((void*)0) for consistency where needed.
13+
14+
// The standard specifies that locale.h defines NULL so ensure that the
15+
// definition is correct since it might not be redefined if it is already
16+
// defined. This ensures any use of NULL is correct while processing the
17+
// include_next.
18+
#define __need_NULL
19+
#include <stddef.h>
20+
21+
#include_next <locale.h>
22+
23+
// Ensure that the definition of NULL is as expected (likely redundant).
24+
#define __need_NULL
25+
#include <stddef.h>

clang/lib/Headers/stdio.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*===---- stdio.h - Standard header for input and output-------------------===*\
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
// Although technically correct according to the standard, NULL defined as 0
10+
// may be problematic since it may result in a different size object than a
11+
// pointer (eg 64 bit mode on AIX). Therefore, re-define the macro to
12+
// ((void*)0) for consistency where needed.
13+
14+
// The standard specifies that stdio.h defines NULL so ensure that the
15+
// definition is correct since it might not be redefined if it is already
16+
// defined. This ensures any use of NULL is correct while processing the
17+
// include_next.
18+
#define __need_NULL
19+
#include <stddef.h>
20+
21+
#include_next <stdio.h>
22+
23+
// Ensure that the definition of NULL is as expected (likely redundant).
24+
#define __need_NULL
25+
#include <stddef.h>

clang/lib/Headers/stdlib.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*===---- stdlib.h - Standard header for general utilities ----------------===*\
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
// Although technically correct according to the standard, NULL defined as 0
10+
// may be problematic since it may result in a different size object than a
11+
// pointer (eg 64 bit mode on AIX). Therefore, re-define the macro to
12+
// ((void*)0) for consistency where needed.
13+
14+
// The standard specifies that stdlib.h defines NULL so ensure that the
15+
// definition is correct since it might not be redefined if it is already
16+
// defined. This ensures any use of NULL is correct while processing the
17+
// include_next.
18+
#define __need_NULL
19+
#include <stddef.h>
20+
21+
#include_next <stdlib.h>
22+
23+
// Ensure that the definition of NULL is as expected (likely redundant).
24+
#define __need_NULL
25+
#include <stddef.h>

clang/lib/Headers/string.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*===---- string.h - Standard header for string handling ------------------===*\
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
// Although technically correct according to the standard, NULL defined as 0
10+
// may be problematic since it may result in a different size object than a
11+
// pointer (eg 64 bit mode on AIX). Therefore, re-define the macro to
12+
// ((void*)0) for consistency where needed.
13+
14+
// The standard specifies that string.h defines NULL so ensure that the
15+
// definition is correct since it might not be redefined if it is already
16+
// defined. This ensures any use of NULL is correct while processing the
17+
// include_next.
18+
#define __need_NULL
19+
#include <stddef.h>
20+
21+
#include_next <string.h>
22+
23+
// Ensure that the definition of NULL is as expected (likely redundant).
24+
#define __need_NULL
25+
#include <stddef.h>

clang/lib/Headers/sys/dir.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*===---- sys/dir.h - BSD header for directory handling -------------------===*\
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
// Although technically correct according to the standard, NULL defined as 0
10+
// may be problematic since it may result in a different size object than a
11+
// pointer (eg 64 bit mode on AIX). Therefore, re-define the macro to
12+
// ((void*)0) for consistency where needed.
13+
14+
// Limit the effects to those platforms that have this as a system header.
15+
#if defined(_AIX)
16+
17+
// Ensure that the definition of NULL (if present) is correct since it might
18+
// not be redefined if it is already defined. This ensures any use of NULL is
19+
// correct while processing the include_next.
20+
#define __need_NULL
21+
#include <stddef.h>
22+
23+
#endif
24+
25+
// Always include_next the file so that it will be included when requested.
26+
// This will trigger an error on platforms where it is not found unless
27+
// system include paths find it, which is the correct behaviour.
28+
#include_next <sys/dir.h>
29+
30+
// Limit the effects to those platforms that have this as a system header.
31+
#if defined(_AIX) && defined(NULL)
32+
33+
// Ensure that the definition of NULL (if present) is consistent with what
34+
// is expected, regardless of where it came from.
35+
#define __need_NULL
36+
#include <stddef.h>
37+
38+
#endif

clang/lib/Headers/sys/param.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*===---- sys/param.h - BSD header ----------------------------------------===*\
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
// Although technically correct according to the standard, NULL defined as 0
10+
// may be problematic since it may result in a different size object than a
11+
// pointer (eg 64 bit mode on AIX). Therefore, re-define the macro to
12+
// ((void*)0) for consistency where needed.
13+
14+
// Limit the effects to those platforms that have this as a system header.
15+
#if defined(_AIX)
16+
17+
// Ensure that the definition of NULL (if present) is correct since it might
18+
// not be redefined if it is already defined. This ensures any use of NULL is
19+
// correct while processing the include_next.
20+
#define __need_NULL
21+
#include <stddef.h>
22+
23+
#endif
24+
25+
// Always include_next the file so that it will be included when requested.
26+
// This will trigger an error on platforms where it is not found unless
27+
// system include paths find it, which is the correct behaviour.
28+
#include_next <sys/param.h>
29+
30+
// Limit the effects to those platforms that have this as a system header.
31+
#if defined(_AIX) && defined(NULL)
32+
33+
// Ensure that the definition of NULL (if present) is consistent with what
34+
// is expected, regardless of where it came from.
35+
#define __need_NULL
36+
#include <stddef.h>
37+
38+
#endif

clang/lib/Headers/sys/types.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*===---- sys/types.h - BSD header for types ------------------------------===*\
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
// Although technically correct according to the standard, NULL defined as 0
10+
// may be problematic since it may result in a different size object than a
11+
// pointer (eg 64 bit mode on AIX). Therefore, re-define the macro to
12+
// ((void*)0) for consistency where needed.
13+
14+
// Limit the effects to those platforms that have this as a system header.
15+
#if defined(_AIX)
16+
17+
// Ensure that the definition of NULL (if present) is correct since it might
18+
// not be redefined if it is already defined. This ensures any use of NULL is
19+
// correct while processing the include_next.
20+
#define __need_NULL
21+
#include <stddef.h>
22+
23+
#endif
24+
25+
// Always include_next the file so that it will be included when requested.
26+
// This will trigger an error on platforms where it is not found unless
27+
// system include paths find it, which is the correct behaviour.
28+
#include_next <sys/types.h>
29+
30+
// Limit the effects to those platforms that have this as a system header.
31+
#if defined(_AIX) && defined(NULL)
32+
33+
// Ensure that the definition of NULL (if present) is consistent with what
34+
// is expected, regardless of where it came from.
35+
#define __need_NULL
36+
#include <stddef.h>
37+
38+
#endif

clang/lib/Headers/time.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*===---- time.h - Standard header for date and time handling -------------===*\
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
// Although technically correct according to the standard, NULL defined as 0
10+
// may be problematic since it may result in a different size object than a
11+
// pointer (eg 64 bit mode on AIX). Therefore, re-define the macro to
12+
// ((void*)0) for consistency where needed.
13+
14+
// The standard specifies that time.h defines NULL so ensure that the
15+
// definition is correct since it might not be redefined if it is already
16+
// defined. This ensures any use of NULL is correct while processing the
17+
// include_next.
18+
#define __need_NULL
19+
#include <stddef.h>
20+
21+
#include_next <time.h>
22+
23+
// Ensure that the definition of NULL is as expected (likely redundant).
24+
#define __need_NULL
25+
#include <stddef.h>

0 commit comments

Comments
 (0)