This is an archive of the discontinued LLVM Phabricator instance.

[modules] when deserializing method, ensure it has correct exception spec
AbandonedPublic

Authored by elsteveogrande on Sep 3 2018, 8:28 PM.

Details

Summary

(PR38627)

After deserializing, the PendingExceptionSpecUpdates table is iterated over to apply exception specs to functions. There may be EST_None-type in this table. However if there is a method in the redecl chain already having some other non-EST_None type, this should not be clobbered with none.

If we see EST_None avoid setting the exception spec. (This is the default anyway, so it's safe to skip in the legit case.)

There may be *better* ways to actually fix this, rather than a simple 1-line defensive check like I did here. It would be more complicated and quite outside my area of experience though.

Test Plan: Passes ninja check-clang, including a new test case.

Andrew Gallagher provided the test case (distilling it from a much more complex instance in our code base).

Diff Detail

Event Timeline

elsteveogrande created this revision.Sep 3 2018, 8:28 PM
rsmith added a comment.Sep 4 2018, 5:59 PM

I think this is addressing a symptom rather than the cause. The bug appears to be that when parsing a.h, we end up with inconsistent exception specifications along the redeclaration chain. It looks like Sema::AdjustDestructorExceptionSpec doesn't do the right thing when befriending a destructor. Here's a non-modules testcase based on yours that demonstrates either the same problem or at least a closely-related one:

struct B {
  virtual ~B();
  struct C { friend B::~B() noexcept; }; 
};

We produce a bogus error here ("exception specification in declaration does not match previous declaration"). But we think the exception specifications match if class C is moved outside class B.

Generally, we skip checking the exception specification for a destructor until we get to the end of the class. But when the destructor declaration is a friend declaration for a destructor of an enclosing class, we need to instead delay until that enclosing class is complete. I expect the logic to do that is what's missing here.

Hi @rsmith ! Thanks for taking a look at this. I'd much prefer to fix the underlying problem and not swat at these symptoms, so thanks for the analysis of what's actually going on here. :) Let me take a stab at fixing the real problem in the manner you describe.

rsmith added a comment.Sep 5 2018, 3:07 PM

I had a look at fixing this, and it... snowballed into a much larger change than I was expecting. I have a patch on the way.

rsmith added a comment.Sep 5 2018, 3:31 PM

Fixed in r341499.

elsteveogrande abandoned this revision.Sep 5 2018, 7:59 PM

that's great news, thanks!