linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dibyendu Majumdar <mobile@majumdar.org.uk>
To: Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Possible incorrect linearization of code (master branch)
Date: Mon, 6 Mar 2017 15:22:19 +0000	[thread overview]
Message-ID: <CACXZuxeNopu3Syg+TCL3TLnhwmA84qkQ1NsN4hjL-VLPi6ASYA@mail.gmail.com> (raw)

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

             reply	other threads:[~2017-03-06 15:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-06 15:22 Dibyendu Majumdar [this message]
2017-03-06 16:36 ` Possible incorrect linearization of code (master branch) 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACXZuxeNopu3Syg+TCL3TLnhwmA84qkQ1NsN4hjL-VLPi6ASYA@mail.gmail.com \
    --to=mobile@majumdar.org.uk \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).