This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Call __chkstk for dynamic stack allocation in all windows environments
ClosedPublic

Authored by mstorsjo on Jan 19 2018, 4:19 AM.

Details

Summary

This matches what MSVC does for alloca() function calls on ARM. Even if MSVC doesn't support VLAs at the language level, it does support the alloca function.

On the clang level, both the _alloca() (when emulating MSVC) and __builtin_alloca() builtin functions, and VLAs, map to the same LLVM IR "alloca" function - so within LLVM they're not distinguishable from each other.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Jan 19 2018, 4:19 AM
mstorsjo updated this revision to Diff 130597.Jan 19 2018, 5:55 AM

Simplified by using Subtarget->isTargetWindows() instead of Subtaget->getTargetTriple().isOSWindows().

What is the motivation for this change? If you are trying to enable this for MinGW, that is fine, but I'm not sure if we should try to catch the VLA issues in the frontend. I believe that on x86_64, we also disallow the VLAs as Microsoft does not permit them there, but @rnk can correct me if I'm wrong on that.

What is the motivation for this change? If you are trying to enable this for MinGW, that is fine, but I'm not sure if we should try to catch the VLA issues in the frontend. I believe that on x86_64, we also disallow the VLAs as Microsoft does not permit them there, but @rnk can correct me if I'm wrong on that.

I'm trying to enable it both for MinGW and for MSVC. I'm not interested in the case of VLAs though, only for the alloca() function. On the clang level, both are lowered to the same LLVM alloca intrinsic function. to match MSVC better, perhaps clang should reject VLAs on that level if acting in MSVC mode - currently it doesn't. And the current code in LLVM (that I'm changing here) doesn't do much to "disable" VLAs for MSVC - it just lowers them into a normal stack decrement, which would compile just fine, but possibly lead to spurious runtime crashes instead.

I'm not sure that I follow how this is only for the alloca function. It is for an intrinsic, which just generally enables it. Does it match a cl intrinsic?

I'm not sure that I follow how this is only for the alloca function. It is for an intrinsic, which just generally enables it. Does it match a cl intrinsic?

Yes - this is for an intrinsic, which enables it for both the alloca function and for VLAs - on the LLVM level they're indistinguishable. MSVC supports the alloca function.

If you want to disallow VLAs, that has to be done in clang, not here.

Does it match a cl intrinsic?

In msvc cl.exe, _alloca is an intrinsic that matchea the alloca intrinsic in llvm.

Ah, then could you add a test case that just lowers the LLVM intrinsic?

mstorsjo edited the summary of this revision. (Show Details)Jan 23 2018, 9:52 PM

Updated the summary/commit message as requested on irc.

compnerd accepted this revision.Jan 23 2018, 9:59 PM
This revision is now accepted and ready to land.Jan 23 2018, 9:59 PM
This revision was automatically updated to reflect the committed changes.