On Thu, Mar 23, 2017 at 11:37 PM, Jakub Jelinek <ja...@redhat.com> wrote: > Hi! > > Since late C++ folding has been committed, we don't sanitize some reference > bindings to NULL. Earlier we had always NOP_EXPR to REFERENCE_TYPE say from > INTEGER_CST or whatever else, but cp_fold can now turn that right into > INTEGER_CST with REFERENCE_TYPE. The following patch sanitizes even those. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2017-03-23 Jakub Jelinek <ja...@redhat.com> > > PR c++/79572 > * c-ubsan.h (ubsan_maybe_instrument_reference): Change argument to > tree *. > * c-ubsan.c (ubsan_maybe_instrument_reference): Likewise. Handle > not just NOP_EXPR to REFERENCE_TYPE, but also INTEGER_CST with > REFERENCE_TYPE. > > * cp-gimplify.c (cp_genericize_r): Sanitize INTEGER_CSTs with > REFERENCE_TYPE. Adjust ubsan_maybe_instrument_reference caller > for NOP_EXPR to REFERENCE_TYPE. > > * g++.dg/ubsan/null-8.C: New test. > ... > --- gcc/testsuite/g++.dg/ubsan/null-8.C.jj 2017-03-23 09:42:31.664696676 > +0100 > +++ gcc/testsuite/g++.dg/ubsan/null-8.C 2017-03-23 09:43:31.501908802 +0100 > @@ -0,0 +1,19 @@ > +// PR c++/79572 > +// { dg-do run } > +// { dg-options "-fsanitize=null -std=c++14" } > +// { dg-output "reference binding to null pointer of type 'const int'" } > + > +void > +foo (const int &iref) > +{ > + if (&iref) > + __builtin_printf ("iref %d\n", iref); > + else > + __builtin_printf ("iref is NULL\n");
Hi Jakub, Using __builtin_printf causes this test to fail sporadically when cross-testing. Stdout and stderr output can get mixed in cross-testing, so dejagnu might see == g++.dg/ubsan/null-8.C:18:7: runtime error: reference binding to null pointer of type iref is NULL 'const int' == instead of == g++.dg/ubsan/null-8.C:18:7: runtime error: reference binding to null pointer of type 'const int' iref is NULL == Is it essential for this testcase to use __builtin_printf or simple "fprintf (stderr, ...)" would do just fine? > +} > + > +int > +main () > +{ > + foo (*((int*) __null)); > +} Regards, -- Maxim Kuvyrkov