-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Add C++ linkage specification in SYCL assert headers #15570
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
Conversation
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.
The example from the commit message should be moved into sycl/test
@@ -16,6 +16,7 @@ | |||
#include <../include/cassert> | |||
#endif | |||
|
|||
extern "C++" { |
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.
Do we really need this? <cassert>
is a C++ header, not C.
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 think something like
#ifdef __cplusplus
extern "C" {
#endif
#include <cassert>
#ifdef __cplusplus
}
#endif
int main() {}
is well-defined code and without the changes, it fails to compile.
Also note that the external linkage specification is after the actual C++ STL header <cassert>
is included so we're not actually changing anything in the STL header contents.
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.
@tahonermann , @AaronBallman , is the above code really well-defined?
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 don't think including a C++ standard library header in a linkage specification block is well-formed.
What problem is the extern "C++"
declaration intended to solve? If the problem is that code somewhere else is including the <cassert>
header inside of an extern "C"
declaration then that is the bug that should be fixed.
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.
Note that, per [support.c.headers.general]p1, there is no need to include C library headers within a extern "C"
block when compiling as C++.
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 might be wrong, but I think libstdc++ itself might be doing something like that.
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.
Since libstdc++ is an implementation of the C++ standard library, it is allowed to do things that user code is not. If it "knows" that the header it is including is a C header that doesn't itself place its contents in an extern "C"
block, then it makes since for it to do so as part of wrapping that header (e.g., inside the <cassert>
header).
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.
Note that, per [support.c.headers.general]p1, there is no need to include C library headers within a extern "C" block when compiling as C++.
"there is no need" doesn't mean "it's prohibited", right?
It also isn't right to include C headers in an extern "C" block when compiling as C++.
Can the clients that are including C headers be fixed to not do so within a extern "C" block?
Do you have a link to the C++ draft section which says this? I initially wanted to push back on the bug report to make customer rewrite their code, but I haven't been able to find a C++ spec section which would pronounce this ill-formed
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'm not aware of wording in the C++ standard that explicitly makes inclusion of a C header within an extern "C"
block ill-formed. My interpretation of such inclusion being ill-formed comes from the absence of constraints that would prohibit use of C++ features in the C++ standard library implementation of the C headers.
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.
As an example where C++ features are used in the implementation of C headers provided by a C++ standard library implementation, see the source code for libstdc++. It provides a set of C compatibility headers that are wrappers around the C++ equivalents. Specifically, see its implementation of the stdlib.h header; it unconditionally uses C++ using
declarations. Whether these compatibility headers are used is a decision made when gcc is configured and built and depends on the availability of a C library implementation.
This [PR](#15570) added C++ linkage specifications for the SYCL wrappers around the STL assert headers `assert.h` and `cassert`. For `cassert`, this is actually superfluous since it is purely a C++ header. This PR removes it.
Some SYCL applications are seeing compilation failures related to the SYCL assert headers. Specifically, they are wrapping the SYCL assert headers in C linkage specifications in their applications. These headers in turn include files that contain templates which emit errors under C linkage specifications so this PR explicitly adds C++ linkage specifications in the header contents to override any extra specification that the clients may add. Here is an example of faulty client code:
Error fragments: