Skip to content

[clang] Fix name conflict with sys/mac.h on AIX #88644

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

Merged
merged 3 commits into from
Apr 14, 2024

Conversation

Endilll
Copy link
Contributor

@Endilll Endilll commented Apr 14, 2024

@Endilll Endilll added cuda clang:frontend Language frontend issues, e.g. anything involving "Sema" platform:aix labels Apr 14, 2024
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 14, 2024

@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)

Changes

Fixes clang-ppc64-aix bot failure after #88559 (0a6f6df) https://lab.llvm.org/buildbot/#/builders/214/builds/11887


Full diff: https://github.com/llvm/llvm-project/pull/88644.diff

1 Files Affected:

  • (modified) clang/include/clang/Basic/Cuda.h (+5)
diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index acc6bb6581d857..3908e10bc61061 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -50,6 +50,11 @@ const char *CudaVersionToString(CudaVersion V);
 // Input is "Major.Minor"
 CudaVersion CudaStringToVersion(const llvm::Twine &S);
 
+// We have a name conflict with sys/mac.h on AIX
+#ifdef _AIX
+#undef SM_32
+#endif
+
 enum class CudaArch {
   UNUSED,
   UNKNOWN,

@Endilll Endilll requested a review from uweigand April 14, 2024 11:37
Co-authored-by: Joseph Huber <huberjn@outlook.com>
@jhuber6
Copy link
Contributor

jhuber6 commented Apr 14, 2024

I can't really think of anything more clever here unfortunately and we should probably unbreak the bot. Maybe someone more familiar with PowerPC knows if it's possible to simply not include this header somewhere.

@Endilll Endilll merged commit 7cfe736 into llvm:main Apr 14, 2024
4 checks passed
@Endilll Endilll deleted the semacuda-aix-fix branch April 14, 2024 13:51
bazuzi pushed a commit to bazuzi/llvm-project that referenced this pull request Apr 15, 2024
Fixes clang-ppc64-aix bot failure after llvm#88559
(0a6f6df)
https://lab.llvm.org/buildbot/#/builders/214/builds/11887

---------

Co-authored-by: Joseph Huber <huberjn@outlook.com>
// We have a name conflict with sys/mac.h on AIX
#ifdef SM_32
#undef SM_32
#endif
Copy link
Member

@Artem-B Artem-B Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. What could possibly go wrong, if someone who needed the original definition of SM_32 ends up transitively including this header and losing the macro definition?

A better way to handle it as a workaround would be to push the macro definition, undef it, and then pop it back at the end of the header.

Even better would be to add prefixes to the macros and/or the enum here to disambiguate them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already do that, the problem is that CudaArch::SM_32 will still invoke the preprocessorr, see https://godbolt.org/z/84xKej5K9. We can't do this from a header level, we'd need to do it around every single use as far as I know, which might be doable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could always just make all of these lower case instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could always just make all of these lower case instead?

That would be odd. LLVM style wants them to be CamelCased.
This enum is rarely used, so renaming them to something more CUDA/NVPTXspecific would be best, IMO.
E.g NVSM_32

Or we could rename only SM_32. The constant is rather inconsequential and is used in a few places only. Renaming it to _SM_32 with a comment that AIX headers have SM_32 defined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, modern CUDA installations don't even allow you to build for anything older than sm_52 now. We could also just delete those enums entirely.

Copy link
Contributor

@jhuber6 jhuber6 Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just naming it like _SM_32 works for me, with a note that they'll get removed in the future. I can make the PR if you want.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_SM_32 is a reserved identifier so we should not use that as a name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, totally forgot that _<uppercase> was reserved (Would've been nice if the AIX headers followed that rule).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. Thank you for taking care of this issue.

On a side note, do we know if there's a way to file a bug for AIX? They should not be setting macros with names that could conceivably be defined by a user. In theory. I think normally they should be double-underscore-prefixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #88779

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category cuda platform:aix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants