Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1355 literal function pointer

closed-accepted
Maarten Brock
5
2013-05-25
2007-07-06
Anonymous
No

SDCC : mcs51 2.7.2 # (Jun 28 2007) (UNIX)
svn #4870

__xdata char baz;

void foo()
{
baz |= 5;
(*(void (*)()) 0) ();
}

compiled with sdcc -c produces an Internal error,

Internal error: validateOpType failed in
OP_SYM_TYPE(IC_LEFT(pl->ic)) @ peep\.c:226:
expected symbol, got value

----

thats in mcs51/pipe.c the function

static bool
isCallerSaveFunc (const lineNode *pl)
...
if (FUNC_CALLEESAVES(OP_SYM_TYPE(IC_LEFT(pl->ic))))
return FALSE;
...

gdb, print *pl, shows
print *pl
$4 = {
line = 0x81d87c0 "lcall\t#0x0000",
ic = 0x81d49c8,
isInline = 0,
isComment = 0,
isDebug = 0,
isLabel = 0,
visited = 1,
aln = 0x0,
prev = 0x81d84b8,
next = 0x81d87d8}

operand *left = IC_LEFT(pl->ic)
gdb, print *left, shows

$5 = {
type = VALUE,
isaddr = 0,
aggr2ptr = 0,
isvolatile = 0,
isGlobal = 0,
isPtr = 0,
isGptr = 0,
isParm = 0,
isLiteral = 1,
key = 0,
operand = {
symOperand = 0x81d5ae0,
valOperand = 0x81d5ae0,
typeOperand = 0x81d5ae0
},
usesDefs = 0x0,
aop = 0x0
}

it seems to me this function has to be extended
to allow a *literal*

another question which arises is,
how to express that a function pointer points
to a caller_save versus callee_save function.
is there something like
(void (__callee_save *)())
?

Robert Larice
larice 0x40 vidisys 0x2e de

Discussion

  • Logged In: NO

    the following patch seems to work around the stated problem.

    i've successfully run sdcc/support/regression

    but i've not succeeded to add a testcase for this bug.
    the regression mechanism seems not to accept sdcc crashes/error-exits as test failures.

    --- sdcc-4870/src/mcs51/peep.c 2007-06-28 11:16:33.000000000 +0200
    +++ sdcc-4870-gdb/src/mcs51/peep.c 2007-07-06 20:38:35.000000000 +0200
    @@ -221,10 +221,16 @@
    static bool
    isCallerSaveFunc (const lineNode *pl)
    {
    if (!isFunc (pl))
    return FALSE;
    + // lets assume calls to literally given locations are
    + // of type "CALLERSAVES"
    + // most notably : (*(void (*)()) 0) ();
    + // see bug 1749275
    + if(IS_OP_LITERAL(IC_LEFT(pl->ic)))
    + return TRUE;
    if (FUNC_CALLEESAVES(OP_SYM_TYPE(IC_LEFT(pl->ic))))
    return FALSE;
    if (FUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT(pl->ic))))
    return FALSE;
    return TRUE;

    Robert Larice
    larice 0x40 vidisys 0x2e de

     
  • Maarten Brock
    Maarten Brock
    2007-07-09

    Logged In: YES
    user_id=888171
    Originator: NO

    Robert,

    Do you have any particular reason not to log in to SourceForge? This would make life so much easier.

    A testcase for this bug is easy: a crash or error-exit of SDCC is also a way of failing the regression tests.

    Instead of assuming literals to be CALLERSAVES I think it's better to assume the default given to the compiler in options.all_callee_saves which can be set with --all-callee-saves.

    A function pointer that points to a callee-saves function should be created using a function pointer variable, IMO. But the code doesn't handle function pointers yet. Along with implementing your patch I'll add that too.

    Maarten

     
  • Maarten Brock
    Maarten Brock
    2007-07-09

    • labels: --> mcs51(8051) target
    • assigned_to: nobody --> maartenbrock
     
  • Maarten Brock
    Maarten Brock
    2007-07-09

    • milestone: --> fixed
    • status: open --> closed-accepted
     
  • Maarten Brock
    Maarten Brock
    2007-07-09

    Logged In: YES
    user_id=888171
    Originator: NO

    Applied with modifications in SDCC 2.7.2 #4876.