Path: utzoo!mnetor!uunet!mosys!nortond From: nortond@mosys.UUCP (Daniel A. Norton) Newsgroups: comp.sys.ibm.pc Subject: MSC 5.0 Intrinsic Bug Message-ID: <211@mosys.UUCP> Date: 21 Dec 87 21:03:14 GMT Expires: 31 Jan 88 05:00:00 GMT Reply-To: nortond@mosys.UUCP (Daniel A. Norton) Organization: Momentum Systems Corp., Cherry Hill, NJ Lines: 123 Summary: strlen() intrinsic fails in LARGE model Copyright (c) 1987, Daniel A. Norton. All Rights Reserved. You are hereby granted free and unlimited use of this article with the exception that neither Microsoft Corporation nor any of its employees or subsidiaries may copy this article beyond that which is automatically provided by USENET and USENET software. Such copying includes, but is not restricted to printing, archiving, xerography, and manual transcription. PRODUCT: MSC 5.0 OPTIMIZING COMPILER SYMPTOMS: Use of intrinsic function strlen() in large data model (/AH, /AL or /AC) results in data loss. If the intrinsic function strlen() is called to return the length of a string represented by an auto-storage or static-storage pointer, and the result is returned into an external or public variable, incorrect code is generated, resulting in loss of data. The error does not appear in the small or medium model. The error does not appear if the variable holding the returned value is in static or auto storage. The error does not appear if the string is a static array (as opposed to a static pointer). The error does not appear if the string is an external or public array or is is accessed through an external or public pointer. WORKAROUND: In source code which has the described characteristics, insert the line: #pragma function(strlen) This statement suppresses the intrinsic and forces the library function _strlen to be invoked instead. REPRODUCING THE PROBLEM: EXAMPLE SOURCE: #include extern int extvar; void dummyproc(arg) char *arg; { extvar = strlen(arg); } COMPILER INVOCATION: cl -c -AL -Oi -Fa bug2.c ASSEMBLY OUTPUT: ; Static Name Aliases ; TITLE bug2.c NAME bug2 .8087 BUG2_TEXT SEGMENT WORD PUBLIC 'CODE' BUG2_TEXT ENDS _DATA SEGMENT WORD PUBLIC 'DATA' _DATA ENDS CONST SEGMENT WORD PUBLIC 'CONST' CONST ENDS _BSS SEGMENT WORD PUBLIC 'BSS' _BSS ENDS DGROUP GROUP CONST, _BSS, _DATA ASSUME CS: BUG2_TEXT, DS: DGROUP, SS: DGROUP EXTRN __acrtused:ABS EXTRN __chkstk:FAR COMM FAR _extvar: BYTE: 2 CONST SEGMENT $T20001 DW SEG _extvar CONST ENDS BUG2_TEXT SEGMENT ASSUME CS: BUG2_TEXT ; Line 6 PUBLIC _dummyproc _dummyproc PROC FAR push bp mov bp,sp xor ax,ax call FAR PTR __chkstk push di ; Line 7 ; arg = 6 ; Line 8 mov es,$T20001 ; *** DISCARDED les di,DWORD PTR [bp+6] ;arg mov cx,-1 xor ax,ax repnz scasb not cx dec cx mov WORD PTR es:_extvar,cx ; *** INVALID ; Line 9 pop di pop bp ret _dummyproc ENDP BUG2_TEXT ENDS END -- Daniel A. Norton nortond@mosys.UUCP c/o Momentum Systems Corporation ...uunet!mosys!nortond 2 Keystone Avenue Cherry Hill, NJ 08003 609/424-0734