All of lore.kernel.org
 help / color / mirror / Atom feed
* sparse-llvm incorrect handling of function pointers
@ 2017-03-10 14:23 Dibyendu Majumdar
  2017-03-10 17:44 ` Luc Van Oostenryck
  0 siblings, 1 reply; 8+ messages in thread
From: Dibyendu Majumdar @ 2017-03-10 14:23 UTC (permalink / raw)
  To: Linux-Sparse

Hi,

This example fails:

extern int (*f) (int);
int main(int argc, const char *argv[]) {
 if (f) {
  return (*f)(6);
 }
}

The linearized output is:

main:
.L0:
        <entry-point>
        load.64     %r1(f) <- 0[f]
        br          %r1(f), .L1, .L3
.L1:
        load        %r3 <- 0[%r1(f)]
        call.32     %r4 <- %r3, $6
        br          .L3
.L3:
        ret.32      %r4

It is the second load that is failing. Am investigating the cause - it
seems something to do with calc_memop_addr().

Regards
Dibyendu

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

* Re: sparse-llvm incorrect handling of function pointers
  2017-03-10 14:23 sparse-llvm incorrect handling of function pointers Dibyendu Majumdar
@ 2017-03-10 17:44 ` Luc Van Oostenryck
  2017-03-10 18:13   ` Dibyendu Majumdar
  0 siblings, 1 reply; 8+ messages in thread
From: Luc Van Oostenryck @ 2017-03-10 17:44 UTC (permalink / raw)
  To: Dibyendu Majumdar; +Cc: Linux-Sparse

On Fri, Mar 10, 2017 at 02:23:26PM +0000, Dibyendu Majumdar wrote:
> Hi,
> 
> This example fails:
> 
> extern int (*f) (int);
> int main(int argc, const char *argv[]) {
>  if (f) {
>   return (*f)(6);
>  }
> }
> 
> The linearized output is:
> 
> main:
> .L0:
>         <entry-point>
>         load.64     %r1(f) <- 0[f]
>         br          %r1(f), .L1, .L3
> .L1:
>         load        %r3 <- 0[%r1(f)]
>         call.32     %r4 <- %r3, $6
>         br          .L3
> .L3:
>         ret.32      %r4
> 
> It is the second load that is failing. Am investigating the cause - it
> seems something to do with calc_memop_addr().

No, it's a problem with the linearized code.
There is no reasons for this second load to even exist.
You can see this by replacing '(*f)(6)' by the equivalent 'f(6)'.

Also you should be careful with this example as there is no
return for the 'else' part which create some undefined value
which can create weirdness.

-- Luc Van Oostenryck

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

* Re: sparse-llvm incorrect handling of function pointers
  2017-03-10 17:44 ` Luc Van Oostenryck
@ 2017-03-10 18:13   ` Dibyendu Majumdar
  2017-03-11 11:54     ` Luc Van Oostenryck
  2017-03-11 11:58     ` [PATCH] llvm: add script to display the deserialized LLVM IR Luc Van Oostenryck
  0 siblings, 2 replies; 8+ messages in thread
From: Dibyendu Majumdar @ 2017-03-10 18:13 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Linux-Sparse

On 10 March 2017 at 17:44, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> On Fri, Mar 10, 2017 at 02:23:26PM +0000, Dibyendu Majumdar wrote:
>> Hi,
>>
>> This example fails:
>>
>> extern int (*f) (int);
>> int main(int argc, const char *argv[]) {
>>  if (f) {
>>   return (*f)(6);
>>  }
>> }
>>
>> The linearized output is:
>>
>> main:
>> .L0:
>>         <entry-point>
>>         load.64     %r1(f) <- 0[f]
>>         br          %r1(f), .L1, .L3
>> .L1:
>>         load        %r3 <- 0[%r1(f)]
>>         call.32     %r4 <- %r3, $6
>>         br          .L3
>> .L3:
>>         ret.32      %r4
>>
>> It is the second load that is failing. Am investigating the cause - it
>> seems something to do with calc_memop_addr().
>
> No, it's a problem with the linearized code.
> There is no reasons for this second load to even exist.
> You can see this by replacing '(*f)(6)' by the equivalent 'f(6)'.

Okay.

>
> Also you should be careful with this example as there is no
> return for the 'else' part which create some undefined value
> which can create weirdness.
>

Yes, here is an amended test.

static int testfunc(int i) {
 return i-6;
}
static int (*f) (int) = testfunc;
int main(int argc, const char *argv[]) {
 if (f) {
  return f(6);
 }
 else {
  return 1;
 }
}

I am creating a bunch of tests that can be run after compiling. The
current backend tests are not very useful as they do not actually run
or validate the results.

Regards
Dibyendu

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

* Re: sparse-llvm incorrect handling of function pointers
  2017-03-10 18:13   ` Dibyendu Majumdar
@ 2017-03-11 11:54     ` Luc Van Oostenryck
  2017-03-11 11:56       ` Dibyendu Majumdar
  2017-03-11 11:58     ` [PATCH] llvm: add script to display the deserialized LLVM IR Luc Van Oostenryck
  1 sibling, 1 reply; 8+ messages in thread
From: Luc Van Oostenryck @ 2017-03-11 11:54 UTC (permalink / raw)
  To: Dibyendu Majumdar; +Cc: Linux-Sparse

On Fri, Mar 10, 2017 at 06:13:16PM +0000, Dibyendu Majumdar wrote:
> Yes, here is an amended test.
> 
> static int testfunc(int i) {
>  return i-6;
> }
> static int (*f) (int) = testfunc;
> int main(int argc, const char *argv[]) {
>  if (f) {
>   return f(6);
>  }
>  else {
>   return 1;
>  }
> }

This one is because of the static initialization.

> I am creating a bunch of tests that can be run after compiling.

Excellent, they are really needed.

> The current backend tests are not very useful as they do not actually run
> or validate the results.

Yes, indeed.

-- Luc Van Oostenryck

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

* Re: sparse-llvm incorrect handling of function pointers
  2017-03-11 11:54     ` Luc Van Oostenryck
