<div class="gmail_quote">On Thu, Jun 7, 2012 at 9:21 PM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><br>
On Jun 7, 2012, at 6:19 PM, Richard Trieu wrote:<br>
<br>
> This patch extends the loops checks that originally only had checked for-loops to also check while and do-while loops.  Changes are:<br>
><br>
> - Add a bit to VarDecl to keep track if a variable has been passed by reference (but not const reference) or had its address taken.<br>
<br>
</div>This particular bit should be separated from the rest of the patch, because it's generally useful on its own and will need a bit more scrutiny/validation/testing. In particular, this<br>
<br>
Index: include/clang/AST/Expr.h<br>
===================================================================<br>
--- include/clang/AST/Expr.h    (revision 158039)<br>
+++ include/clang/AST/Expr.h    (working copy)<br>
@@ -1545,7 +1545,12 @@<br>
            (input->isInstantiationDependent() ||<br>
             type->isInstantiationDependentType()),<br>
            input->containsUnexpandedParameterPack()),<br>
-      Opc(opc), Loc(l), Val(input) {}<br>
+      Opc(opc), Loc(l), Val(input) {<br>
+    if (opc == UO_AddrOf)<br>
+      if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(input->IgnoreParens()))<br>
+        if (VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl()))<br>
+          VD->setReference(true);<br>
+  }<br>
<br>
is not something we should do in AST. Sema should be in charge of marking the 'address taken' bit, and should do so for any of the constructs---implicit or explicit---that take the address of a variable. And if we're going to add this AddressTaken bit, we need to find a good way to validate that it is correct, because it could be useful elsewhere (e.g., in IR generation).<br>



<div><br></div></blockquote><div>I'll be splitting this patch up soon and finding a better location checking the address of part.  I didn't think about other code being interested in this bit as well.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div>
<br>
> - If the bit above is set on a variable, do not emit the warning.  Also, don't emit the warning for parameter variables in while loops.<br>
> - Don't warn on variable declared inside a conditional.<br>
> - Don't warn when there is a function call to a noreturn function inside the loop.<br>
<br>
</div>@@ -1196,7 +1149,6 @@<br>
   class DeclMatcher : public EvaluatedExprVisitor<DeclMatcher> {<br>
     llvm::SmallPtrSet<VarDecl*, 8> &Decls;<br>
     bool FoundDecl;<br>
-    //bool EvalDecl;<br>
<br>
 public:<br>
   typedef EvaluatedExprVisitor<DeclMatcher> Inherited;<br>
<br>
Orphan declaration here?<br></blockquote><div>Forgot to clean that up when I submitted the original patch.  Removed in r158225. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<br>
The rest (= the parts that don't introduce, set, or use the new 'HasReference' bit) looks okay.<br></blockquote><div><br></div><div>Thanks for the fast review.  I think it's best to hold off committing until both parts are ready.  The 'HasReference' bit helps with a common code pattern in threaded code.</div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
        - Doug<br>
</blockquote></div><br>