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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/Cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ 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 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

enum class CudaArch {
UNUSED,
UNKNOWN,
Expand Down