[PATCH] D65445: [CrossTU] Handle case when no USR could be generated during Decl search.

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 31 05:25:51 PDT 2019

martong added a comment.

In D65445#1607803 <https://reviews.llvm.org/D65445#1607803>, @balazske wrote:

> It looks like that the problem can happen when the anonymous union is in any `DeclContext` and for CTU import the import of a variable is requested and that variable is in a related `DeclContext` (it can be at upper or lower level). (See code of `findDefInDeclContext`: If used for variables, it goes through every `DeclContext` and computes USR for specific `VarDecl`s until the one is found. If we have luck it may be found before the union. An anonymous union can not be imported because we get no USR for it so it is OK to ignore these.) So the test can be written in many other forms but this case (the code of `f`) was encountered in protobuf code.

Thanks for the explanation.

So, IIUC we cannot generate the USR for the member of the anonymous union, right? `f` or `i` below does not have a USR.

  class TestAnonUnionUSR {
    inline float f(int value) {
      union {
        float f;
        int i;
      i = value;
      return f;
    static const int Test;

And `findDefInDeclContext` goes through all children DC. So if the DC is `TestAnonUnionUSR` then we may try to get the USR for `f` and `i`. Please confirm if I understand it correctly or not.

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list