[Vm-dev] Another code-generation problem

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


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.
    self printHex: aContext.
    (self isMarriedOrWidowedContext: aContext)
        ifTrue: [(self checkIsStillMarriedContext: aContext currentFP:
                        [(self isMachineCodeFrame: (theFP := self
frameOfMarriedContext: aContext))
                            ifTrue: [self print: ' M (']
                            ifFalse: [self print: ' I ('].
                         self printHex: theFP asUnsignedInteger; print: ')
                        [self print: ' w ']]
... snip ...

is generated in spurstacksrc as:

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

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

            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
     failing within ceSend:to:numArgs: et al with an unbalanced stack."
    <var: #theFP type: #'char *'>
    <inline: true>

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