[cfe-dev] Undiagnosed null pointer dereference

Martin J. O'Riordan via cfe-dev cfe-dev at lists.llvm.org
Fri Sep 8 09:53:48 PDT 2017


I was looking at a bug that a customer reported to me, and have reduced the
code to the following fragment:

void func(int *z) {

  int *b = 0; // This is the customer bug

 

  for (int j = 0; j < 16; j++) {

    int c = *b;

    c -= *z++;

    *b++ = c;

  }

}

It is clearly undefined behaviour, and this produces the following IR:

; Function Attrs: norecurse nounwind

define void @func(i32* nocapture readonly) local_unnamed_addr #0 {

  unreachable

}

which emits a label for the function in assembly, but no instructions.  But
if I comment out any of the lines in the loop, I get:

; Function Attrs: norecurse nounwind readnone

define void @func(i32* nocapture) local_unnamed_addr #0 {

  ret void

}

then it emits an function which returns immediately.

 

I was surprised though, that even with '-Wall -Wextra' the de-reference of
the null pointer is not diagnosed.

 

I guess this is a bug, but I haven't yet gone through the process of
reporting bugs.

 

            MartinO

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170908/ce24156d/attachment.html>


More information about the cfe-dev mailing list