[cfe-dev] Redeclaration of weak import causes assertion failure

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Jan 10 08:52:48 PST 2013


On 9 January 2013 22:18, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:
> This reduces to the awesome testcase:
>
> template <typename T>
> void f(T x) {
> }
> struct C {
>   static void g() {
>     f([](){});
>   }
> };
> void g() {
>   C::g();
> }
>
> It is awesome because the LV of [](){} is taken from that of g, and
> that changes when g gets a body and we are building with
> -fvisibility-inlines-hidden.
>
> Trying to figure out how to solve this.

The attached patch (which goes on top of the patch for pr14766) fixes
the problem by not trying to compute the LV at a time where me might
still not know it. The problematic sequence right now is:

* We try to find out if f's LV.
* For that we try to find the LV of the argument type.
* For that we try to find the LV of the lambda.
* For that we try to find the LV of the context (which is g).
* hasBody returns false for g, which causes us to get the wrong answer
because of -fvisibility-inlines-hidden.

A possible optimization on top of this patch is to add a
hasCachedLinkage method to NamedDecl. If we already know the linkage,
it is safe to use it.

A completely different option is to set a dummy (pointer cast of 1 for
example) body in g's decl while we construct the real one.

Cheers,
Rafael




More information about the cfe-dev mailing list