]> granicus.if.org Git - clang/commit
[ubsan] Use the object pointer's type info for devirtualized calls
authorVedant Kumar <vsk@apple.com>
Wed, 19 Oct 2016 20:21:16 +0000 (20:21 +0000)
committerVedant Kumar <vsk@apple.com>
Wed, 19 Oct 2016 20:21:16 +0000 (20:21 +0000)
commitb35098f3acfb5c873065cbd880aa559b43640ded
tree5956daf4031a80d23bd01974e70b4db5523346a1
parent8bd12ac7941aee16def56b2bf0d6d39d8c2aaa7b
[ubsan] Use the object pointer's type info for devirtualized calls

ubsan reports a false positive 'invalid member call' diagnostic on the
following example (PR30478):

  struct Base1 {
    virtual int f1() { return 1; }
  };

  struct Base2 {
    virtual int f1() { return 2; }
  };

  struct Derived2 final : Base1, Base2 {
    int f1() override { return 3; }
  };

  int t1() {
    Derived2 d;
    return static_cast<Base2 *>(&d)->f1();
  }

Adding the "final" attribute to a most-derived class allows clang to
devirtualize member calls into an instance of that class. We should pass
along the type info of the object pointer to avoid the FP. In this case,
that means passing along the type info for 'Derived2' instead of 'Base2'
when checking the dynamic type of static_cast<Base2 *>(&d2).

Differential Revision: https://reviews.llvm.org/D25448

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284636 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGExprCXX.cpp
test/CodeGenCXX/ubsan-devirtualized-calls.cpp [new file with mode: 0644]