NVIDIA-Omniverse / PhysX

NVIDIA PhysX SDK
BSD 3-Clause "New" or "Revised" License
2.61k stars 374 forks source link

Unable to compile with Clang - __m128 is not a structure or union #265

Closed thempc closed 7 months ago

thempc commented 7 months ago

Versions

PhysX v5.3.1 Windows 11 Visual Studio Community 2022 - Version 17.8.5

Additional Info

I'm in the process of upgrading from 4.1 to 5.3.1, this wasn't an issue in the 4.1 release.

Steps to Trigger Behavior

  1. Build PhysX (technically not required to reproduce the issue, can skip to step 2)
  2. Include the PxPhysicsAPI.h in an external project
  3. Try to build external project using the platform toolset "LLVM (clang-cl)" in Visual Studio Community 2022 - Version 17.8.5

Code Snippet to Reproduce Behavior

#include <iostream>
#include <PhysX/PxPhysicsAPI.h>

int main() {
    std::cout << "Hello, world!" << std::endl;
    return 0;
}

Expected Behavior

It's expected the code compiles without issues.

Actual Behavior

The code will fail to compile and gives the following errors:

1>In file included from ..\..\..\Source\Boot\Main.cpp:46:
1>In file included from ..\..\..\includes\PhysX/PxPhysicsAPI.h:99:
1>In file included from ..\..\..\includes\physx/foundation/PxVecMath.h:1327:
1>In file included from ..\..\..\includes\physx/foundation/PxInlineAoS.h:36:
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3088,8): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3088,32): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3088,50): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3089,8): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3089,32): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3089,50): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3090,8): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3090,32): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3090,50): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3091,8): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3091,32): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3091,50): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3092,8): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3092,32): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3092,50): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3093,8): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3093,32): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3093,50): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>..\..\..\includes\physx/foundation/windows/PxWindowsInlineAoS.h(3094,8): error : member reference base type 'VecU16V' (aka '__m128') is not a structure or union
1>fatal error: too many errors emitted, stopping now [-ferror-limit=]
preist-nvidia commented 7 months ago

Hi @thempc - we only test and support MSVC on Windows is that not an option for you?

On Linux we support Clang, see the platform readme, but you may have to update some build configuration settings/defines to make Clang work on Windows.

thempc commented 7 months ago

Hey @preist-nvidia, thanks for the quick reply. MSVC is technically an option, however we've chosen clang for multiple other reasons. If this isn't something supported then of course feel free to close this issue, I just assumed you might wish to know as it used to work before.

We'll be fine with adjusting the code locally to make it work. If appreciated we can make a pull request with it later.

preist-nvidia commented 7 months ago

Yes, always best to let us know! And we do need to state more clearly what compilers we support on Win.

Please don't worry about the PR for now, I'd ping you if it becomes relevant. Thank you very much for offering!

Closing with this.

zopsicle commented 3 months ago

It may still be worth noting that Microsoft (vendor of MSVC) recommends against accessing the fields of __m128 directly:

https://learn.microsoft.com/en-us/cpp/cpp/m128?view=msvc-170

You should not access the __m128 fields directly.

There's only a handful places where PhysX does this (grep '\.m128_'), so it may be worth fixing regardless of intended clang compatibility.