Disable caching of visibility.
The testcase in pr14929 shows that this is extremely hard to do. If we choose
to apply the attribute, that causes the visibility of some decls to change and
that can happen really late (during codegen).
Current gcc warns and ignores the attribute in this testcase with a warning.
This suggest that the correct solution is to find a point in the compilation
where we can compute the visibility and
* assert it was never computed before
* reject any attempts to compute it again in the future (with warnings).
llvm-svn: 172305
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 3bfb8f2..b212b3f 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -321,7 +321,6 @@
= (VisibilityAttr::VisibilityType) rawType;
SourceLocation loc = Stack->back().second;
- ND->ClearLVCache();
D->addAttr(::new (Context) VisibilityAttr(loc, Context, type));
}
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c3a2ad1..b9d141b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1824,18 +1824,14 @@
bool Sema::mergeDeclAttribute(NamedDecl *D, InheritableAttr *Attr) {
InheritableAttr *NewAttr = NULL;
- if (AvailabilityAttr *AA = dyn_cast<AvailabilityAttr>(Attr)) {
+ if (AvailabilityAttr *AA = dyn_cast<AvailabilityAttr>(Attr))
NewAttr = mergeAvailabilityAttr(D, AA->getRange(), AA->getPlatform(),
AA->getIntroduced(), AA->getDeprecated(),
AA->getObsoleted(), AA->getUnavailable(),
AA->getMessage());
- if (NewAttr)
- D->ClearLVCache();
- } else if (VisibilityAttr *VA = dyn_cast<VisibilityAttr>(Attr)) {
+ else if (VisibilityAttr *VA = dyn_cast<VisibilityAttr>(Attr))
NewAttr = mergeVisibilityAttr(D, VA->getRange(), VA->getVisibility());
- if (NewAttr)
- D->ClearLVCache();
- } else if (DLLImportAttr *ImportA = dyn_cast<DLLImportAttr>(Attr))
+ else if (DLLImportAttr *ImportA = dyn_cast<DLLImportAttr>(Attr))
NewAttr = mergeDLLImportAttr(D, ImportA->getRange());
else if (DLLExportAttr *ExportA = dyn_cast<DLLExportAttr>(Attr))
NewAttr = mergeDLLExportAttr(D, ExportA->getRange());
@@ -6695,7 +6691,7 @@
}
VDecl->setTypeSourceInfo(DeducedType);
VDecl->setType(DeducedType->getType());
- VDecl->ClearLVCache();
+ VDecl->ClearLinkageCache();
// In ARC, infer lifetime.
if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(VDecl))
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 225ee24..9c17d6e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2043,7 +2043,6 @@
VersionTuple MergedDeprecated = Deprecated;
VersionTuple MergedObsoleted = Obsoleted;
bool FoundAny = false;
- bool DroppedAny = false;
if (D->hasAttrs()) {
AttrVec &Attrs = D->getAttrs();
@@ -2078,7 +2077,6 @@
Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
Diag(Range.getBegin(), diag::note_previous_attribute);
Attrs.erase(Attrs.begin() + i);
- DroppedAny = true;
--e;
continue;
}
@@ -2098,7 +2096,6 @@
MergedIntroduced2, MergedDeprecated2,
MergedObsoleted2)) {
Attrs.erase(Attrs.begin() + i);
- DroppedAny = true;
--e;
continue;
}
@@ -2110,9 +2107,6 @@
}
}
- if (DroppedAny)
- D->ClearLVCache();
-
if (FoundAny &&
MergedIntroduced == Introduced &&
MergedDeprecated == Deprecated &&
@@ -2159,10 +2153,8 @@
Deprecated.Version,
Obsoleted.Version,
IsUnavailable, Str);
- if (NewAttr) {
+ if (NewAttr)
D->addAttr(NewAttr);
- ND->ClearLVCache();
- }
}
VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, SourceRange Range,
@@ -2179,8 +2171,6 @@
Diag(ExistingAttr->getLocation(), diag::err_mismatched_visibility);
Diag(Range.getBegin(), diag::note_previous_attribute);
D->dropAttr<VisibilityAttr>();
- NamedDecl *ND = cast<NamedDecl>(D);
- ND->ClearLVCache();
}
return ::new (Context) VisibilityAttr(Range, Context, Vis);
}
@@ -2224,11 +2214,8 @@
}
VisibilityAttr *NewAttr = S.mergeVisibilityAttr(D, Attr.getRange(), type);
- if (NewAttr) {
+ if (NewAttr)
D->addAttr(NewAttr);
- NamedDecl *ND = cast<NamedDecl>(D);
- ND->ClearLVCache();
- }
}
static void handleObjCMethodFamilyAttr(Sema &S, Decl *decl,