#2131 MemoryBarrier() crashes when older than VISTA

WSL
open
Earnie Boyd
None
Support
none
Unknown
True
2015-01-25
2013-11-09
Carlo Bramini
No

The MemoryBarrier() macro crashes the compilation when _WIN32_WINNT is less than _WIN32_WINNT_VISTA.
If you try to compile this source:

#undef _WIN32_WINNT
#define _WIN32_WINNT 0x501 // XP
#include <windows.h>

int main()
{
    MemoryBarrier();

    return 0;
}

the preprocessor will translate it to:

int main()
{
    ();

    return 0;
}

because the macro is declared without parentheses and the compiler returns:

c.c: In function 'main':
c.c:7:19: error: expected expression before ')' token
  MemoryBarrier();
                ^

Bug discovered when compiling FFMPEG.
Attached patch fixes this bug.

Sincerely,

Carlo Bramini.

Discussion

  • Carlo Bramini
    Carlo Bramini
    2013-11-09

    The patch.

     
    Attachments
  • Earnie Boyd
    Earnie Boyd
    2013-11-09

    • status: unread --> closed
    • Type: Bug --> Support
    • Resolution: none --> invalid
    • Category: Feature_in_WSL_4.1 --> Behaves_as_Documented
     
  • Earnie Boyd
    Earnie Boyd
    2013-11-09

    MemoryBarrier isn't supported in XP. Therefore the outcome is as documented.

     
  • Carlo Bramini
    Carlo Bramini
    2013-11-10

    From this page:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208%28v=vs.85%29.aspx

    the text says:
    "This macro can be called on all processor platforms where Windows is supported, but it has no effect on some platforms".

    Apparently, what I am understanding is that you can call that macro even on older platforms, without causing a crash in the compilation... it has simply no effect, like an empty macro would do. If the intention is to raise an error at compile time, perhaps it would be even better to remove directly its declaration for older platforms, so that the compiler will complain a message "MemoryBarrier: undefined identifier" or something like that, no?

    Sincerely,

    Carlo Bramini.

     
  • Keith Marshall
    Keith Marshall
    2013-11-10

    • status: closed --> open
    • assigned_to: Earnie Boyd
    • Resolution: invalid --> none
    • Category: Behaves_as_Documented --> Unknown
     
  • Keith Marshall
    Keith Marshall
    2013-11-10

    "All processor platform's where Windows is supported" is not the same as "all versions of Windows"; the reference is unequivocal: this macro is not supported on WinXP, and should not be defined when you set your _WIN32_WINNT compatibility level to anything less than 0x600. However, the outcome you report does not seem correct, (and is certainly not "as documented"); correct outcome would be that you are notified of a "MemoryBarrier not defined in this scope" error (in C++), or an undefined reference to _MemoryBarrier, at link time, where the C compiler generates a default prototype.

    I'm reopening this; it is inappropriate to simply declare it as "invalid". The definition of MemoryBarrier() should be conditional on a _WIN32_WINNT >= 0x600 guard.

     
  • ebraminio
    ebraminio
    2014-07-18

    So if _WIN32_WINNT is not defined isn't better to not defining MemoryBarrier?
    #if WIN32_WINNT >= _WIN32_WINNT_VISTA
    # if defined(_AMD64
    ) || defined(X86_64)
    # define MemoryBarrier
    faststorefence

    # elif defined(IA64)

    # define MemoryBarrier mf
    # else


    void
    mingworg_MemoryBarrier(void);
    # define MemoryBarrier __mingworg_MemoryBarrier
    # endif

    #else

    # define MemoryBarrier <-- Hmm?
    #endif

    This bug caused a compilation error https://github.com/behdad/harfbuzz/commit/fbb2847f541389f40718af71c4945024ae177ab2

     
    Last edit: ebraminio 2014-07-18