Skip to contentSkip to conversation

intended use of "safe"?

DISCUSSION Ben Pfaff 3 participants 3 messages Aug 11, 2011 – Aug 12, 2011 Sparse checker

lore
Share & tools
lore

Ben Pfaff

author
#0 lore raw

It looks like the sparse "safe" attribute warns about use of "safe" values as conditional expressions. It's not obvious to me when I would find that useful.

What is the intended use of the sparse "safe" attribute? I do not see any uses of it in Linux (although there is a __safe macro for it). I don't see any documentation for it either.

Thanks,

Ben.

Signature · 2 lines
Ben Pfaff 
http://benpfaff.org
maintainer
#1 lore raw
Quoted 3 lines · Ben Pfaff

What is the intended use of the sparse "safe" attribute?  I do not see any uses of it in Linux (although there is a __safe macro for it).  I don't see any documentation for it either.

I don't know much about the safe attribute either. I find out the commit which introduce the safe attribute by "git blame".

If a pointer is never NULL, there is not need to test the pointer.

Chris

commit 98f14350c26518f0f5c45632d145a218d468d8b8

Author: Linus Torvalds <[email protected]>
Date:   Fri Apr 16 18:19:30 2004 -0700

Introduce "safe" pointer expressions.

These are defined to never be NULL or nontrapping, and could help code generation, but right now only cause a warning if they are tested in a conditional.
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 13 lines · Christopher Li
Quoted 3 lines · Ben Pfaff

What is the intended use of the sparse "safe" attribute?  I do not see any uses of it in Linux (although there is a __safe macro for it).  I don't see any documentation for it either.

I don't know much about the safe attribute either. I find out the commit which introduce the safe attribute by "git blame".

If a pointer is never NULL, there is not need to test the pointer.

Chris

commit 98f14350c26518f0f5c45632d145a218d468d8b8

Quoted 8 lines
Author: Linus Torvalds <[email protected]>
Date:   Fri Apr 16 18:19:30 2004 -0700

Introduce "safe" pointer expressions.

These are defined to never be NULL or nontrapping, and could help code generation, but right now only cause a warning if they are tested in a conditional.

That does actually seem useful. The Linux kernel has various structures with pointers that should never be NULL, and documenting that in a compiler-visible way seems like a feature.

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html