[cfe-commits] r159212 - in /cfe/trunk: include/clang/AST/DeclCXX.h include/clang/AST/Expr.h lib/AST/DeclCXX.cpp lib/AST/Expr.cpp lib/CodeGen/CGExprCXX.cpp lib/Sema/SemaExpr.cpp test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp

Rafael Espíndola rafael.espindola at gmail.com
Wed Jun 27 11:41:26 PDT 2012


> There is another latent bug in this optimization:  'this' will have been
> converted to the base type, but we may be calling a method on a
> derived type, which will then be passed an invalid 'this' pointer.
>
> Why don't we just constrain the optimization for now to only apply
> when the static method has not been overridden in the most-derived
> type?  That will catch the common case of derived->foo().

I fixed the other comments (thanks!), but I am not able to build a
testcase where this fails. What I have tried was

struct foo {
  int x;
};
struct bar {
  int y;
  virtual int f() { return y; }
};
struct zed final : public foo, public bar {
  int z;
  virtual int f() {return z;}
};
int f(zed *z) {
  return static_cast<bar*>(z)->f();
}

In the hope that f would call zed::f with a bar* this, but it is
correctly passing a zed*. Is this what you had in mind?

> John.

Cheers,
Rafael




More information about the cfe-commits mailing list