BUG: Bad Code for __fastcall Function Calling an Intrinsic

Last reviewed: July 22, 1997
Article ID: Q114875
1.00 1.50 WINDOWS kbtool kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE), included with: Microsoft Visual C++ for Windows, versions 1.0 and 1.5

SYMPTOMS

The compiler generates incorrect code to call a function that uses the register calling convention when one of the parameters to the function is the return value of another function. The register calling convention can be specified by using the __fastcall keyword or by compiling with the /Gr compiler switch. The generated code may crash or behave unpredictably.

CAUSE

The problem is triggered by the embedded function call being optimized to use an intrinsic form of the function. The code generated to pass the parameter to the __fastcall function is incorrect. The intrinsic form of functions are used when the /Oi compiler switch is used or when the function is specified as intrinsic by a #pragma intrinsic() statement.

RESOLUTION

To avoid the problem, do one of the following:

  • Use the /f compiler switch instead of the /f- compiler switch.

    -or-

  • Change the function from register calling convention to another calling convention.

    -or-

  • Force the compiler not to use an intrinsic form of the embedded function by using a #pragma function () statement.

STATUS

Microsoft has confirmed this to be a bug in C/C++ for MS-DOS versions 8.0, and 8.0c. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

This is not a problem in Microsoft C/C++ 32-bit compiler, version 8.0, included in Visual C++ 32-bit Edition, version 1.0.

Sample Code

/* Compile options needed: /f- /Oi /Gs
*/

// The program incorrectly prints 0, 1 instead of 0, 0.

#include <stdio.h>
#include <string.h>

// #pragma function (strcmp)

int __fastcall func (int nIndex)
{
    return nIndex;
}

int main (void)
{
    printf ("%d\n", (strcmp("free", "alloc") == 0) );
    printf ("%d\n", func(strcmp("free", "alloc") == 0) );
    return 0;
}


Additional reference words: 1.00 1.50 8.00 8.00c
KBCategory: kbtool kbbuglist
KBSubcategory: CodeGen
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.