-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Fix compiler errors in GVN.h for clang versions older than 15 #107636
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
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-support Author: Thomas Fransham (fsfod) ChangesFix compiler errors in GVN.h from clang versions older than 15 that don't support gnu style attribute on namespaces. @tstellar, @compnerd. Full diff: https://github.com/llvm/llvm-project/pull/107636.diff 1 Files Affected:
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index e1d54af7dfcce1..0452f88cbf2c66 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -130,7 +130,12 @@
#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \
(defined(__MINGW32__) && defined(__clang__)))
+// Clang compilers older then 15 do not support gnu style attributes on namespaces
+#if defined(__clang__) && _clang_major__ < 15
+#define LLVM_LIBRARY_VISIBILITY [[gnu::visibility("hidden")]]
+#else
#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
+#endif
#define LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#elif defined(_WIN32)
#define LLVM_ALWAYS_EXPORT __declspec(dllexport)
|
llvm/include/llvm/Support/Compiler.h
Outdated
@@ -130,7 +130,12 @@ | |||
|
|||
#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \ | |||
(defined(__MINGW32__) && defined(__clang__))) | |||
// Clang compilers older then 15 do not support gnu style attributes on namespaces | |||
#if defined(__clang__) && _clang_major__ < 15 |
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.
Typo, you have one leading underscore on __clang_major__
while you should have two.
Note that with Apple Clang, there's a separate different versioning, where __clang_major__
reflects the Apple versioning. If __apple_build_version__
is defined, then __clang_major__
reflects the Xcode version number, distinct from the upstream LLVM.org version numbers.
According to https://en.wikipedia.org/wiki/Xcode#Xcode_11.0_-_14.x_(since_SwiftUI_framework)_2, Xcode 14.0 - 14.2 maps to LLVM 14.0, while Xcode 14.3 maps to LLVM 15.0.
So out of pure luck and coincidence, the cutoff we're looking at might actually mostly work out here with one single version number check :-)
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 guess i should of read further down when i went looking for the correct macro on this page https://github.com/cpredef/predef/blob/master/Compilers.md#clang
Unfortunately, it seems like this isn't enough to fix the build issues:
|
At this point, I think it would be safest to revert, reevaluate and test the known problematic cases before trying to reland this. |
is that on a old version of clang as well? |
Yes, this was on Apple Clang 12, which should correspond to llvm.org Clang 10-11. |
And just to be clear - the issue here is that |
I guess i will have to change my LLVM_C_ABI macro as well although my changes to switch that file to use are not in yet. The alternative fix i had before was just a separate macro for namespaces, I was just trying to avoid a proliferation of visibility macros for different code elements. |
You can test this locally with the following command:git-clang-format --diff 7f77db4ffca9b275b40e8720208a03dd6cbc390e 1ee44f3d3ab976b35b1e81e2fe91da86684d8534 --extensions h -- llvm/include/llvm/Support/Compiler.h llvm/include/llvm/Transforms/Scalar/GVN.h View the diff from clang-format here.diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h b/llvm/include/llvm/Transforms/Scalar/GVN.h
index be6c0ec5ed..e6adb183ff 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -62,7 +62,7 @@ struct AvailableValue;
struct AvailableValueInBlock;
class GVNLegacyPass;
-} // end namespace gvn
+} // namespace LLVM_LIBRARY_VISIBILITY_NAMESPACE gvn
/// A set of parameters to control various transforms performed by GVN pass.
// Each of the optional boolean parameters can be set to:
|
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.
LGTM, this seems to fix my build on Apple Clang 12 (at least it seems to not fail for quite a while).
…gnu style attributes on namespaces Fixes errors in GVN.h after changes in llvm#96630 to how LLVM_LIBRARY_VISIBILITY is defined
946d770
to
1ee44f3
Compare
Please either revert the original commit or land this commit to fix the issue. The libc runtimes builder is currently broken on this issue since it is on clang 14: https://lab.llvm.org/buildbot/#/builders/78/builds/5463 |
You can commit it for me if for if you want since i don't have commit access. |
Fix compiler errors in GVN.h from clang versions older than 15 that don't support gnu style attribute on namespaces. @tstellar, @compnerd.