Richard Smith
2014-Dec-20 02:59 UTC
[LLVMdev] [cfe-dev] ubsan - active member check for unions
On Thu, Dec 18, 2014 at 11:05 PM, Yury Gribov <y.gribov at samsung.com> wrote:> > On 12/19/2014 01:14 AM, Nick Lewycky wrote: > >> On 12/16/2014 02:43 AM, Yury Gribov wrote: >> >>> On 12/15/2014 10:24 PM, Ismail Pazarbasi wrote: >>> >>>> s.d = 42.0; >>>> if (s.l > 100) // fire here >>>> >>> >>> Note that code like this is frequently used to convert integers to >>> floats so you'll get tons of false positives. >>> >> >> True positives. The fix is to use memcpy instead. >> > > Hm, I thought C aliasing rules explicitly allow changing types through > unions.See my previous email; the kindest thing I can say about how C treats aliasing through unions is that it is confused.> Anyway, the pattern is so widespread that IMHO most maintainers will find > such errors useless.Well, given that this is the bug that the sanitizer is built to detect, such maintainers should not turn it on. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141219/1ae013e6/attachment.html>
Joerg Sonnenberger
2014-Dec-20 10:13 UTC
[LLVMdev] [cfe-dev] ubsan - active member check for unions
On Fri, Dec 19, 2014 at 06:59:48PM -0800, Richard Smith wrote:> On Thu, Dec 18, 2014 at 11:05 PM, Yury Gribov <y.gribov at samsung.com> wrote: > > Anyway, the pattern is so widespread that IMHO most maintainers will find > > such errors useless. > > > Well, given that this is the bug that the sanitizer is built to detect, > such maintainers should not turn it on.I agree with Yury that there are a few cases where it is the standard approach and flagging it as error doesn't make sense. Question is whether we can enumerate those cases and white list them. I know unions are used in mathematical code for accesing floats as int and vice versa, not sure about any thing else. Joerg
Caldarale, Charles R
2014-Dec-20 13:39 UTC
[LLVMdev] [cfe-dev] ubsan - active member check for unions
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of Joerg Sonnenberger > Subject: Re: [LLVMdev] [cfe-dev] ubsan - active member check for unions> On Fri, Dec 19, 2014 at 06:59:48PM -0800, Richard Smith wrote: > > On Thu, Dec 18, 2014 at 11:05 PM, Yury Gribov <y.gribov at samsung.com> wrote: > > > Anyway, the pattern is so widespread that IMHO most maintainers will find > > > such errors useless.> > Well, given that this is the bug that the sanitizer is built to detect, > > such maintainers should not turn it on.> I agree with Yury that there are a few cases where it is the standard > approach and flagging it as error doesn't make sense. Question is > whether we can enumerate those cases and white list them. I know unions > are used in mathematical code for accesing floats as int and vice versa, > not sure about any thing else.Often used when dealing with bare hardware and the types of fields are dependent on other information, so several are folded into one union. - Chuck