[PATCH] D49511: [Sema/Attribute] Check for noderef attribute
Leonard Chan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 18 14:48:14 PDT 2018
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr.
leonardchan added a project: clang.
This patch adds the `noderef` attribute in clang and checks for dereferences of types that have this attribute. This attribute is currently used by sparse and would like to be ported to clang.
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
Repository:
rC Clang
https://reviews.llvm.org/D49511
Files:
include/clang/AST/Type.h
include/clang/Basic/Attr.td
include/clang/Basic/AttrDocs.td
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/AST/Type.cpp
lib/AST/TypePrinter.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaStmt.cpp
lib/Sema/SemaType.cpp
test/Frontend/noderef.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49511.156152.patch
Type: text/x-patch
Size: 14433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180718/f14aab76/attachment-0001.bin>
More information about the cfe-commits
mailing list