I made a few changes, but I'm still getting the same errors.  I expanded out 
the list_for_each_entry macro (well, Eclipse's mouse-over macro expansion did) 
and copied that in place of my list_for_each_entry call.  I then changed all 
references of typeof to __typeof__ just in case Splint was having issues with 
typeof not being defined.  I still get the error about local_mptr not found.  I 
also tried annotating the macros with /*@notfunction@*/, and that didn't change 
my results either.  I do find it odd that it works just fine when the 
list_entry macro doesn't end up in the for loop statement, which leads me to 
think that Splint has no issue with typeof.  Anything else I could put up that 
would be helpful?

Thanks,
Bryan


From: [email protected] 
[mailto:[email protected]] On Behalf Of Sasikanth
Sent: Thursday, January 26, 2012 12:22 PM
To: Discussions about the Splint annotation-assisted static analysis project
Subject: Re: [splint-discuss] Proper annotations for linked list implementation


On Thu, Jan 26, 2012 at 8:08 PM, Bryan Evenson <[email protected]> wrote:
There's one specific issue I'm really having with splint's parsing, and it's 
with the list_for_each_entry macro.  For reference, the macro is defined as:

/**
 * list_for_each_entry  -   iterate over list of given type
 * @pos:    the type * to use as a loop cursor.
 * @head:   the head for your list.
 * @member: the name of the list_struct within the struct.
 */
#define list_for_each_entry(pos, head, member)              \
   for (pos = list_entry((head)->next, typeof(*pos), member);  \
        &pos->member != (head);    \
        pos = list_entry(pos->member.next, typeof(*pos), member))

where list_entry is defined as:
/**
 * list_entry - get the struct for this entry
 * @ptr:    the &struct list_head pointer.
 * @type:   the type of the struct this is embedded in.
 * @member: the name of the list_struct within the struct.
 */
#define list_entry(ptr, type, member) \
   container_of(ptr, type, member)

and where container_of is defined as:
/**
 * container_of - cast a member of a structure out to the containing structure
 * @ptr:    the pointer to the member.
 * @type:   the type of the container struct this is embedded in.
 * @member: the name of the member within the struct.
 *
 */
#define container_of(ptr, type, member) ({          \
   const typeof( ((type *)0)->member ) *local_mptr = (ptr);    \
   (type *)( (char *)local_mptr - offset_of(type,member) );})

And finally where offset of is defined as:
#define offset_of(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

When I try to use list_for_each_entry, splint crashes with the following error:
*** Fatal bug: usymtab_lookup: not found: *local_mptr*
*** Last code point: exprNode.c:10317
*** Previous code point: exprNode.c:10317
    *** Please report bug to [email protected] (via reportbug) ***

I'm not quite sure what it doesn't like about the macro expansion and the usage 
of local_mptr.  If I instead use list_for_each and then use list_entry inside 
my loop, splint deals with that okay.  So it doesn't have any issue in itself 
with the list_entry or container_of macros, but it doesn't like it when these 
expand out to be part of the for loop statement.  I could just use 
list_for_each, but I'd hate to avoid adding more cumbersome code just to make 
splint happy.  Any tips?
     I think the problem is not  about the macro expansion its with typeof. 
typeof is not a standard one and its GCC specific extension, Splint may not 
understand typeof. Since doesn't understand typeof it was not able to define a 
variable local_mptr .
Thanks,
Bryan

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Bryan Evenson
Sent: Tuesday, January 24, 2012 2:27 PM
To: [email protected]
Subject: [splint-discuss] Proper annotations for linked list implementation

I'm using splint on some userspace application code that will run in an 
embedded Linux environment.  I borrowed the kernel linked list implementation 
(list.h) for use in userspace.  The linked list works great, but it's giving me 
a bunch of issues for checking with splint.  I think if I saw what the 
annotations were that was used for list.h that is used by the unixlib I'd be 
able to solve a lot of my problems.  Does anyone know where I can find what the 
annotation for list.h should look like?

Thanks,
Bryan

_______________________________________________
splint-discuss mailing list
[email protected]
http://www.cs.virginia.edu/mailman/listinfo/splint-discuss

_______________________________________________
splint-discuss mailing list
[email protected]
http://www.cs.virginia.edu/mailman/listinfo/splint-discuss


_______________________________________________
splint-discuss mailing list
[email protected]
http://www.cs.virginia.edu/mailman/listinfo/splint-discuss

Reply via email to