Skip to content

Commit

Permalink
Merging r244101:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
r244101 | samsonov | 2015-08-05 12:35:46 -0700 (Wed, 05 Aug 2015) | 6 lines

[UBSan] Fix UBSan-vptr false positive.

Offset from vptr to the start of most-derived object can actually
be positive in some virtual base class vtables.

Patch by Stephan Bergmann!
------------------------------------------------------------------------


git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/branches/release_37@245114 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
zmodem committed Aug 14, 2015
1 parent 25ac0b1 commit b521409
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ubsan/ubsan_type_hash_itanium.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ namespace {

struct VtablePrefix {
/// The offset from the vptr to the start of the most-derived object.
/// This should never be greater than zero, and will usually be exactly
/// zero.
/// This will only be greater than zero in some virtual base class vtables
/// used during object con-/destruction, and will usually be exactly zero.
sptr Offset;
/// The type_info object describing the most-derived class type.
std::type_info *TypeInfo;
Expand All @@ -196,7 +196,7 @@ VtablePrefix *getVtablePrefix(void *Vtable) {
if (!Vptr)
return 0;
VtablePrefix *Prefix = Vptr - 1;
if (Prefix->Offset > 0 || !Prefix->TypeInfo)
if (!Prefix->TypeInfo)
// This can't possibly be a valid vtable.
return 0;
return Prefix;
Expand Down
13 changes: 13 additions & 0 deletions test/ubsan/TestCases/TypeCheck/vptr-virtual-base-construction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr %s -o %t
// RUN: %run %t

// REQUIRES: cxxabi

int volatile n;

struct A { virtual ~A() {} };
struct B: virtual A {};
struct C: virtual A { ~C() { n = 0; } };
struct D: virtual B, virtual C {};

int main() { delete new D; }

0 comments on commit b521409

Please sign in to comment.