[PATCH] Implement no_sanitize attribute.
Peter Collingbourne
peter at pcc.me.uk
Thu May 14 15:35:17 PDT 2015
On Thu, May 14, 2015 at 05:06:22PM -0400, Aaron Ballman wrote:
> On Thu, May 14, 2015 at 4:36 PM, Peter Collingbourne <peter at pcc.me.uk> wrote:
> > - Introduce VariadicStringArgument, start using it for no_sanitize; support ObjC methods
> > - Add support for C++11 attribute; fix multiple no_sanitize attribute case
> >
> >
> > http://reviews.llvm.org/D9631
> >
> > Files:
> > include/clang/AST/Attr.h
> > include/clang/Basic/Attr.td
> > include/clang/Basic/AttrDocs.td
> > lib/CodeGen/CodeGenFunction.cpp
> > lib/CodeGen/CodeGenModule.cpp
> > lib/Sema/SemaDeclAttr.cpp
> > test/CodeGen/address-safety-attr.cpp
> > test/CodeGen/sanitize-thread-attr.cpp
> > test/CodeGenCXX/cfi-vcall.cpp
> > test/CodeGenObjC/no-sanitize.m
> > test/SemaCXX/attr-no-sanitize.cpp
> > utils/TableGen/ClangAttrEmitter.cpp
>
> > Index: include/clang/AST/Attr.h
> > ===================================================================
> > --- include/clang/AST/Attr.h
> > +++ include/clang/AST/Attr.h
> > @@ -20,6 +20,7 @@
> > #include "clang/AST/Type.h"
> > #include "clang/Basic/AttrKinds.h"
> > #include "clang/Basic/LLVM.h"
> > +#include "clang/Basic/Sanitizers.h"
> > #include "clang/Basic/SourceLocation.h"
> > #include "clang/Basic/VersionTuple.h"
> > #include "llvm/ADT/SmallVector.h"
> > Index: include/clang/Basic/Attr.td
> > ===================================================================
> > --- include/clang/Basic/Attr.td
> > +++ include/clang/Basic/Attr.td
> > @@ -144,6 +144,7 @@
> > class UnsignedArgument<string name, bit opt = 0> : Argument<name, opt>;
> > class VariadicUnsignedArgument<string name> : Argument<name, 1>;
> > class VariadicExprArgument<string name> : Argument<name, 1>;
> > +class VariadicStringArgument<string name> : Argument<name, 0>;
>
> This should be set to Argument<name, 1> since a variadic string could
> potentially be empty. We can add the nonempty logic to the handler.
Done.
> > --- include/clang/Basic/AttrDocs.td
> > +++ include/clang/Basic/AttrDocs.td
> > @@ -920,6 +920,19 @@
> > }];
> > }
> >
> > +def NoSanitizeDocs : Documentation {
> > + let Category = DocCatFunction;
> > + let Content = [{
> > +Use the ``no_sanitize`` attribute on a function declaration to specify
> > +that a particular instrumentation or set of instrumentations should not be
> > +applied to that function. The attribute takes a list of string literals,
> > +which have the same meaning as values accepted by the ``-fno-sanitize=``
> > +flag. For example, ``__attribute__((no_sanitize("address", "thread")))``
> > +specifies that AddressSanitizer and ThreadSanitizer should not be applied
> > +to the function.
> > + }];
>
> Do we have the -fno-sanitize flags documented somewhere? If so, it
> would be handy to have a link to that documentation from here. If not,
> that's fine.
Added link.
>
> > +}
> > +
> > def NoSanitizeAddressDocs : Documentation {
> > let Category = DocCatFunction;
> > // This function has multiple distinct spellings, and so it requires a custom
> > Index: lib/CodeGen/CodeGenFunction.cpp
> > ===================================================================
> > --- lib/CodeGen/CodeGenFunction.cpp
> > +++ lib/CodeGen/CodeGenFunction.cpp
> > @@ -608,6 +608,28 @@
> > if (CGM.isInSanitizerBlacklist(Fn, Loc))
> > SanOpts.clear();
> >
> > + if (D) {
> > + // Apply the no_sanitize* attributes to SanOpts.
> > + for (auto I = D->specific_attr_begin<NoSanitizeAttr>(),
> > + E = D->specific_attr_end<NoSanitizeAttr>();
> > + I != E; ++I)
>
> Range-based for loop with specific_attrs<NoSanitizeAttr>()?
Done.
> > --- lib/Sema/SemaDeclAttr.cpp
> > +++ lib/Sema/SemaDeclAttr.cpp
> > @@ -4354,6 +4354,24 @@
> > handleAttrWithMessage<DeprecatedAttr>(S, D, Attr);
> > }
> >
> > +static void handleNoSanitizeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
> > + std::vector<std::string> Sanitizers;
>
> Can call checkAttributeAtLeastNumArgs(S, Attr, 1) to diagnose if no
> arguments are specified after changing the definition of
> VariadicStringArgument.
Done.
Thanks,
--
Peter
More information about the cfe-commits
mailing list