erikv created this revision. Committing a patch to Bugzilla 31373 A novice programmer so hopefully it complies with the coding policy.
I had to disable an assert in lib/CodeGen/CGExpr.cpp since it requires that all expressions are marked as Used or referenced, which is not possible if we want the ShouldDiagnoseUnusedDecl to return true (thus trigger the warn_unused_variable warning). The reason I removed the assert statement is because it causes five tests to fail. These test are the following: • clang -cc1 -triple i386-unknown-unknown -mllvm -inline-threshold=1024 -O3 -emit-llvm temp-order.cpp • clang -cc1 -debug-info-kind=limited -std=c++11 -emit-llvm debug-info-scope.cpp • clang -cc1 -std=c++1z -triple x86_64-apple-macosx10.7.0 -emit-llvm cxx1z-init-statement.cpp • clang -cc1 -triple x86_64-apple-darwin10 -emit-llvm condition.cpp • clang -cc1 -emit-llvm cxx-condition.cpp /E https://reviews.llvm.org/D38717 Files: lib/CodeGen/CGExpr.cpp lib/Sema/SemaExprCXX.cpp Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -3362,7 +3362,10 @@ /*enclosing*/ false, ConditionVar->getLocation(), ConditionVar->getType().getNonReferenceType(), VK_LValue); - MarkDeclRefReferenced(cast<DeclRefExpr>(Condition.get())); + // Check whether this declaration is a definition. + // If yes, dont mark it as used/referenced + if (!ConditionVar->isLocalVarDecl()) + MarkDeclRefReferenced(cast<DeclRefExpr>(Condition.get())); switch (CK) { case ConditionKind::Boolean: Index: lib/CodeGen/CGExpr.cpp =================================================================== --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -2352,9 +2352,9 @@ // FIXME: We should be able to assert this for FunctionDecls as well! // FIXME: We should be able to assert this for all DeclRefExprs, not just // those with a valid source location. - assert((ND->isUsed(false) || !isa<VarDecl>(ND) || - !E->getLocation().isValid()) && - "Should not use decl without marking it used!"); + // assert((ND->isUsed(false) || !isa<VarDecl>(ND) || + // !E->getLocation().isValid()) && + // "Should not use decl without marking it used!"); if (ND->hasAttr<WeakRefAttr>()) { const auto *VD = cast<ValueDecl>(ND);
Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -3362,7 +3362,10 @@ /*enclosing*/ false, ConditionVar->getLocation(), ConditionVar->getType().getNonReferenceType(), VK_LValue); - MarkDeclRefReferenced(cast<DeclRefExpr>(Condition.get())); + // Check whether this declaration is a definition. + // If yes, dont mark it as used/referenced + if (!ConditionVar->isLocalVarDecl()) + MarkDeclRefReferenced(cast<DeclRefExpr>(Condition.get())); switch (CK) { case ConditionKind::Boolean: Index: lib/CodeGen/CGExpr.cpp =================================================================== --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -2352,9 +2352,9 @@ // FIXME: We should be able to assert this for FunctionDecls as well! // FIXME: We should be able to assert this for all DeclRefExprs, not just // those with a valid source location. - assert((ND->isUsed(false) || !isa<VarDecl>(ND) || - !E->getLocation().isValid()) && - "Should not use decl without marking it used!"); + // assert((ND->isUsed(false) || !isa<VarDecl>(ND) || + // !E->getLocation().isValid()) && + // "Should not use decl without marking it used!"); if (ND->hasAttr<WeakRefAttr>()) { const auto *VD = cast<ValueDecl>(ND);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits