Commit d5ed033d authored by Rafael Espindola's avatar Rafael Espindola
Browse files

In Sema::MergeVarDecl we handle merging of storage classes and visibility

attributes. In cases where the merged declaration is fully equivalent to the
two original ones, some of the code was getLVForDecl was duplicated.

Cases that are still handled in getLVForDecl are things like

__private_extern__ int N;
int N;

For which we cannot produce a single merged decl with all the information.

llvm-svn: 167703
parent 2700433f
Loading
Loading
Loading
Loading
+6 −25
Original line number Diff line number Diff line
@@ -341,25 +341,9 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D,
    if (Var->getStorageClass() == SC_PrivateExtern)
      LV.mergeVisibility(HiddenVisibility, true);

    if (!Context.getLangOpts().CPlusPlus &&
        (Var->getStorageClass() == SC_Extern ||
         Var->getStorageClass() == SC_PrivateExtern)) {

      // C99 6.2.2p4:
      //   For an identifier declared with the storage-class specifier
      //   extern in a scope in which a prior declaration of that
      //   identifier is visible, if the prior declaration specifies
      //   internal or external linkage, the linkage of the identifier
      //   at the later declaration is the same as the linkage
      //   specified at the prior declaration. If no prior declaration
      //   is visible, or if the prior declaration specifies no
      //   linkage, then the identifier has external linkage.
      if (const VarDecl *PrevVar = Var->getPreviousDecl()) {
        LinkageInfo PrevLV = getLVForDecl(PrevVar, OnlyTemplate);
        if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage());
        LV.mergeVisibility(PrevLV);
      }
    }
    // Note that Sema::MergeVarDecl already takes care of implementing
    // C99 6.2.2p4 and propagating the visibility attribute, so we don't have
    // to do it here.

  //     - a function, unless it has internal linkage; or
  } else if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
@@ -842,12 +826,9 @@ static LinkageInfo getLVForDecl(const NamedDecl *D, bool OnlyTemplate) {
            LV.mergeVisibility(*Vis, true);
        }

        if (const VarDecl *Prev = Var->getPreviousDecl()) {
          LinkageInfo PrevLV = getLVForDecl(Prev, OnlyTemplate);
          if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage());
          LV.mergeVisibility(PrevLV);
        }

        // Note that Sema::MergeVarDecl already takes care of implementing
        // C99 6.2.2p4 and propagating the visibility attribute, so we don't
        // have to do it here.
        return LV;
      }
  }