This is an archive of the discontinued LLVM Phabricator instance.

[AIX] Define __HOS_AIX__ macro
ClosedPublic

Authored by Jake-Egan on Aug 1 2021, 1:56 PM.

Details

Summary


This patch defines __HOS_AIX__ macro for AIX in case of a cross compiler implementation.

Tested with SPEC.

Diff Detail

Event Timeline

Jake-Egan created this revision.Aug 1 2021, 1:56 PM
Jake-Egan requested review of this revision.Aug 1 2021, 1:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2021, 1:56 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Jake-Egan retitled this revision from Define __HOS_AIX__ macro to [AIX] Define __HOS_AIX__ macro.Aug 1 2021, 2:00 PM
Jake-Egan edited the summary of this revision. (Show Details)
Jake-Egan added a reviewer: cebowleratibm.
Jake-Egan edited the summary of this revision. (Show Details)Aug 1 2021, 2:24 PM
cebowleratibm requested changes to this revision.Aug 4 2021, 11:59 AM
cebowleratibm added inline comments.
clang/lib/Basic/Targets/OSTargets.h
679

HOS_AIX should only be defined if both the host and the target OS are AIX.

This revision now requires changes to proceed.Aug 4 2021, 11:59 AM
Jake-Egan updated this revision to Diff 364685.Aug 5 2021, 8:20 PM

Only define if AIX is the target and host.

cebowleratibm added inline comments.Aug 5 2021, 8:29 PM
clang/test/Preprocessor/not-host-aix.c
2 ↗(On Diff #364685)

this should specify an aix triple. The test doesn't run on an aix host and any other host should not define the macro even with an aix target.

cebowleratibm added inline comments.Aug 5 2021, 8:33 PM
clang/lib/Basic/Targets/PPC.cpp
306 ↗(On Diff #364685)

suggest using a temp rather than unnecessarily declaring the local var:

if (Triple(sys::getProcessTriple()).isOSAIX() ...

Jake-Egan updated this revision to Diff 364779.Aug 6 2021, 6:40 AM

Use a temp rather than a local var.

Jake-Egan marked 2 inline comments as done.Aug 6 2021, 6:40 AM
This revision is now accepted and ready to land.Aug 6 2021, 7:24 AM
This revision was automatically updated to reflect the committed changes.
joerg added a subscriber: joerg.Aug 6 2021, 4:18 PM

I'm puzzled by this change. I don't think we have any case so far where the compiler behavior changes with the host OS and I don't think it should. What's the point / use case of this macro?

I'm puzzled by this change. I don't think we have any case so far where the compiler behavior changes with the host OS and I don't think it should. What's the point / use case of this macro?

I agree that this is strange. And strange things need good documentation. The documentation for this extremely strange behaviour is woefully inadequate both in the code and in the commit message. Of course, I am not certain why this is needed but I assume it has something to do with the fact that it is the OS on AIX that owns the headers so the compiler needs to know whether it is running on an AIX host due to some non-portable code in the headers. Of course, this can't be the full explanation as it brings up many questions. This needs to be very clear to the reader - both in the commit message and in the code.

Another thing that I find extremely strange is that we set this only if we are on an AIX host and are targeting AIX. If this is truly something that has to do with the host (which I am not positive is the case as I'm not sure what HOS in the macro name means), then why is it not needed when cross-compiling?

I'm puzzled by this change. I don't think we have any case so far where the compiler behavior changes with the host OS and I don't think it should. What's the point / use case of this macro?

HOS_AIX is a macro defined by the XL C/C++ compilers on AIX. Although there was never an AIX cross compiler offering from IBM, the intention of the macro was to indicate that the host is AIX. HOS_AIX is being defined to minimize porting pain for existing code compiled with xlc/xlC. Given that LLVM has the infrastructure to be a cross-compiler, I consider it important to implement the macro to the original intention. Because the macro is a "legacy" AIX xlc macro I don't think it's relevant to define for non-AIX targets. If there's no objection to the change I can work with Jake to elaborate on the comments with an improved commit message.

joerg added a comment.Aug 9 2021, 8:08 AM

clang is fundamentally a cross-compiler only. I don't see any point for having host-specific branches in this case at all. Either the macro should be specified for the target all the time or not at all, but it should most definitely not depend on the host. That's actually breaking a number of existing use case for clang in subtle ways, e.g. partially preprocessed files (-frewrite-includes) should behave the same on any platform given the same command line.

clang is fundamentally a cross-compiler only. I don't see any point for having host-specific branches in this case at all. Either the macro should be specified for the target all the time or not at all, but it should most definitely not depend on the host. That's actually breaking a number of existing use case for clang in subtle ways, e.g. partially preprocessed files (-frewrite-includes) should behave the same on any platform given the same command line.

Given that we have a legacy XL macro with no legacy cross compiler I think it's fine if we set this according to the target only. It's fully redundant to _AIX but we'll define it for any working use-case with the current xlC compiler. If IBM has a compelling use case for a host-specific macro we can always revive this discussion. For now, you're probably making us from making a mistake ;)

Given that we have a legacy XL macro with no legacy cross compiler I think it's fine if we set this according to the target only. It's fully redundant to _AIX but we'll define it for any working use-case with the current xlC compiler. If IBM has a compelling use case for a host-specific macro we can always revive this discussion. For now, you're probably making us from making a mistake ;)

follow up in https://reviews.llvm.org/D107825