All of lore.kernel.org
 help / color / mirror / Atom feed
* Potential issue with handling of va_arg()
@ 2017-03-31 13:47 Dibyendu Majumdar
  2017-03-31 14:06 ` Dibyendu Majumdar
  0 siblings, 1 reply; 5+ messages in thread
From: Dibyendu Majumdar @ 2017-03-31 13:47 UTC (permalink / raw)
  To: Linux-Sparse

Hi,

I am investigating a failure in this test:

#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>

void error_message(const char *fmt, ...) {
va_list argp;
va_start(argp, fmt);
vfprintf(stdout, fmt, argp);
va_end(argp);
}

int main(void)
{
error_message("%s\n", "hello world");
return 0;
}


The linearized output for error_message() is:

rror_message:
.L0:
<entry-point>
store.64    %arg1 -> 0[fmt]
cast.64     %r2 <- (64) fmt
load.64     %r3 <- 0[stdout]
call.32     %r6 <- vfprintf, %r3, %arg1, %r2
ret

Above seems incorrect to me, as %r2 should be pointing to [8]fmt presumably?

Thanks and Regards
Dibyendu

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

* Re: Potential issue with handling of va_arg()
  2017-03-31 13:47 Potential issue with handling of va_arg() Dibyendu Majumdar
@ 2017-03-31 14:06 ` Dibyendu Majumdar
  2017-03-31 14:34   ` Dibyendu Majumdar
  2017-03-31 18:55   ` Luc Van Oostenryck
  0 siblings, 2 replies; 5+ messages in thread
From: Dibyendu Majumdar @ 2017-03-31 14:06 UTC (permalink / raw)
  To: Linux-Sparse

Hi,

On 31 March 2017 at 14:47, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> I am investigating a failure in this test:
>
> #include <stdarg.h>
> #include <stdlib.h>
> #include <stdio.h>
>
> void error_message(const char *fmt, ...) {
> va_list argp;
> va_start(argp, fmt);
> vfprintf(stdout, fmt, argp);
> va_end(argp);
> }
>
> int main(void)
> {
> error_message("%s\n", "hello world");
> return 0;
> }
>
>
> The linearized output for error_message() is:
>
> rror_message:
> .L0:
> <entry-point>
> store.64    %arg1 -> 0[fmt]
> cast.64     %r2 <- (64) fmt
> load.64     %r3 <- 0[stdout]
> call.32     %r6 <- vfprintf, %r3, %arg1, %r2
> ret
>
> Above seems incorrect to me, as %r2 should be pointing to [8]fmt presumably?
>

I think this might be because the macro __builtin_va_start() is being
defined in sparse but this doesn't match what gets defined by gcc? I
see this in sparse:

#define __builtin_va_start(a,b) ((a) = (__builtin_va_list)(&(b)))

but if I run above code through gcc then preprocessed output says:

__builtin_va_start(argp, fmt);

Thanks and Regards
Dibyendu

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

