PREfast: Different outcome if compiled with or without?

Discussion in 'Windows Vista Drivers' started by Spiro Trikaliotis, Feb 18, 2005.

  1. Hello,

    I just had a somehow unexpected result: I compiled a driver which
    compiles perfectly ("build -cZ") with PREfast (driver specific rules),
    that is, "prefast build -cZ".

    Somehow, the compilation breaks if I use prefast. I tracked it down to
    the following statement:

    signal(SIGINT, reset);

    Somewhere else, there is the following function definition:

    static void ARCH_SIGNALDECL reset(int dummy)
    { ... }

    and, in some header file, there is:

    #ifdef WIN32
    #define ARCH_LINUX_WINDOWS( _linux, _windows) _windows
    #else
    #define ARCH_LINUX_WINDOWS( _linux, _windows) _linux
    #endif
    #define ARCH_SIGNALDECL ARCH_LINUX_WINDOWS(/* no decl needed */, __cdecl)


    Yes, I AM sure that this header file is included before. ARCH_SIGNALDECL
    is not defined anywhere else, but the compiler does not complain about
    ARCH_SIGNALDECL not defined, but about not being able to convert reset()
    from __stdcall to __cdecl.

    Now, if I replace

    static void ARCH_SIGNALDECL reset(int dummy)
    { ... }

    through

    static void __cdecl reset(int dummy)
    { ... }

    everything works fine.


    Well, the most interesting part is: If I do NOT use prefast, even the
    first version works perfectly. It works perfectly, too, if I replace

    #define ARCH_SIGNALDECL ARCH_LINUX_WINDOWS(__cdecl, __cdecl)

    Now, I ask myself what changes PREfast does to the compiler?

    I do not understand why this compiles perfectly without PREfast, but
    does not compile with PREfast.

    Ah, I forgot: This happens with PREfast 1.5.2402 (2K3 SP1 RC1 DDK,
    3790.1289), as well as with 2K3 DDK (3790) - in the latter case,
    obviously without the driver specific rules.

    Can anybody give me a good hint on what is going on?

    Regards,
    Spiro.
     
    Spiro Trikaliotis, Feb 18, 2005
    #1
    1. Advertisements

  2. Spiro Trikaliotis

    Ray Trent Guest

    What's the error message?

     
    Ray Trent, Feb 18, 2005
    #2
    1. Advertisements

  3. Hello,

    A good question. I totally forgot to mention that:

    main.c(19) : error C2440: 'function' : cannot convert from 'void
    (__stdcall *)(int)' to 'void (__cdecl *)(int)'

    I set up a small sample on
    http://www.trikaliotis.net/download/ddk-prob/prefast-problem.zip
    that shows the behaviour.

    Compiling with
    build -cefZ
    , it compiles perfectly.

    Running
    prefast build -cefZ
    , you get the above error message.

    Replacing

    #define ARCH_SIGNALDECL ARCH_LINUX_WINDOWS(__cdecl, __cdecl)

    in arch.h, the problem is gone, too.

    Does prefast make the compiler "forget" that it is running in WIN32?
    (just kidding)

    Regards,
    Spiro.
     
    Spiro Trikaliotis, Feb 19, 2005
    #3
  4. Spiro Trikaliotis

    Ray Trent Guest

    Hmmm. Don't see anything obvious unless it's a twitchy difference
    between the prefast compiler and the standard one (they aren't exactly
    the same compiler IIRC).

    Technically speaking, it's not legal to call a macro function and to
    fail to pass one of the parameters. Since comments are typically
    stripped before macros are expanded, your declaration of ARCH_SIGNALDECL
    (as, effectively, "ARCH_LINUX_WIN(,__cdecl)") may have undefined
    behavior. The spec is a bit unclear on this point, though, so I could be
    misreading it... Also, this may not apply to your actual situation...
     
    Ray Trent, Feb 22, 2005
    #4
  5. Hello Ray,

    Yes, I have thought about this, too. In fact, I changed my header to
    defined ARCH_SIGNALDECL with appropriate #ifdefs, and it works that way.

    I asked over at comp.lang.c if this should be legal C or not. Hopefully,
    they will be able to answer me this, so I know if it does make sense to
    send a bug report to MS or not. ;-)

    Regards,
    Spiro.
     
    Spiro Trikaliotis, Feb 24, 2005
    #5
  6. Hello again,

    This was easier to write than to do. Where can I send a bug report about
    PREfast to? I though I could send to , which is
    given in the PREfast documentation. Anyway, I got a


    SMTP error from remote mailer after RCPT TO:<>:
    host mailc.microsoft.com [207.46.121.52]: 550 5.1.1 User unknown

    Thus, where can I send a bug report to?

    Thanks,
    Spiro.
     
    Spiro Trikaliotis, Feb 28, 2005
    #6
  7. Eliyas Yakub [MSFT], Feb 28, 2005
    #7
  8. Hello Eliyas,

    Yes, that's what the error message told me, too. This is surprising as
    that mail address can be found inside the prefast documentation
    (Start/Programs/Development Kits/Windows DDK 3790.1289/Help/Prefast/Getting Started with Prefast.
    Ok, I've just done that. Thank you for your offer.

    Regards,
    Spiro.
     
    Spiro Trikaliotis, Mar 1, 2005
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.