This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Fix some broken IR generated by -fsanitize=unsigned-integer-overflow
ClosedPublic

Authored by erik.pilkington on Feb 27 2019, 3:08 PM.

Details

Summary

I think the author of the function assumed that GetInsertBlock() wouldn't change from where atomicPHI was created, but this isn't true when -fsanitize=unsigned-integer-overflow is enabled (we generate an overflow/continuation label). Fix by keeping track of the block we want to return to to complete the cmpxchg loop.

rdar://48406558

Thanks!

Diff Detail

Repository
rL LLVM

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2019, 3:08 PM

Use FileCheck in the test, NFC.

ahatanak added inline comments.Feb 27 2019, 4:12 PM
clang/lib/CodeGen/CGExprScalar.cpp
2921 ↗(On Diff #188631)

Would passing atomicPHI->getParent() instead of opBB to Builder.CreateCondBr fix the crash?

clang/test/CodeGen/sanitize-atomic-int-overflow.c
3 ↗(On Diff #188631)

It's probably better to add some check strings here.

3 ↗(On Diff #188631)

I see this has been fixed in the updated patch.

erik.pilkington marked an inline comment as done.Feb 27 2019, 4:15 PM
erik.pilkington added inline comments.
clang/lib/CodeGen/CGExprScalar.cpp
2921 ↗(On Diff #188631)

Yeah, atomicOpBB and atomicPHI->getParent() should always be equal here. I'll update the patch to use this, since there is one less variable to keep track of.

Use atomicPHI->getParent() instead of tracking the block.

This revision is now accepted and ready to land.Feb 27 2019, 4:36 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2019, 4:48 PM