[cfe-dev] noderef attribute

Hal Finkel via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 19 13:06:54 PDT 2018



On 07/19/2018 02:33 PM, Leonard Chan via cfe-dev wrote:
> Hi all,
>
> I'm working on a patch at https://reviews.llvm.org/D49511 that
> implements the `noderef` attribute in clang. Essentially the attribute
> works by raising a warning when dereferencing a pointer marked with
> `__attribute__((noderef))`. This attribute is currently used by sparse

Sparse is this: https://sparse.wiki.kernel.org/index.php/Main_Page

Any other attributes from Sparse you're interesting in adding, or just
this one?

If we have a function parameter that takes a noderef pointer, can we add
the readnone attribute on the argument so that the optimizer knows that
memory is not accessed through that pointer?

 -Hal

> and would like to be ported to clang and wanted to see if anyone would
> be up for reviewing it/had any comments on it.
>
> The following are examples of when a warning would be raised on
> dereferencing a noderef type.
>
> ```
> int __attribute__((noderef)) *p;
> int x = *p;  // warning: dereference of noderef expression
> [-Wignored-attributes]
>
> int __attribute__((noderef)) **p2;
> x = **p2;  // warning: dereference of noderef expression [-Wignored-attributes]
>
> int * __attribute__((noderef)) *p3;
> p = *p3;  // warning: dereference of noderef expression [-Wignored-attributes]
>
> struct S {
>   int a;
> };
> struct S __attribute__((noderef)) *s;
> x = s->a;    // warning: dereference of noderef expression
> [-Wignored-attributes]
> x = (*s).a;   // warning: dereference of noderef expression
> [-Wignored-attributes]
> ```
>
> Not all accesses may raise a warning if the value directed by the
> pointer may not be accessed. The following are examples where no
> warning may be raised:
>
> ```
> int *q;
> int __attribute__((noderef)) *p;
> q = &*p;
> q = *&p;
>
> struct S {
>   int a;
> };
> struct S __attribute__((noderef)) *s;
> p = &s->a;
> p = &(*s).a;
> ```
>
> More examples of existing usage of noderef in sparse can be found in
> https://git.kernel.org/pub/scm/devel/sparse/sparse.git/tree/validation/noderef.c
>
> Feel free to provide feedback/reviews.
>
> Thanks,
> Leo
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory




More information about the cfe-dev mailing list