* Handle __builtin_ms_va_list.
@ 2009-09-30 21:34 Michael Stefaniuc
2009-10-01 18:41 ` Christopher Li
0 siblings, 1 reply; 11+ messages in thread
From: Michael Stefaniuc @ 2009-09-30 21:34 UTC (permalink / raw)
To: linux-sparse
For Win64 compiles Wine does
#ifndef __ms_va_list
# if defined(__x86_64__) && defined (__GNUC__)
# define __ms_va_list __builtin_ms_va_list
# define __ms_va_start(list,arg) __builtin_ms_va_start(list,arg)
# define __ms_va_end(list) __builtin_ms_va_end(list)
# else
Wouldn't be as bad if sparse cannot handle those but it trips over
WINBASEAPI DWORD WINAPI FormatMessageA(DWORD,LPCVOID,DWORD,DWORD,LPSTR,DWORD,__ms_va_list*);
WINBASEAPI DWORD WINAPI FormatMessageW(DWORD,LPCVOID,DWORD,DWORD,LPWSTR,DWORD,__ms_va_list*);
producing this errors for basically every file:
wine/include/winbase.h:1546:96: error: Expected ) in function declarator
wine/include/winbase.h:1546:96: error: got *
wine/include/winbase.h:1547:97: error: Expected ) in function declarator
wine/include/winbase.h:1547:97: error: got *
Signed-off-by: Michael Stefaniuc <mstefaniuc@gmail.com>
---
lib.c | 2 ++
parse.c | 1 +
2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/lib.c b/lib.c
index 622b547..cf00c8b 100644
--- a/lib.c
+++ b/lib.c
@@ -794,11 +794,13 @@ void create_builtin_stream(void)
add_pre_buffer("#define __builtin_stdarg_start(a,b) ((a) = (__builtin_va_list)(&(b)))\n");
add_pre_buffer("#define __builtin_va_start(a,b) ((a) = (__builtin_va_list)(&(b)))\n");
+ add_pre_buffer("#define __builtin_ms_va_start(a,b) ((a) = (__builtin_ms_va_list)(&(b)))\n");
add_pre_buffer("#define __builtin_va_arg(arg,type) ({ type __va_arg_ret = *(type *)(arg); arg += sizeof(type); __va_arg_ret; })\n");
add_pre_buffer("#define __builtin_va_alist (*(void *)0)\n");
add_pre_buffer("#define __builtin_va_arg_incr(x) ((x) + 1)\n");
add_pre_buffer("#define __builtin_va_copy(dest, src) ({ dest = src; (void)0; })\n");
add_pre_buffer("#define __builtin_va_end(arg)\n");
+ add_pre_buffer("#define __builtin_ms_va_end(arg)\n");
/* FIXME! We need to do these as special magic macros at expansion time! */
add_pre_buffer("#define __BASE_FILE__ \"base_file.c\"\n");
diff --git a/parse.c b/parse.c
index c3f9b6a..6ab2ac4 100644
--- a/parse.c
+++ b/parse.c
@@ -391,6 +391,7 @@ static struct init_keyword {
/* Predeclared types */
{ "__builtin_va_list", NS_TYPEDEF, .type = &ptr_ctype, .op = &spec_op },
+ { "__builtin_ms_va_list", NS_TYPEDEF, .type = &ptr_ctype, .op = &spec_op },
{ "__int128_t", NS_TYPEDEF, .type = &lllong_ctype, .op = &spec_op },
{ "__uint128_t",NS_TYPEDEF, .type = &ulllong_ctype, .op = &spec_op },
--
1.6.5.rc2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: Handle __builtin_ms_va_list.
2009-09-30 21:34 Handle __builtin_ms_va_list Michael Stefaniuc
@ 2009-10-01 18:41 ` Christopher Li
2009-11-25 14:15 ` Getting info from used typedef Thomas Schmid
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Li @ 2009-10-01 18:41 UTC (permalink / raw)
To: Michael Stefaniuc; +Cc: linux-sparse
On Wed, Sep 30, 2009 at 2:34 PM, Michael Stefaniuc <mstefani@redhat.com> wrote:
> For Win64 compiles Wine does
> #ifndef __ms_va_list
> # if defined(__x86_64__) && defined (__GNUC__)
> # define __ms_va_list __builtin_ms_va_list
> # define __ms_va_start(list,arg) __builtin_ms_va_start(list,arg)
> # define __ms_va_end(list) __builtin_ms_va_end(list)
> # else
>
> Wouldn't be as bad if sparse cannot handle those but it trips over
> WINBASEAPI DWORD WINAPI FormatMessageA(DWORD,LPCVOID,DWORD,DWORD,LPSTR,DWORD,__ms_va_list*);
> WINBASEAPI DWORD WINAPI FormatMessageW(DWORD,LPCVOID,DWORD,DWORD,LPWSTR,DWORD,__ms_va_list*);
> producing this errors for basically every file:
> wine/include/winbase.h:1546:96: error: Expected ) in function declarator
> wine/include/winbase.h:1546:96: error: got *
> wine/include/winbase.h:1547:97: error: Expected ) in function declarator
> wine/include/winbase.h:1547:97: error: got *
Applied.
Thanks
Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Getting info from used typedef
2009-10-01 18:41 ` Christopher Li
@ 2009-11-25 14:15 ` Thomas Schmid
2009-11-30 23:41 ` Christopher Li
0 siblings, 1 reply; 11+ messages in thread
From: Thomas Schmid @ 2009-11-25 14:15 UTC (permalink / raw)
To: Christopher Li; +Cc: linux-sparse, linux-sparse-owner
Hello,
I try to get information about a typedef, which was used in a declaration.
For example:
typedef signed short INT;
INT var1;
When i iterate over the symbol_list which is returend by sparse(), I can
get the information,
that "var1" was declared using a typedef, this information is held in
"symbol->ctype.modifiers".
Can you tell me how I can examine the name of the typedef - "INT", which
was used in the declaration?
I'm only able to get the name of the basic datatype, which is "signed
short" in this case.
This behaviour has changed in 0.4.2, in former versions the name of a used
typedef was stored in the used datatypes ident
(altough the behaviour was erroneous there).
Thanks in advance,
regards,
Thomas
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Getting info from used typedef
2009-11-25 14:15 ` Getting info from used typedef Thomas Schmid
@ 2009-11-30 23:41 ` Christopher Li
2009-12-01 12:30 ` Antwort: " Thomas Schmid
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Li @ 2009-11-30 23:41 UTC (permalink / raw)
To: Thomas Schmid; +Cc: linux-sparse
On Wed, Nov 25, 2009 at 6:15 AM, Thomas Schmid
<Thomas.Schmid@br-automation.com> wrote:
> typedef signed short INT;
> INT var1;
>
> When i iterate over the symbol_list which is returend by sparse(), I can
> get the information,
> that "var1" was declared using a typedef, this information is held in
> "symbol->ctype.modifiers".
So far so good.
> Can you tell me how I can examine the name of the typedef - "INT", which
> was used in the declaration?
I take a look at the current code base, there is no good way to get the
typedef from the symbol node. When sparse parse the "INT" token.
It will try to lookup it as type define. If it is, sparse directly
apply the underlying
ctype, which is "signed short", to var1.
The code does that is in declaration_specifiers() if you are curious.
Sparse only use the base type of the user type, as if the declaration
is "signed short var1". This make the later process much easier.
It is none trivial change to preserve the type define name.
May I ask more back ground information what do you want to do
with the type define name? I am trying to find out if there is other easier
way to achieve your goal.
Chris
^ permalink raw reply [flat|nested] 11+ messages in thread
* Antwort: Re: Getting info from used typedef
2009-11-30 23:41 ` Christopher Li
@ 2009-12-01 12:30 ` Thomas Schmid
2009-12-01 18:49 ` Christopher Li
0 siblings, 1 reply; 11+ messages in thread
From: Thomas Schmid @ 2009-12-01 12:30 UTC (permalink / raw)
To: Christopher Li; +Cc: christ.li, linux-sparse
christ.li@gmail.com schrieb am 01.12.2009 00:41:18:
> The code does that is in declaration_specifiers() if you are curious.
> Sparse only use the base type of the user type, as if the declaration
> is "signed short var1". This make the later process much easier.
> It is none trivial change to preserve the type define name.
I see.
> May I ask more back ground information what do you want to do
> with the type define name? I am trying to find out if there is other
easier
> way to achieve your goal.
Of course: I wrote a tool, which converts C-declarations into another
format (IEC61131).
These generated declarations are used as a interface to communicate to
programs of different languages.
This IEC-format uses datatypes, which are not known in ANSI C, such as the
following:
typedef signed long DINT;
typedef unsigned long UDINT;
typedef signed long TIME;
typedef unsigned long DATE_AND_TIME;
typedef unsigned short UINT;
typedef unsigned short WSTRING;
As you can see, the use of the basetype "unsigned long" for example is not
clear.
If I now declare a variable of type TIME and another one of type DINT,
I am not able to determine which type was used in the declaration.
I hope this is understandable,
regards,
Thomas
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Re: Getting info from used typedef
2009-12-01 12:30 ` Antwort: " Thomas Schmid
@ 2009-12-01 18:49 ` Christopher Li
2009-12-02 14:05 ` Thomas Schmid
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Li @ 2009-12-01 18:49 UTC (permalink / raw)
To: Thomas Schmid; +Cc: linux-sparse
[-- Attachment #1: Type: text/plain, Size: 907 bytes --]
On Tue, Dec 1, 2009 at 4:30 AM, Thomas Schmid
<Thomas.Schmid@br-automation.com> wrote:
> Of course: I wrote a tool, which converts C-declarations into another
> format (IEC61131).
> These generated declarations are used as a interface to communicate to
> programs of different languages.
> This IEC-format uses datatypes, which are not known in ANSI C, such as the
> following:
>
> typedef signed long DINT;
> typedef unsigned long UDINT;
> typedef signed long TIME;
> typedef unsigned long DATE_AND_TIME;
> typedef unsigned short UINT;
> typedef unsigned short WSTRING;
>
So you only use sparse as a C source code processing tool. You don't
care about the back end part of the sparse right?
In that case, you can try this one line patch. It should preserve the typedef
symbol as the base type. I will not commit that to main line though.
Will that work for you?
Chris
[-- Attachment #2: 0001-hacking-preserve-typedef-name.patch --]
[-- Type: application/octet-stream, Size: 710 bytes --]
From 6f1a577af7d9fa23c9070f278bdab02dbf8fb068 Mon Sep 17 00:00:00 2001
From: Christopher Li <sparse@chrisli.org>
Date: Tue, 1 Dec 2009 10:38:02 -0800
Subject: [PATCH] hacking preserve typedef name.
---
parse.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/parse.c b/parse.c
index 66b8112..249135b 100644
--- a/parse.c
+++ b/parse.c
@@ -1429,7 +1429,7 @@ static struct token *declaration_specifiers(struct token *token, struct decl_sta
if (seen & Set_Any)
break;
seen |= Set_S | Set_T;
- ctx->ctype.base_type = s->ctype.base_type;
+ ctx->ctype.base_type = s;
apply_ctype(token->pos, &s->ctype, &ctx->ctype);
token = token->next;
continue;
--
1.6.0.6
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: Re: Re: Getting info from used typedef
2009-12-01 18:49 ` Christopher Li
@ 2009-12-02 14:05 ` Thomas Schmid
2010-01-21 0:38 ` Christopher Li
0 siblings, 1 reply; 11+ messages in thread
From: Thomas Schmid @ 2009-12-02 14:05 UTC (permalink / raw)
To: Christopher Li; +Cc: christ.li, linux-sparse
christ.li@gmail.com schrieb am 01.12.2009 19:49:18:
> So you only use sparse as a C source code processing tool. You don't
> care about the back end part of the sparse right?
Yes, that's right.
> In that case, you can try this one line patch. It should preserve the
typedef
> symbol as the base type. I will not commit that to main line though.
>
> Will that work for you?
Thank you, but I'm sorry, that patch doesn't work for me.
The output is the same as before, the base_type of the symbol doesn't have
an ident.
I'm surprised that the base_type had an ident in former versions of sparse
(which didn't also work correctly - I tried to figure out something in the
past, see
http://marc.info/?l=linux-sparse&m=118171213001092&w=2
), but now this has changed.
In former versions of sparse, this code gave output, even tough it was
incorrect:
("sym" is a "struct symbol*" of the symlist returned by sparse() )
struct symbol *type;
type = sym->ctype.base_type;
if (type->ident)
{
if (sym->ctype.modifiers & MOD_USERTYPE)
fprintf(pFOut, "Typedef=\"%s\" ",
type->ident->name);
}
I tried to compare the function "declaration_specifiers" from sparse 0.4.1
and 0.4.2.
The function changed a lot, but I don't understand the changes.
Is it really not necessary for compilers (or frontends) to hold the
information about declarations with typedefs?
Regards,
Thomas
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Re: Re: Getting info from used typedef
2009-12-02 14:05 ` Thomas Schmid
@ 2010-01-21 0:38 ` Christopher Li
2010-01-26 15:28 ` Thomas Schmid
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Li @ 2010-01-21 0:38 UTC (permalink / raw)
To: Thomas Schmid; +Cc: linux-sparse
On Wed, Dec 2, 2009 at 6:05 AM, Thomas Schmid
<Thomas.Schmid@br-automation.com> wrote:
>
> Thank you, but I'm sorry, that patch doesn't work for me.
I took another look into it. I think if you are just working on the
source code transform,
you should be able to skip the evaluation step which short cut the typedef.
Can you try again with the same patch, but in your program, using
__sparse(filename)
instead of sparse(filename) to get the symbols? Using __sparse will skip the
evaluation step. It should keep the typedef node unchanged.
> Is it really not necessary for compilers (or frontends) to hold the
> information about declarations with typedefs?
The back end only care about the type, not the name of type.
In fact, C type system need to evaluation the type to get ride of the
alias so it will not complain type mismatch due to typedef.
Chris
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Re: Re: Re: Getting info from used typedef
2010-01-21 0:38 ` Christopher Li
@ 2010-01-26 15:28 ` Thomas Schmid
2010-01-29 1:21 ` Christopher Li
0 siblings, 1 reply; 11+ messages in thread
From: Thomas Schmid @ 2010-01-26 15:28 UTC (permalink / raw)
To: Christopher Li; +Cc: linux-sparse, linux-sparse-owner
linux-sparse-owner@vger.kernel.org schrieb am 21.01.2010 01:38:09:
> I took another look into it. I think if you are just working on the
> source code transform,
> you should be able to skip the evaluation step which short cut the
typedef.
>
> Can you try again with the same patch, but in your program, using
> __sparse(filename)
> instead of sparse(filename) to get the symbols? Using __sparse will skip
the
> evaluation step. It should keep the typedef node unchanged.
Yes, that seems to help, thank you very much.
I think because of the missing evaluation step, it is now a little bit
more tricky
to get out the elements of an struct or enum, but it will work.
Do I lose anything else, skipping the evaluation step?
Is it possible to commit your change (
0001-hacking-preserve-typedef-name.patch) in source?
- I didn't recognize any change in behaviour when using the function
sparse().
Regards
Tom
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Re: Re: Re: Getting info from used typedef
2010-01-26 15:28 ` Thomas Schmid
@ 2010-01-29 1:21 ` Christopher Li
2010-02-02 8:52 ` Thomas Schmid
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Li @ 2010-01-29 1:21 UTC (permalink / raw)
To: Thomas Schmid; +Cc: linux-sparse, linux-sparse-owner
On Tue, Jan 26, 2010 at 7:28 AM, Thomas Schmid
<Thomas.Schmid@br-automation.com> wrote:
>
> Yes, that seems to help, thank you very much.
> I think because of the missing evaluation step, it is now a little bit
> more tricky
> to get out the elements of an struct or enum, but it will work.
> Do I lose anything else, skipping the evaluation step?
You don't have the type evaluation. I don't think your source code
transform program
cares.
>
> Is it possible to commit your change (
> 0001-hacking-preserve-typedef-name.patch) in source?
> - I didn't recognize any change in behaviour when using the function
> sparse().
How about make it an hidden options? It does not make sense for compiler
to care about the typedef name. I will send out a review later.
Chris
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Re: Re: Re: Re: Getting info from used typedef
2010-01-29 1:21 ` Christopher Li
@ 2010-02-02 8:52 ` Thomas Schmid
0 siblings, 0 replies; 11+ messages in thread
From: Thomas Schmid @ 2010-02-02 8:52 UTC (permalink / raw)
To: Christopher Li; +Cc: linux-sparse, linux-sparse-owner
linux-sparse-owner@vger.kernel.org schrieb am 29.01.2010 02:21:18:
> Christopher Li <sparse@chrisli.org>
> > Is it possible to commit your change (
> > 0001-hacking-preserve-typedef-name.patch) in source?
> > - I didn't recognize any change in behaviour when using the function
> > sparse().
>
> How about make it an hidden options? It does not make sense for compiler
> to care about the typedef name. I will send out a review later.
Sounds good to me.
Regards
Thomas
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-02-02 8:52 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-30 21:34 Handle __builtin_ms_va_list Michael Stefaniuc
2009-10-01 18:41 ` Christopher Li
2009-11-25 14:15 ` Getting info from used typedef Thomas Schmid
2009-11-30 23:41 ` Christopher Li
2009-12-01 12:30 ` Antwort: " Thomas Schmid
2009-12-01 18:49 ` Christopher Li
2009-12-02 14:05 ` Thomas Schmid
2010-01-21 0:38 ` Christopher Li
2010-01-26 15:28 ` Thomas Schmid
2010-01-29 1:21 ` Christopher Li
2010-02-02 8:52 ` Thomas Schmid
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).