@ 2017-03-11 11:56       ` Dibyendu Majumdar
  0 siblings, 0 replies; 8+ messages in thread
From: Dibyendu Majumdar @ 2017-03-11 11:56 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Linux-Sparse

On 11 March 2017 at 11:54, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> On Fri, Mar 10, 2017 at 06:13:16PM +0000, Dibyendu Majumdar wrote:
>> Yes, here is an amended test.
>>
>> static int testfunc(int i) {
>>  return i-6;
>> }
>> static int (*f) (int) = testfunc;
>> int main(int argc, const char *argv[]) {
>>  if (f) {
>>   return f(6);
>>  }
>>  else {
>>   return 1;
>>  }
>> }
>
> This one is because of the static initialization.
>

Yes, this works now:

static int testfunc(int i) {
 return i-6;
}
/* initialiser does not work */
/* static int (*f) (int) = testfunc */
static int (*f) (int);
int main(int argc, const char *argv[]) {
 f = testfunc;
 if (f) {
  return f(6);
 }
 else {
  return 1;
 }
}

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

* [PATCH] llvm: add script to display the deserialized LLVM IR
  2017-03-10 18:13   ` Dibyendu Majumdar
  2017-03-11 11:54     ` Luc Van Oostenryck
@ 2017-03-11 11:58     ` Luc Van Oostenryck
  2017-04-25 20:43       ` Christopher Li
  1 sibling, 1 reply; 8+ messages in thread
From: Luc Van Oostenryck @ 2017-03-11 11:58 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Dibyendu Majumdar, Luc Van Oostenryck

The goal is to use this in some of test cases, by comparing
the expected output with the actual one.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 sparse-llvm-dis | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100755 sparse-llvm-dis

diff --git a/sparse-llvm-dis b/sparse-llvm-dis
new file mode 100755
index 000000000..573f8bbd0
--- /dev/null
+++ b/sparse-llvm-dis
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set +e
+
+DIRNAME=`dirname $0`
+DIS=`"${LLVM_CONFIG:-llvm-config}" --bindir`/llvm-dis
+
+if [ $# -eq 0 ]; then
+  echo "`basename $0`: no input files"
+  exit 1
+fi
+
+$DIRNAME/sparse-llvm $@ | $DIS
-- 
2.11.1


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

* Re: [PATCH] llvm: add script to display the deserialized LLVM IR
  2017-03-11 11:58     ` [PATCH] llvm: add script to display the deserialized LLVM IR Luc Van Oostenryck
@ 2017-04-25 20:43       ` Christopher Li
  2017-04-26  2:11         ` Luc Van Oostenryck
  0 siblings, 1 reply; 8+ messages in thread
From: Christopher Li @ 2017-04-25 20:43 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Linux-Sparse, Dibyendu Majumdar

On Sat, Mar 11, 2017 at 7:58 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> The goal is to use this in some of test cases, by comparing
> the expected output with the actual one.
>
> diff --git a/sparse-llvm-dis b/sparse-llvm-dis
> new file mode 100755
> index 000000000..573f8bbd0
> --- /dev/null
> +++ b/sparse-llvm-dis
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +set +e
> +
> +DIRNAME=`dirname $0`
> +DIS=`"${LLVM_CONFIG:-llvm-config}" --bindir`/llvm-dis
> +
> +if [ $# -eq 0 ]; then
> +  echo "`basename $0`: no input files"
> +  exit 1
> +fi
> +
> +$DIRNAME/sparse-llvm $@ | $DIS

Looks good. You might want to check llvm-dis and sparse-llvm is
there. I assume this script will not be invoked if llvm is not there
so it is not a big deal.

Chris

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

* Re: [PATCH] llvm: add script to display the deserialized LLVM IR
  2017-04-25 20:43       ` Christopher Li
@ 2017-04-26  2:11         ` Luc Van Oostenryck
  0 siblings, 0 replies; 8+ messages in thread
From: Luc Van Oostenryck @ 2017-04-26  2:11 UTC (permalink / raw)
  To: Christopher Li; +Cc: Linux-Sparse, Dibyendu Majumdar

On Tue, Apr 25, 2017 at 10:43 PM, Christopher Li <sparse@chrisli.org> wrote:
> On Sat, Mar 11, 2017 at 7:58 PM, Luc Van Oostenryck
> <luc.vanoostenryck@gmail.com> wrote:
>> The goal is to use this in some of test cases, by comparing
>> the expected output with the actual one.
>>
>
> Looks good. You might want to check llvm-dis and sparse-llvm is
> there. I assume this script will not be invoked if llvm is not there
> so it is not a big deal.
>
> Chris

Yes, it need sparse-llvm anyway.

OTOH, there is no users for this script so it can kept on hold too.

-- Luc

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

end of thread, other threads:[~2017-04-26  2:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-10 14:23 sparse-llvm incorrect handling of function pointers Dibyendu Majumdar
2017-03-10 17:44 ` Luc Van Oostenryck
2017-03-10 18:13   ` Dibyendu Majumdar
2017-03-11 11:54     ` Luc Van Oostenryck
2017-03-11 11:56       ` Dibyendu Majumdar
2017-03-11 11:58     ` [PATCH] llvm: add script to display the deserialized LLVM IR Luc Van Oostenryck
2017-04-25 20:43       ` Christopher Li
2017-04-26  2:11         ` Luc Van Oostenryck

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.