All of lore.kernel.org
 help / color / mirror / Atom feed
* Possible incorrect linearization of code (master branch)
@ 2017-03-06 15:22 Dibyendu Majumdar
  2017-03-06 16:36 ` Luc Van Oostenryck
  0 siblings, 1 reply; 8+ messages in thread
From: Dibyendu Majumdar @ 2017-03-06 15:22 UTC (permalink / raw)
  To: Linux-Sparse

Hi,

I have this test program:

extern char *incr(char *p);
char *incr(char *p) {
 char *tmp = p;
 tmp += 5;
 return tmp;
}
int main(const char *argv[]) {
 char *text =  "abcde";
 char *p = incr(text);
 return (*p == 'e') ? 0 : 1;
}

The linearizer outputs following which I think is incorrect as it is
missing a load.

incr:
.L0:
        <entry-point>
        cast.64     %r3 <- (64) %arg1
        add.64      %r4 <- %r3, $5
        ptrcast.64  %r5 <- (64) %r4
        ret.64      %r5

main:
.L2:
        <entry-point>
        call.64     %r10 <- incr, "abcde"
        setne.32    %r15 <- %r13, $101
        ret.32      %r15

If I change the return in main to be a if else block then correct code
is generated.

int main(const char *argv[]) {
 char *text =  "abcde";
 char *p = incr(text);
 // return (*p == 'e') ? 0 : 1;
 if (*p == 'e')
  return 0;
 else
  return 1;
}

main:
.L2:
        <entry-point>
        call.64     %r10 <- incr, "abcde"
        load.8      %r12 <- 0[%r10]
        scast.32    %r13 <- (8) %r12
        setne.32    %r15 <- %r13, $101
        ret.32      %r15

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-03-07 17:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-06 15:22 Possible incorrect linearization of code (master branch) Dibyendu Majumdar
2017-03-06 16:36 ` Luc Van Oostenryck
2017-03-06 18:47   ` Dibyendu Majumdar
2017-03-06 19:26     ` Luc Van Oostenryck
2017-03-06 22:39       ` Dibyendu Majumdar
2017-03-07  6:42         ` Luc Van Oostenryck
2017-03-07 15:45         ` Christopher Li
2017-03-07 17:13           ` Dibyendu Majumdar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.