On Tue, Sep 17, 2013 at 05:37:51PM +0200, Jakub Jelinek wrote:
> On Tue, Sep 17, 2013 at 05:24:22PM +0200, Marek Polacek wrote:
> > This patch adds the no_sanitize_undefined attribute, so the user can tell
> > that a particular function should be ignored by ubsan.
> 
> Does this correspond to some llvm attribute?

No, it seems they don't have a flag for disabling the ubsan; they only
have flags for disabling asan/tsan/msan.
 
> > --- gcc/builtins.c.mp2      2013-09-17 16:13:26.623161281 +0200
> > +++ gcc/builtins.c  2013-09-17 16:15:20.846557451 +0200
> > @@ -10313,7 +10313,9 @@ fold_builtin_0 (location_t loc, tree fnd
> >        return fold_builtin_classify_type (NULL_TREE);
> >  
> >      case BUILT_IN_UNREACHABLE:
> > -      if (flag_sanitize & SANITIZE_UNREACHABLE)
> > +      if (flag_sanitize & SANITIZE_UNREACHABLE
> > +     && !lookup_attribute ("no_sanitize_undefined",
> > +                           DECL_ATTRIBUTES (current_function_decl)))
> >     return ubsan_instrument_unreachable (loc);
> >        break;
> 
> I wonder if current_function_decl couldn't be NULL here, say if
> __builtin_unreachable () appears in C++ global var initializers or similar.

Well I wonder too ;)  I thought it can't be NULL, and tried this

struct C {
  C() { __builtin_unreachable (); }
};

C c;

int
main ()
{
  return 0;
}

and here everything looks ok.  Or is this not the proper way of
checking that?  Surely, I can add the check for current_function_decl
!= NULL just to be on the safe side...

        Marek

Reply via email to