<div dir="ltr"><div>Ping.<br><br>To recap: this patch fixes PR16182 (<a href="http://llvm.org/bugs/show_bug.cgi?id=16182" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=16182</a>). OK to commit?<br><br></div>Thanks.<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 11, 2013 at 1:31 PM, Michael Han <span dir="ltr"><<a href="mailto:fragmentshaders@gmail.com" target="_blank">fragmentshaders@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc 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;<br>
+  Visitor.ExpectMatch("", 1, 7);<br>
+  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><br></div>