[PATCH] D20647: Add flag to add InlineHint attribute on implicitly inline functions

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 17 08:27:02 PDT 2016


rnk added a comment.

In http://reviews.llvm.org/D20647#460520, @Ilod wrote:

> I don't think weak linkage defines this.


Right, sorry, normal external linkage is the obvious case. I was hung up thinking about cases like this:

  volatile int x;
  template <typename T>
  struct A {
    void f();
    void g() { ++x; } // implicitly inline
  };
  template <typename T>
  void A<T>::f() { ++x; } // not inline
  int main() {
    A<int> a;
    a.f(); // not inlined with /Ob1
    a.g(); // inlined with /Ob1
  }

In this code, A::g has weak linkage but is not inline. MSVC will not inline it with /Ob1.

Can you get the behavior you want by doing `if (!FD->isInlined()) Fn->addFnAttr(llvm::Attribute::NoInline);` instead? It seems nicer because we don't need to thread any options to the inliner, like you did in http://reviews.llvm.org/D20603.


http://reviews.llvm.org/D20647





More information about the cfe-commits mailing list