[Compiler-rt][PATCH] Fix MSVC compilation of lib/profile/InstrProfData.inc

Johan Engelen via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 20 04:08:19 PST 2015


On Sat, Dec 19, 2015 at 8:00 PM, Xinliang David Li <davidxl at google.com>
wrote:

> On Sat, Dec 19, 2015 at 10:27 AM, Johan Engelen <jbc.engelen at gmail.com>
> wrote:
> >
> > 2. COMPILER_RT_HAS_ATOMICS should not be 1 for MSVC. Unfortunately, MSVC
> > does not have a drop-in replacement for GCC's
> __sync_bool_compare_and_swap,
> > and so a fix is non-trivial.
>
> How about InterlockedCompareExchange?
>

I think something like this might work, but I'm not sure.
InterlockedCompareExchange is not overloaded for different types, like
__sync_bool_compare_and_swap is.

template <typename T>
bool BoolCmpXchg(T *Ptr, T OldV, T NewV) {
  T origval;
  if (sizeof(T) == 8)
     origval = InterlockedCompareExchange64(Ptr, NewV, OldV);
  else if (sizeof(T) == 4)
     origval = InterlockedCompareExchange(Ptr, NewV, OldV);
  else if (sizeof(T) == 2)
     origval = InterlockedCompareExchange16(Ptr, NewV, OldV);
  else
     assert(0);
  return origval == OldV
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151220/6ff588c0/attachment.html>


More information about the llvm-commits mailing list