-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang][Headers] Fix tgmath.h incompatibility with Glibc #161301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
When building Glibc with Clang, several conformance and math tests related to <tgmath.h> fail. This is because Clang's built-in <tgmath.h> is used by default, which is not fully compatible with the expectations of the Glibc test suite. Glibc provides its own <tgmath.h> which is specifically designed to work with its library implementation, supporting all necessary GNU extensions and features. This patch modifies Clang's <tgmath.h> to detect when it is being used in a Glibc environment (by checking for the `__GLIBC__` macro). When `__GLIBC__` is defined, Clang's header will use `include_next` to include Glibc's system header, effectively deferring to Glibc's implementation. This is the same mechanism already used for macOS (`__APPLE__`). This change allows Glibc to be successfully built and tested with Clang, resolving the following test failures: - conform/ISO11/tgmath.h/conform - conform/ISO99/tgmath.h/conform - conform/POSIX2008/tgmath.h/conform - conform/XOPEN2K/tgmath.h/conform - conform/XOPEN2K8/tgmath.h/conform - math/test-tgmath - math/test-tgmath2 This approach addresses the compatibility issue at its source within Clang, rather than requiring workarounds in Glibc.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-x86 Author: Zhao Mao (ac-bcc) ChangesWhen building Glibc with Clang, several conformance and math tests related to <tgmath.h> fail. This is because Clang's built-in <tgmath.h> is used by default, which is not fully compatible with the expectations of the Glibc test suite. Glibc provides its own <tgmath.h> which is specifically designed to work with its library implementation, supporting all necessary GNU extensions and features. This patch modifies Clang's <tgmath.h> to detect when it is being used in a Glibc environment (by checking for the This change allows Glibc to be successfully built and tested with Clang, resolving the following test failures:
This approach addresses the compatibility issue at its source within Clang, rather than requiring workarounds in Glibc. Full diff: https://github.com/llvm/llvm-project/pull/161301.diff 1 Files Affected:
diff --git a/clang/lib/Headers/tgmath.h b/clang/lib/Headers/tgmath.h
index 7acf18b9dd357..e79e84b1c72e5 100644
--- a/clang/lib/Headers/tgmath.h
+++ b/clang/lib/Headers/tgmath.h
@@ -17,7 +17,7 @@
* platforms. This is done after #include <math.h> to avoid depcycle conflicts
* between libcxx and darwin in C++ modules builds.
*/
-#if defined(__APPLE__) && __STDC_HOSTED__ && __has_include_next(<tgmath.h>)
+#if (defined(__APPLE__) && __STDC_HOSTED__ && __has_include_next(<tgmath.h>)) || defined(__GLIBC__)
# include_next <tgmath.h>
#else
|
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions h -- clang/lib/Headers/tgmath.h
View the diff from clang-format here.diff --git a/clang/lib/Headers/tgmath.h b/clang/lib/Headers/tgmath.h
index e79e84b1c..594e44d55 100644
--- a/clang/lib/Headers/tgmath.h
+++ b/clang/lib/Headers/tgmath.h
@@ -17,7 +17,8 @@
* platforms. This is done after #include <math.h> to avoid depcycle conflicts
* between libcxx and darwin in C++ modules builds.
*/
-#if (defined(__APPLE__) && __STDC_HOSTED__ && __has_include_next(<tgmath.h>)) || defined(__GLIBC__)
+#if (defined(__APPLE__) && __STDC_HOSTED__ && \
+ __has_include_next(<tgmath.h>)) || defined(__GLIBC__)
# include_next <tgmath.h>
#else
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to not just do #if __has_include_next(<tgmath.h>)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea on the headers... Aaron is perhaps a better person to review?
When building Glibc with Clang, several conformance and math tests related to <tgmath.h> fail. This is because Clang's built-in <tgmath.h> is used by default, which is not fully compatible with the expectations of the Glibc test suite.
Glibc provides its own <tgmath.h> which is specifically designed to work with its library implementation, supporting all necessary GNU extensions and features.
This patch modifies Clang's <tgmath.h> to detect when it is being used in a Glibc environment (by checking for the
__GLIBC__
macro). When__GLIBC__
is defined, Clang's header will useinclude_next
to include Glibc's system header, effectively deferring to Glibc's implementation. This is the same mechanism already used for macOS (__APPLE__
).This change allows Glibc to be successfully built and tested with Clang, resolving the following test failures:
This approach addresses the compatibility issue at its source within Clang, rather than requiring workarounds in Glibc.