Skip to content

Commit 75bbf4d

Browse files
author
Job Henandez Lara
authored
[libc] Add proxy headers for fenv types. (#88467)
Fixes #88187
1 parent 58c5f50 commit 75bbf4d

26 files changed

+108
-24
lines changed

libc/hdr/types/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,21 @@ add_proxy_header_library(
2121
FULL_BUILD_DEPENDS
2222
libc.include.llvm-libc-types.struct_timespec
2323
)
24+
25+
add_proxy_header_library(
26+
fenv_t
27+
HDRS
28+
fenv_t.h
29+
FULL_BUILD_DEPENDS
30+
libc.include.llvm-libc-types.fenv_t
31+
libc.incude.fenv
32+
)
33+
34+
add_proxy_header_library(
35+
fexcept_t
36+
HDRS
37+
fexcept_t.h
38+
FULL_BUILD_DEPENDS
39+
libc.include.llvm-libc-types.fexcept_t
40+
libc.incude.fenv
41+
)

libc/hdr/types/fenv_t.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from fenv_t.h --------------------------------===//
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+
#ifndef LLVM_LIBC_HDR_FENV_T_H
10+
#define LLVM_LIBC_HDR_FENV_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/fenv_t.h"
15+
16+
#else // Overlay mode
17+
18+
#include <fenv.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_FENV_T_H

libc/hdr/types/fexcept_t.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from fexcept_t.h -----------------------------===//
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+
#ifndef LLVM_LIBC_HDR_FEXCEPT_T_H
10+
#define LLVM_LIBC_HDR_FEXCEPT_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/fexcept_t.h"
15+
16+
#else // Overlay mode
17+
18+
#include <fenv.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_FENV_T_H

libc/src/__support/FPUtil/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ add_header_library(
33
HDRS
44
FEnvImpl.h
55
DEPENDS
6-
libc.include.fenv
6+
libc.hdr.types.fenv_t
77
libc.hdr.fenv_macros
88
libc.hdr.math_macros
99
libc.src.__support.macros.attributes

libc/src/__support/FPUtil/aarch64/FEnvImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#endif
1818

1919
#include <arm_acle.h>
20-
#include <fenv.h>
2120
#include <stdint.h>
2221

2322
#include "hdr/fenv_macros.h"
23+
#include "hdr/types/fenv_t.h"
2424
#include "src/__support/FPUtil/FPBits.h"
2525

2626
namespace LIBC_NAMESPACE {

libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#endif
1818

1919
#include <arm_acle.h>
20-
#include <fenv.h>
2120
#include <stdint.h>
2221

2322
#include "hdr/fenv_macros.h"
23+
#include "hdr/types/fenv_t.h"
2424
#include "src/__support/FPUtil/FPBits.h"
2525

2626
namespace LIBC_NAMESPACE {

libc/src/__support/FPUtil/arm/FEnvImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_ARM_FENVIMPL_H
1111

1212
#include "hdr/fenv_macros.h"
13+
#include "hdr/types/fenv_t.h"
1314
#include "src/__support/FPUtil/FPBits.h"
1415
#include "src/__support/macros/attributes.h" // For LIBC_INLINE
15-
#include <fenv.h>
1616
#include <stdint.h>
1717

1818
namespace LIBC_NAMESPACE {

libc/src/__support/FPUtil/riscv/FEnvImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FENVIMPL_H
1111

1212
#include "hdr/fenv_macros.h"
13+
#include "hdr/types/fenv_t.h"
1314
#include "src/__support/FPUtil/FPBits.h"
1415
#include "src/__support/macros/attributes.h" // For LIBC_INLINE_ASM
1516
#include "src/__support/macros/config.h" // For LIBC_INLINE

libc/src/__support/FPUtil/x86_64/FEnvImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#error "Invalid include"
1717
#endif
1818

19-
#include <fenv.h>
2019
#include <stdint.h>
2120

21+
#include "hdr/types/fenv_t.h"
2222
#include "src/__support/macros/sanitizer.h"
2323

2424
namespace LIBC_NAMESPACE {

libc/src/fenv/CMakeLists.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ add_entrypoint_object(
55
HDRS
66
fegetround.h
77
DEPENDS
8-
libc.include.fenv
98
libc.src.__support.FPUtil.fenv_impl
109
COMPILE_OPTIONS
1110
-O2
@@ -71,6 +70,7 @@ add_entrypoint_object(
7170
fegetenv.h
7271
DEPENDS
7372
libc.hdr.fenv_macros
73+
libc.hdr.types.fenv_t
7474
libc.src.__support.FPUtil.fenv_impl
7575
COMPILE_OPTIONS
7676
-O2
@@ -84,6 +84,7 @@ add_entrypoint_object(
8484
fesetenv.h
8585
DEPENDS
8686
libc.hdr.fenv_macros
87+
libc.hdr.types.fenv_t
8788
libc.src.__support.FPUtil.fenv_impl
8889
COMPILE_OPTIONS
8990
-O2
@@ -97,6 +98,7 @@ add_entrypoint_object(
9798
fegetexceptflag.h
9899
DEPENDS
99100
libc.hdr.fenv_macros
101+
libc.hdr.types.fexcept_t
100102
libc.src.__support.FPUtil.fenv_impl
101103
COMPILE_OPTIONS
102104
-O2
@@ -123,6 +125,7 @@ add_entrypoint_object(
123125
fesetexceptflag.h
124126
DEPENDS
125127
libc.hdr.fenv_macros
128+
libc.hdr.types.fexcept_t
126129
libc.src.__support.FPUtil.fenv_impl
127130
COMPILE_OPTIONS
128131
-O2
@@ -136,6 +139,7 @@ add_entrypoint_object(
136139
feholdexcept.h
137140
DEPENDS
138141
libc.hdr.fenv_macros
142+
libc.hdr.types.fenv_t
139143
libc.src.__support.FPUtil.fenv_impl
140144
COMPILE_OPTIONS
141145
-O2
@@ -149,6 +153,7 @@ add_entrypoint_object(
149153
feupdateenv.h
150154
DEPENDS
151155
libc.hdr.fenv_macros
156+
libc.hdr.types.fenv_t
152157
libc.src.__support.FPUtil.fenv_impl
153158
COMPILE_OPTIONS
154159
-O2

libc/src/fenv/fegetenv.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_FENV_FEGETENV_H
1010
#define LLVM_LIBC_SRC_FENV_FEGETENV_H
1111

12-
#include <fenv.h>
12+
#include "hdr/types/fenv_t.h"
1313

1414
namespace LIBC_NAMESPACE {
1515

libc/src/fenv/fegetexceptflag.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/fenv/fegetexceptflag.h"
10+
#include "hdr/types/fexcept_t.h"
1011
#include "src/__support/FPUtil/FEnvImpl.h"
1112
#include "src/__support/common.h"
1213

13-
#include <fenv.h>
14-
1514
namespace LIBC_NAMESPACE {
1615

1716
LLVM_LIBC_FUNCTION(int, fegetexceptflag, (fexcept_t * flagp, int excepts)) {

libc/src/fenv/feholdexcept.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/fenv/feholdexcept.h"
10+
#include "hdr/types/fenv_t.h"
1011
#include "src/__support/FPUtil/FEnvImpl.h"
1112
#include "src/__support/common.h"
12-
#include <fenv.h>
1313

1414
namespace LIBC_NAMESPACE {
1515

libc/src/fenv/feholdexcept.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_FENV_FEHOLDEXCEPT_H
1010
#define LLVM_LIBC_SRC_FENV_FEHOLDEXCEPT_H
1111

12-
#include <fenv.h>
12+
#include "hdr/types/fenv_t.h"
1313

1414
namespace LIBC_NAMESPACE {
1515

libc/src/fenv/fesetenv.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_FENV_FESETENV_H
1010
#define LLVM_LIBC_SRC_FENV_FESETENV_H
1111

12-
#include <fenv.h>
12+
#include "hdr/types/fenv_t.h"
1313

1414
namespace LIBC_NAMESPACE {
1515

libc/src/fenv/fesetexceptflag.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/fenv/fesetexceptflag.h"
10+
#include "hdr/types/fexcept_t.h"
1011
#include "src/__support/FPUtil/FEnvImpl.h"
1112
#include "src/__support/common.h"
12-
#include <fenv.h>
1313

1414
namespace LIBC_NAMESPACE {
1515

libc/src/fenv/feupdateenv.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_FENV_FEUPDATEENV_H
1010
#define LLVM_LIBC_SRC_FENV_FEUPDATEENV_H
1111

12-
#include <fenv.h>
12+
#include "hdr/types/fenv_t.h"
1313

1414
namespace LIBC_NAMESPACE {
1515

libc/test/UnitTest/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ add_unittest_framework_library(
135135
LibcTest
136136
libc.src.__support.FPUtil.fp_bits
137137
libc.src.__support.FPUtil.fenv_impl
138+
libc.hdr.types.fenv_t
138139
)
139140

140141
add_unittest_framework_library(

libc/test/UnitTest/FPExceptMatcher.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
#include "FPExceptMatcher.h"
1010

11-
#include <fenv.h>
11+
#include "hdr/types/fenv_t.h"
12+
#include "src/__support/FPUtil/FEnvImpl.h"
1213
#include <memory>
1314
#include <setjmp.h>
1415
#include <signal.h>
@@ -36,12 +37,12 @@ FPExceptMatcher::FPExceptMatcher(FunctionCaller *func) {
3637

3738
caughtExcept = false;
3839
fenv_t oldEnv;
39-
fegetenv(&oldEnv);
40+
fputil::get_env(&oldEnv);
4041
if (sigsetjmp(jumpBuffer, 1) == 0)
4142
funcUP->call();
4243
// We restore the previous floating point environment after
4344
// the call to the function which can potentially raise SIGFPE.
44-
fesetenv(&oldEnv);
45+
fputil::set_env(&oldEnv);
4546
signal(SIGFPE, oldSIGFPEHandler);
4647
exceptionRaised = caughtExcept;
4748
}

libc/test/src/fenv/exception_flags_test.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/types/fexcept_t.h"
910
#include "src/fenv/fegetexceptflag.h"
1011
#include "src/fenv/fesetexceptflag.h"
1112

1213
#include "src/__support/FPUtil/FEnvImpl.h"
1314
#include "test/UnitTest/Test.h"
1415

15-
#include <fenv.h>
16-
1716
TEST(LlvmLibcFenvTest, GetExceptFlagAndSetExceptFlag) {
1817
// We will disable all exceptions to prevent invocation of the exception
1918
// handler.

libc/test/src/fenv/feholdexcept_test.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/types/fenv_t.h"
910
#include "src/fenv/feholdexcept.h"
1011

1112
#include "src/__support/FPUtil/FEnvImpl.h"
1213
#include "src/__support/macros/properties/architectures.h"
1314
#include "test/UnitTest/FPExceptMatcher.h"
1415
#include "test/UnitTest/Test.h"
1516

16-
#include <fenv.h>
17-
1817
TEST(LlvmLibcFEnvTest, RaiseAndCrash) {
1918
#if defined(LIBC_TARGET_ARCH_IS_ANY_ARM) || \
2019
defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)

libc/test/src/fenv/feupdateenv_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/types/fenv_t.h"
910
#include "src/fenv/feupdateenv.h"
1011

1112
#include "src/__support/FPUtil/FEnvImpl.h"
1213
#include "test/UnitTest/Test.h"
1314

14-
#include <fenv.h>
1515
#include <signal.h>
1616

1717
TEST(LlvmLibcFEnvTest, UpdateEnvTest) {

libc/test/src/fenv/getenv_and_setenv_test.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/types/fenv_t.h"
910
#include "src/fenv/fegetenv.h"
1011
#include "src/fenv/fegetround.h"
1112
#include "src/fenv/fesetenv.h"
@@ -14,8 +15,6 @@
1415
#include "src/__support/FPUtil/FEnvImpl.h"
1516
#include "test/UnitTest/Test.h"
1617

17-
#include <fenv.h>
18-
1918
TEST(LlvmLibcFenvTest, GetEnvAndSetEnv) {
2019
// We will disable all exceptions to prevent invocation of the exception
2120
// handler.

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

+13
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ libc_support_library(
130130

131131
############################ Type Proxy Header Files ###########################
132132

133+
libc_support_library(
134+
name = "types_fenv_t",
135+
hdrs = ["hdr/types/fenv_t.h"],
136+
)
137+
138+
libc_support_library(
139+
name = "types_fexcept_t",
140+
hdrs = ["hdr/types/fexcept_t.h"],
141+
)
142+
133143
libc_support_library(
134144
name = "types_sigset_t",
135145
hdrs = ["hdr/types/sigset_t.h"],
@@ -776,6 +786,7 @@ libc_support_library(
776786
":errno",
777787
":hdr_fenv_macros",
778788
":hdr_math_macros",
789+
":types_fenv_t"
779790
],
780791
)
781792

@@ -1251,6 +1262,7 @@ libc_function(
12511262
deps = [
12521263
":__support_common",
12531264
":__support_fputil_fenv_impl",
1265+
":types_fexcept_t"
12541266
],
12551267
)
12561268

@@ -1261,6 +1273,7 @@ libc_function(
12611273
deps = [
12621274
":__support_common",
12631275
":__support_fputil_fenv_impl",
1276+
":types_fexcept_t",
12641277
],
12651278
)
12661279

0 commit comments

Comments
 (0)