Redeclaration of weak import causes assertion failure

Hey, Rafael. Somewhere in the last week or so this test case broke:

extern int x __attribute__((availability(macosx,introduced=10.5)));
extern int x;

Assertion failed: (LV == computeLVForDecl(this, false)), function getLinkageAndVisibility, file /Volumes/Lore/llvm-public/clang/lib/AST/Decl.cpp, line 630.

Note that this still works (or at least, does not assert):

extern int x;
extern int x __attribute__((availability(macosx,introduced=10.5)));

Any ideas?
Jordan

Hey, Rafael. Somewhere in the last week or so this test case broke:

extern int x __attribute__((availability(macosx,introduced=10.5)));
extern int x;

Fixed in 171840. Sorry for the troubles.

Any ideas?
Jordan

Cheers,
Rafael

Hm...our internal build is still hitting that assertion. I'll see if I can re-reduce soon.

Jordan

Hm...our internal build is still hitting that assertion. I'll see if I can re-reduce soon.

Thanks again and sorry for the problems.

Jordan

Cheers,
Rafael

Okay, here you go.

extern int x __attribute__((availability(macosx,introduced=10.2)));
extern int x __attribute__((availability(macosx,introduced=10.5)));

I'll file an internal bug against this stupidity as well.

Jordan

Okay, here you go.

extern int x __attribute__((availability(macosx,introduced=10.2)));
extern int x __attribute__((availability(macosx,introduced=10.5)));

I'll file an internal bug against this stupidity as well.

Fixed with r171906.

Jordan

Cheers,
Rafael

I’m getting the same assertion on WriterELF.cpp, line 1666, when instantiating std::stable_sort.
This is while running on Mac OS X with the latest clang from trunk.

I’m trying to reduce the test case, but creduce is taking a while.

Regards,

Filipe

Thanks, our builder's passing again! (Hope Filipe's issue isn't too hard...)

Jordan

I'm getting the same assertion on WriterELF.cpp, line 1666, when
instantiating std::stable_sort.
This is while running on Mac OS X with the latest clang from trunk.

I'm trying to reduce the test case, but creduce is taking a while.

If the preprocessed source is something you can share, I can try
manually reducing it.

Regards,

  Filipe

  F

Cheers,
Rafael

Here are the files clang generates when asserting.

Cool. I managed to cut quiet a bit of code manually. Delta is making
progress in reducing it further now.

Thanks,

  Filipe

  F

Cheers,
Rafael

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.

Cheers,
Rafael

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

Forgot the patch, it is attached now.

Cheers,
Rafael

t.patch (1.48 KB)

Thanks, Rafael.

That works.

Filipe