This is an archive of the discontinued LLVM Phabricator instance.

Add a test for vcall on a null ptr.
ClosedPublic

Authored by krasin on Nov 11 2016, 1:03 PM.

Details

Summary

Turns out that in the case of -fsanitize=null and a virtual call,
the type check was generated *after* reading from vtable, which
causes a non-interpretable segfault. The check has been moved up
in https://reviews.llvm.org/D26559 and this CL adds a test for this case.

Event Timeline

krasin updated this revision to Diff 77661.Nov 11 2016, 1:03 PM
krasin retitled this revision from to Add a test for vcall on a null ptr..
krasin updated this object.
krasin updated this object.Nov 11 2016, 1:04 PM
krasin added a reviewer: pcc.
pcc added inline comments.Nov 17 2016, 5:43 PM
test/ubsan/TestCases/TypeCheck/null.cpp
1–10

Why add the -g?

10

Is this #include needed?

35

Did you intend to add tests for these cases?

krasin updated this revision to Diff 78557.Nov 18 2016, 11:14 AM

sync & address the comments.

test/ubsan/TestCases/TypeCheck/null.cpp
1–10

It's a debug left over. Thank you for the catch.

10

Debug leftover. Removed. Thank you for spotting this.

35

Actually, the real reason for adding these is that break_optimization didn't really fool the compiler, and I had to add some more logic to avoid letting it know that the pointer is always null => it's undefined behavior. In my case, I saw my return being ignored and two switch statements executed together.

I can't currently reproduce it now, most likely, because the fix has eliminated the virtual call on a pointer that is guaranteed to be null. So, I have removed these as well as break_optimization calls.

pcc accepted this revision.Nov 21 2016, 12:53 PM
pcc edited edge metadata.

LGTM

This revision is now accepted and ready to land.Nov 21 2016, 12:53 PM
krasin closed this revision.Nov 21 2016, 1:33 PM