* Re: Potential issue with handling of va_arg()
  2017-03-31 14:06 ` Dibyendu Majumdar
@ 2017-03-31 14:34   ` Dibyendu Majumdar
  2017-03-31 18:55   ` Luc Van Oostenryck
  1 sibling, 0 replies; 5+ messages in thread
From: Dibyendu Majumdar @ 2017-03-31 14:34 UTC (permalink / raw)
  To: Linux-Sparse

On 31 March 2017 at 15:06, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> On 31 March 2017 at 14:47, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
>> I am investigating a failure in this test:
>>
>> #include <stdarg.h>
>> #include <stdlib.h>
>> #include <stdio.h>
>>
>> void error_message(const char *fmt, ...) {
>> va_list argp;
>> va_start(argp, fmt);
>> vfprintf(stdout, fmt, argp);
>> va_end(argp);
>> }
>>
>> int main(void)
>> {
>> error_message("%s\n", "hello world");
>> return 0;
>> }
>>
>>
>> The linearized output for error_message() is:
>>
>> rror_message:
>> .L0:
>> <entry-point>
>> store.64    %arg1 -> 0[fmt]
>> cast.64     %r2 <- (64) fmt
>> load.64     %r3 <- 0[stdout]
>> call.32     %r6 <- vfprintf, %r3, %arg1, %r2
>> ret
>>
>> Above seems incorrect to me, as %r2 should be pointing to [8]fmt presumably?
>>
>
> I think this might be because the macro __builtin_va_start() is being
> defined in sparse but this doesn't match what gets defined by gcc? I
> see this in sparse:
>
> #define __builtin_va_start(a,b) ((a) = (__builtin_va_list)(&(b)))
>
> but if I run above code through gcc then preprocessed output says:
>
> __builtin_va_start(argp, fmt);
>

And it also seems that LLVM provides special instructions and
intrinsics for variable argument handling:

http://llvm.org/docs/LangRef.html#int-varargs

I don't know how to fix this issue as it appears that there is
OP_VAARG instruction in sparse but this is not implemented/output?

Thanks and Regards
Dibyendu

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

* Re: Potential issue with handling of va_arg()
  2017-03-31 14:06 ` Dibyendu Majumdar
  2017-03-31 14:34   ` Dibyendu Majumdar
@ 2017-03-31 18:55   ` Luc Van Oostenryck
  2017-04-01 12:56     ` Dibyendu Majumdar
  1 sibling, 1 reply; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-03-31 18:55 UTC (permalink / raw)
  To: Dibyendu Majumdar; +Cc: Linux-Sparse

On Fri, Mar 31, 2017 at 4:06 PM, Dibyendu Majumdar
<mobile@majumdar.org.uk> wrote:
> Hi,
>
> On 31 March 2017 at 14:47, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
>> I am investigating a failure in this test:
>>
>> #include <stdarg.h>
>> #include <stdlib.h>
>> #include <stdio.h>
>>
>> void error_message(const char *fmt, ...) {
>> va_list argp;
>> va_start(argp, fmt);
>
> I think this might be because the macro __builtin_va_start() is being
> defined in sparse but this doesn't match what gets defined by gcc? I
> see this in sparse:
>
> #define __builtin_va_start(a,b) ((a) = (__builtin_va_list)(&(b)))
>
> but if I run above code through gcc then preprocessed output says:
>
> __builtin_va_start(argp, fmt);
>

Current support for vaarg is more faked than anything else.
There is just the minimum needed to be able to do correct parsing
of code using it but there is nothing behind it.

-- Luc

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

* Re: Potential issue with handling of va_arg()
  2017-03-31 18:55   ` Luc Van Oostenryck
@ 2017-04-01 12:56     ` Dibyendu Majumdar
  0 siblings, 0 replies; 5+ messages in thread
From: Dibyendu Majumdar @ 2017-04-01 12:56 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Linux-Sparse

Hi Luc,

On 31 March 2017 at 19:55, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> On Fri, Mar 31, 2017 at 4:06 PM, Dibyendu Majumdar
> <mobile@majumdar.org.uk> wrote:
>> On 31 March 2017 at 14:47, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
>>> I am investigating a failure in this test:
>>>
>>> #include <stdarg.h>
>>> #include <stdlib.h>
>>> #include <stdio.h>
>>>
>>> void error_message(const char *fmt, ...) {
>>> va_list argp;
>>> va_start(argp, fmt);
>>
>> I think this might be because the macro __builtin_va_start() is being
>> defined in sparse but this doesn't match what gets defined by gcc? I
>> see this in sparse:
>>
>
> Current support for vaarg is more faked than anything else.
> There is just the minimum needed to be able to do correct parsing
> of code using it but there is nothing behind it.
>

Okay, I think a workaround for sparse-llvm is to disable generation of
the macros related to var arg processing - this will cause the
compilation to fail with undefined errors, rather than silently
generating bad code. I have done this in dmr_C where the relevant
macros are not defined when llvm backend is being used. I was
experiencing crashes with minilua due to this issue - I have reworked
minilua so that the functions that rely upon var arg processing are
moved to a separate source file which cannot be compiled with
sparse-llvm.

For my use case the var arg issue is not a pressing issue to fix, what
is more important is that bad code is never generated and the cases
not handled correctly are detected early and compilation fails.

Thanks and Regards
Dibyendu

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

end of thread, other threads:[~2017-04-01 12:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-31 13:47 Potential issue with handling of va_arg() Dibyendu Majumdar
2017-03-31 14:06 ` Dibyendu Majumdar
2017-03-31 14:34   ` Dibyendu Majumdar
2017-03-31 18:55   ` Luc Van Oostenryck
2017-04-01 12:56     ` 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.