[Vm-dev] Another code-generation problem

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Fri Nov 11 17:01:34 UTC 2016


Hi,

The following slang:

shortPrintContext: aContext
    | theFP |
    <inline: false>
    <var: #theFP type: #'char *'>
    (objectMemory isContext: aContext) ifFalse:
        [self printHex: aContext; print: ' is not a context'; cr.
        ^nil].
    self printHex: aContext.
    (self isMarriedOrWidowedContext: aContext)
        ifTrue: [(self checkIsStillMarriedContext: aContext currentFP:
framePointer)
                    ifTrue:
                        [(self isMachineCodeFrame: (theFP := self
frameOfMarriedContext: aContext))
                            ifTrue: [self print: ' M (']
                            ifFalse: [self print: ' I ('].
                         self printHex: theFP asUnsignedInteger; print: ')
']
                    ifFalse:
                        [self print: ' w ']]
... snip ...

is generated in spurstacksrc as:

shortPrintContext(sqInt aContext)
{   DECL_MAYBE_SQ_GLOBAL_STRUCT
    sqInt home;
    char *theFP;

    if (!(((aContext & (tagMask())) == 0)
         && (((longAt(aContext)) & (classIndexMask())) ==
ClassMethodContextCompactIndex))) {
        printHex(aContext);
        print(" is not a context");
        /* begin cr */
        printf("\n");
        return null;
    }
    printHex(aContext);
    if (((longAt((aContext + BaseHeaderSize) +
(((int)((usqInt)(SenderIndex) << (shiftForWord())))))) & 1)) {
        if (checkIsStillMarriedContextcurrentFP(aContext,
GIV(framePointer))) {
            print(" I (");

            printHex(((usqInt)theFP));
            print(") ");
        }
        else {
            print(" w ");
        }
    }
... snip ...

It has a problem:

opensmalltalk-vm\spurstacksrc\vm\interp.c(59772): warning C4700:
uninitialized local variable 'theFP' used

This is because the inliner cleverly eliminated a branch, thanks to allways
false condition in stack flavour:

isMachineCodeFrame: theFP
    "For compatibility with CoInterpreter.  Needed to avoid
slowPrimitiveResponse
     failing within ceSend:to:numArgs: et al with an unbalanced stack."
    <var: #theFP type: #'char *'>
    <inline: true>
    ^false

Great... Except that eliminated code had a side effect of setting theFP...

For now I will patch the slang, but it would be good to fix the inliner (at
least check for side effects before eliminating).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20161111/ddae230c/attachment.html>


More information about the Vm-dev mailing list