@@ -13380,62 +13380,6 @@ void Sema::checkNonTrivialCUnion(QualType QT, SourceLocation Loc,
13380
13380
.visit(QT, nullptr, false);
13381
13381
}
13382
13382
13383
- bool Sema::GloballyUniqueObjectMightBeAccidentallyDuplicated(
13384
- const VarDecl *Dcl) {
13385
- if (!getLangOpts().CPlusPlus)
13386
- return false;
13387
-
13388
- // We only need to warn if the definition is in a header file, so wait to
13389
- // diagnose until we've seen the definition.
13390
- if (!Dcl->isThisDeclarationADefinition())
13391
- return false;
13392
-
13393
- // If an object is defined in a source file, its definition can't get
13394
- // duplicated since it will never appear in more than one TU.
13395
- if (Dcl->getASTContext().getSourceManager().isInMainFile(Dcl->getLocation()))
13396
- return false;
13397
-
13398
- // If the variable we're looking at is a static local, then we actually care
13399
- // about the properties of the function containing it.
13400
- const ValueDecl *Target = Dcl;
13401
- // VarDecls and FunctionDecls have different functions for checking
13402
- // inline-ness, so we have to do it manually.
13403
- bool TargetIsInline = Dcl->isInline();
13404
-
13405
- // Update the Target and TargetIsInline property if necessary
13406
- if (Dcl->isStaticLocal()) {
13407
- const DeclContext *Ctx = Dcl->getDeclContext();
13408
- if (!Ctx)
13409
- return false;
13410
-
13411
- const FunctionDecl *FunDcl =
13412
- dyn_cast_if_present<FunctionDecl>(Ctx->getNonClosureAncestor());
13413
- if (!FunDcl)
13414
- return false;
13415
-
13416
- Target = FunDcl;
13417
- // IsInlined() checks for the C++ inline property
13418
- TargetIsInline = FunDcl->isInlined();
13419
- }
13420
-
13421
- // Non-inline variables can only legally appear in one TU
13422
- // FIXME: This also applies to templated variables, but that can rarely lead
13423
- // to false positives so templates are disabled for now.
13424
- if (!TargetIsInline)
13425
- return false;
13426
-
13427
- // If the object isn't hidden, the dynamic linker will prevent duplication.
13428
- clang::LinkageInfo Lnk = Target->getLinkageAndVisibility();
13429
- if (Lnk.getVisibility() != HiddenVisibility)
13430
- return false;
13431
-
13432
- // If the obj doesn't have external linkage, it's supposed to be duplicated.
13433
- if (!isExternalFormalLinkage(Lnk.getLinkage()))
13434
- return false;
13435
-
13436
- return true;
13437
- }
13438
-
13439
13383
void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
13440
13384
// If there is no declaration, there was an error parsing it. Just ignore
13441
13385
// the initializer.
@@ -14842,51 +14786,6 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
14842
14786
if (DC->getRedeclContext()->isFileContext() && VD->isExternallyVisible())
14843
14787
AddPushedVisibilityAttribute(VD);
14844
14788
14845
- // If this object has external linkage and hidden visibility, it might be
14846
- // duplicated when built into a shared library, which causes problems if it's
14847
- // mutable (since the copies won't be in sync) or its initialization has side
14848
- // effects (since it will run once per copy instead of once globally)
14849
- // FIXME: Windows uses dllexport/dllimport instead of visibility, and we don't
14850
- // handle that yet. Disable the warning on Windows for now.
14851
- // FIXME: Checking templates can cause false positives if the template in
14852
- // question is never instantiated (e.g. only specialized templates are used).
14853
- if (!Context.getTargetInfo().shouldDLLImportComdatSymbols() &&
14854
- !VD->isTemplated() &&
14855
- GloballyUniqueObjectMightBeAccidentallyDuplicated(VD)) {
14856
- // Check mutability. For pointers, ensure that both the pointer and the
14857
- // pointee are (recursively) const.
14858
- QualType Type = VD->getType().getNonReferenceType();
14859
- if (!Type.isConstant(VD->getASTContext())) {
14860
- Diag(VD->getLocation(), diag::warn_possible_object_duplication_mutable)
14861
- << VD;
14862
- } else {
14863
- while (Type->isPointerType()) {
14864
- Type = Type->getPointeeType();
14865
- if (Type->isFunctionType())
14866
- break;
14867
- if (!Type.isConstant(VD->getASTContext())) {
14868
- Diag(VD->getLocation(),
14869
- diag::warn_possible_object_duplication_mutable)
14870
- << VD;
14871
- break;
14872
- }
14873
- }
14874
- }
14875
-
14876
- // To keep false positives low, only warn if we're certain that the
14877
- // initializer has side effects. Don't warn on operator new, since a mutable
14878
- // pointer will trigger the previous warning, and an immutable pointer
14879
- // getting duplicated just results in a little extra memory usage.
14880
- const Expr *Init = VD->getAnyInitializer();
14881
- if (Init &&
14882
- Init->HasSideEffects(VD->getASTContext(),
14883
- /*IncludePossibleEffects=*/false) &&
14884
- !isa<CXXNewExpr>(Init->IgnoreParenImpCasts())) {
14885
- Diag(Init->getExprLoc(), diag::warn_possible_object_duplication_init)
14886
- << VD;
14887
- }
14888
- }
14889
-
14890
14789
// FIXME: Warn on unused var template partial specializations.
14891
14790
if (VD->isFileVarDecl() && !isa<VarTemplatePartialSpecializationDecl>(VD))
14892
14791
MarkUnusedFileScopedDecl(VD);
0 commit comments