Visual Studio can't compile aligned function parameters
When compiling using Visual Studio 2017 I get the following errors:
c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(707): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(707): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(744): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(744): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(802): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(802): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(818): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(877): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(877): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(893): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(924): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(924): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(945): error C2719: 'VecOne': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(945): error C2719: 'VecTwo': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(996): error C2719: 'A': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1017): error C2719: 'A': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1057): error C2719: 'A': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1088): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1125): error C2719: 'Matrix': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1138): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1138): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1154): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1154): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1168): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1168): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1172): error C2719: 'Matrix': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1187): error C2719: 'Matrix': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1187): error C2719: 'Vector': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1191): error C2719: 'Matrix': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1287): error C2719: 'Vector': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1416): error C2719: 'A': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1437): error C2719: 'A': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1458): error C2719: 'A': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1486): error C2719: 'VecOne': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1486): error C2719: 'VecTwo': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1514): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1514): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1521): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1521): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1549): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1549): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1556): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1556): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1598): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1598): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1605): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1612): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1612): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1619): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1626): error C2719: 'Matrix': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1626): error C2719: 'Vector': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1675): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1675): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1682): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1689): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1717): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1717): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1738): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1738): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1745): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1745): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1773): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1773): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1780): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1780): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1808): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1808): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1815): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1815): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1843): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1850): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1878): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1885): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1899): error C2719: 'Matrix': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1899): error C2719: 'Vector': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1920): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1920): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1941): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1948): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1972): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1977): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(1997): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2002): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2022): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2062): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2102): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2102): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2117): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2117): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2208): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2208): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2263): error C2719: 'Matrix': formal parameter with requested alignment of 16 won't be aligned c:\users\pmckenna\documents\experiments\src\Handmade-Math/HandmadeMath.h(2263): error C2719: 'Vector': formal parameter with requested alignment of 16 won't be aligned
These function parameters could be const references instead of copies as this SO post suggests, no? https://stackoverflow.com/questions/28488986/formal-parameter-with-declspecalign16-wont-be-aligned
Sorry, forgot to mention that this is with v1.5.0
Enable __vectorcall https://msdn.microsoft.com/en-us/library/dn375768.aspx.
Hey, ill look into getting this fixed. @coastwise I see all your commits passing everything as const ref's instead due to us having to keep C compatibility we can't do that. If i remember correctly this only happens when you compile in MSVC using a x86 configuration ?
Thanks! That is the configuration I'm using yes. I'm calling cl directly.
I guess I saw the operator overloads and didn't realize they were in a #ifdef __cplusplus block. I obviously won't make a pull request with it, but the const refs have unblocked me from developing on windows for now.
Cheers, Patrick
If you compiled with x64 it wouldn't be an issue, but i understand that isn't the real solution here
@coastwise Hey spent some time tonight trying to reproduce this in Visual Studio 2017, and i couldn't. Can you provide me a with repro file?
Hey, I've added a build script and minimum source file to reproduce the errors I'm having.
Try running visualstudio_build.bat in the tests folder
https://github.com/coastwise/Handmade-Math/tree/visualstudio
Thanks!
Weird seems that i can't reproduce this on VS2017. All i did was is change the VcVarsall path in the bat file you supplied fork you supplied. Ill check later if one of my other PCs has a earlier version of VS installed
I can repro on VS2015 community:
If I compile the tests/hmm_test.c (and add HandemadeMath.c), and use a "win32" target (32 bit), I get this error. If I create a x64 target and compile I do not see this error.
I think this should either be documented, a more clear static assertion should be thrown, or the ifdefs should automatically do whatever they need to do to fix this.
Ohhhhhhh, i never use x86 mode this could actually be a problem! Let me see if i can reproduce ill get back to you ASAP
So an update on the investigation. I compiled HandmadeMath.h in x86 mode with C and CPP and got no errors. This might be caused be a default Visual Studio parameter.
S:\Handmade-Math>cl main.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26726 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
main.cpp
Microsoft (R) Incremental Linker Version 14.15.26726.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:main.exe
main.obj
S:\Handmade-Math>cl main.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26726 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
main.c
Microsoft (R) Incremental Linker Version 14.15.26726.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:main.exe
main.obj
main.cpp and main.c aren't in the repo, so I don't know what files you are compiling.
If you just include the HandmadeMath.h header and don't actually pass parameters to the affected functions then you won't get these alignment errors. You also won't actually be using any of the functions, so that's not super useful. Hence why I'm trying to compile the test suite :)
On the plus side, I do not see this repro in VS 2017 in x86 mode. I only see the problem on VS 2015.
I tried with cl.exe, roughly as you described, with test suite instead, and here's the output -
VS 2015:
λ cl hmm_test.c HandmadeMath.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
hmm_test.c
c:\users\myusername\dev\handmade-math\test\../HandmadeMath.h(757): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned
c:\users\myusername\dev\handmade-math\test\../HandmadeMath.h(757): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned
c:\users\myusername\dev\handmade-math\test\../HandmadeMath.h(794): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned
c:\users\myusername\dev\handmade-math\test\../HandmadeMath.h(794): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned
c:\users\myusername\dev\handmade-math\test\../HandmadeMath.h(852): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned
c:\users\myusername\dev\handmade-math\test\../HandmadeMath.h(852): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned
c:\users\myusername\dev\handmade-math\test\../HandmadeMath.h(868): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned
c:\users\myusername\dev\handmade-math\test\../HandmadeMath.h(927): error C2719: 'Left': formal parameter with requested alignment of 16 won't be aligned
c:\users\myusername\dev\handmade-math\test\../HandmadeMath.h(927): error C2719: 'Right': formal parameter with requested alignment of 16 won't be aligned
... lots more of these ...
VS 2017:
λ cl hmm_test.c HandmadeMath.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26726 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
hmm_test.c
HandmadeMath.c
Generating Code...
Microsoft (R) Incremental Linker Version 14.15.26726.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:hmm_test.exe
hmm_test.obj
HandmadeMath.obj
With the VS 2017 compile, I also get 100% of tests passing when I run hmm_test.exe.
Seems ill have to get VS2015 installed and get back to you. I LOVE when compiler updates change things haha.