[Openmp-commits] [PATCH] D137828: RFC: [openmp] Don't assume a specific layout for alloca() in Windows arm64 __kmp_invoke_microtask

Martin Storsjö via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Nov 14 05:13:28 PST 2022


mstorsjo added inline comments.


================
Comment at: openmp/runtime/src/z_Windows_NT-586_util.cpp:174
-    size_t len = (argc - 6) * sizeof(void *);
-    void *argbuf = alloca(len);
-    memcpy(argbuf, &p_argv[6], len);
----------------
mstorsjo wrote:
> natgla wrote:
> > argbuf better be volatile void*, to prevent optimizer messing with it
> Yes, possibly. With Clang I managed to make it not optimize it out, by adding e.g. `__asm__ __ volatile__("" ::"r"(argbuf))`, which passes the buffer pointer to an opaque inline assembly snippet (so the compiler can't assume anything about it) which does nothing.
> 
> But even then, there's no strict guarantee that the buffer actually is at the exact bottom of the stack frame - there could concievably be some extra space at the bottom of the frame (e.g. if the compiler is saving space for outgoing parameters, if there is a function call with more than 8 parameters somewhere).
FWIW, changing the buffer to `volatile void *` doesn't work as such here:
```
../runtime/src/z_Windows_NT-586_util.cpp:173:5: error: no matching function for call to 'memcpy'
    memcpy(argbuf, &p_argv[6], len);
    ^~~~~~
/home/martin/clang-nightly/aarch64-w64-mingw32/include/wchar.h:1476:17: note: candidate function not viable: 1st argument ('volatile void *') would lose volatile qualifier
  void *__cdecl memcpy(void * __restrict__ _Dst,const void * __restrict__ _Src,size_t _MaxCount) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
                ^
```
(And if casting the volatile pointer back to `void*`, there's no effect from that.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137828/new/

https://reviews.llvm.org/D137828



More information about the Openmp-commits mailing list