This is an archive of the discontinued LLVM Phabricator instance.

LowerTypeTests: Give imported symbols a type with size 0 so that they are not assumed not to alias.
ClosedPublic

Authored by pcc on Oct 12 2017, 6:46 PM.

Details

Summary

It is possible for both a base and a derived class to be satisfied
with a unique vtable. If a program contains casts of the same pointer
to both of those types, the CFI checks will be lowered to this
(with ThinLTO):

if (p != &__typeid_base_global_addr)

trap();

if (p != &__typeid_derived_global_addr)

trap();

The optimizer may then use the first condition combined
with the assumption that typeid_base_global_addr and
typeid_derived_global_addr may not alias to optimize away the second
comparison, resulting in an unconditional trap.

This patch fixes the bug by giving imported globals the type [0 x i8]*,
which prevents the optimizer from assuming that they do not alias.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.Oct 12 2017, 6:46 PM
eugenis accepted this revision.Oct 13 2017, 1:04 PM
This revision is now accepted and ready to land.Oct 13 2017, 1:04 PM
This revision was automatically updated to reflect the committed changes.