[PATCH] D38717: Patch to Bugzilla 31373

Erik Viktorsson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 10 02:38:09 PDT 2017


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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38717.118334.patch
Type: text/x-patch
Size: 1390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171010/3e09a150/attachment.bin>


More information about the cfe-commits mailing list