<div dir="ltr"><div>Hi Manuel,<br><br>Thank you for the comments! The patch is updated.<br><br></div>For the test, I am only testing visiting the parameter of implicit copy assignment function. The same test visitor can be reused to test visiting parameter of other implicit functions like copy / move constructors. I am only testing copy assignment operator in this patch because other implicit functions have the same problem that needs to be fixed, and if my fix in this patch is the right approach I will apply the fix to other implicit functions as well, and add then add more tests.<br>
<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 11, 2013 at 11:37 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5">On Tue, Jun 11, 2013 at 10:31 PM, Michael Han <span dir="ltr"><<a href="mailto:fragmentshaders@gmail.com" target="_blank">fragmentshaders@gmail.com</a>></span> wrote:<br>
</div></div><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi klimek, rsmith,<br>
<br>
This patch fixes PR16182<br>
<a href="http://llvm.org/bugs/show_bug.cgi?id=16182" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=16182</a><br>
<br>
A valid TypeSourceInfo of a function is required for the RAV to visit the parameter declaration of the function, and previously we don't have a valid TypeSourceInfo when creating the function declaration of implicit copy assignment operator.<br>


<br>
This patch fixes this by building a TypeSourceInfo from the function prototype of copy assignment operator and associate its ParmVarDecl with this function type location.<br>
<br>
The test is done by matching that an empty name (we don't have a name for the parameter of the implicit copy assignment function) appears at expect location, which is the source location of the class that is also used as the location of the implicit copy assignment function.<br>


<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D958" target="_blank">http://llvm-reviews.chandlerc.com/D958</a><br>
<br>
Files:<br>
  unittests/Tooling/TestVisitor.h<br>
  unittests/Tooling/RecursiveASTVisitorTest.cpp<br>
  lib/Sema/SemaDeclCXX.cpp<br>
<br>
Index: unittests/Tooling/TestVisitor.h<br>
===================================================================<br>
--- unittests/Tooling/TestVisitor.h<br>
+++ unittests/Tooling/TestVisitor.h<br>
@@ -31,7 +31,7 @@<br>
 /// This is a drop-in replacement for RecursiveASTVisitor itself, with the<br>
 /// additional capability of running it over a snippet of code.<br>
 ///<br>
-/// Visits template instantiations (but not implicit code) by default.<br>
+/// Visits template instantiations and implicit code by default.<br>
 template <typename T><br>
 class TestVisitor : public RecursiveASTVisitor<T> {<br>
 public:<br>
@@ -55,6 +55,10 @@<br>
     return true;<br>
   }<br>
<br>
+  bool shouldVisitImplicitCode() const {<br>
+    return true;<br>
+  }<br>
+<br>
 protected:<br>
   virtual ASTFrontendAction* CreateTestAction() {<br>
     return new TestAction(this);<br>
Index: unittests/Tooling/RecursiveASTVisitorTest.cpp<br>
===================================================================<br>
--- unittests/Tooling/RecursiveASTVisitorTest.cpp<br>
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp<br>
@@ -35,6 +35,14 @@<br>
  }<br>
 };<br>
<br>
+class ParmVarDeclVisitor : public ExpectedLocationVisitor<ParmVarDeclVisitor> {<br>
+public:<br>
+  bool VisitParmVarDecl(ParmVarDecl *ParamVar) {<br>
+    Match(ParamVar->getNameAsString(), ParamVar->getLocStart());<br>
+    return true;<br>
+  }<br>
+};<br>
+<br>
 class CXXMemberCallVisitor<br>
   : public ExpectedLocationVisitor<CXXMemberCallVisitor> {<br>
 public:<br>
@@ -106,6 +114,14 @@<br>
   }<br>
 };<br>
<br>
+TEST(RecursiveASTVisitor, VisitsParmVarDecl) {<br>
+  ParmVarDeclVisitor Visitor;</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">+  Visitor.ExpectMatch("", 1, 7);<br>

</blockquote><div><br></div></div></div><div>First, I'd call this test VisitsParmVarDeclForImplicitCode.</div><div>Seconds, you're testing that it visits any parameter, not the one for operator==, right?</div><div>
<br></div><div>
I'd also add a short comment explaining this test - if I didn't know the full context, I'd have a hard time figuring out what it does. Especially explain why the name is empty, and why the position is expected to point to the class definition.</div>

<div><br></div><div>I'll let Richard speak for the non-test portion of this patch :)</div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


+  EXPECT_TRUE(Visitor.runOver(<br>
+    "class X {};\n"<br>
+    "void foo(X a, X b) {a = b;}"));<br>
+}<br>
+<br>
 TEST(RecursiveASTVisitor, VisitsBaseClassDeclarations) {<br>
   TypeLocVisitor Visitor;<br>
   Visitor.ExpectMatch("class X", 1, 30);<br>
Index: lib/Sema/SemaDeclCXX.cpp<br>
===================================================================<br>
--- lib/Sema/SemaDeclCXX.cpp<br>
+++ lib/Sema/SemaDeclCXX.cpp<br>
@@ -8788,14 +8788,24 @@<br>
   FunctionProtoType::ExtProtoInfo EPI;<br>
   EPI.ExceptionSpecType = EST_Unevaluated;<br>
   EPI.ExceptionSpecDecl = CopyAssignment;<br>
-  CopyAssignment->setType(Context.getFunctionType(RetType, ArgType, EPI));<br>
+  QualType T = Context.getFunctionType(RetType, ArgType, EPI);<br>
+  CopyAssignment->setType(T);<br>
<br>
+  // PR16182. Build type source info for copy assignment operator. RAV relies on<br>
+  // type source info to traverse parameter declaration of implicit<br>
+  // declared copy assignment operator.<br>
+  TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, ClassLoc);<br>
+  CopyAssignment->setTypeSourceInfo(TSInfo);<br>
+  UnqualTypeLoc UnQualTL = TSInfo->getTypeLoc().getUnqualifiedLoc();<br>
+  FunctionTypeLoc FTL = UnQualTL.getAs<FunctionTypeLoc>();<br>
+<br>
   // Add the parameter to the operator.<br>
   ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyAssignment,<br>
                                                ClassLoc, ClassLoc, /*Id=*/0,<br>
                                                ArgType, /*TInfo=*/0,<br>
                                                SC_None, 0);<br>
   CopyAssignment->setParams(FromParam);<br>
+  FTL.setArg(0, FromParam);<br>
<br>
   AddOverriddenMethods(ClassDecl, CopyAssignment);<br>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div>