Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp	(revision 206253)
+++ clang/lib/CodeGen/CGDebugInfo.cpp	(working copy)
@@ -1251,32 +1251,35 @@
                        : CGM.getContext().getPointerType(D->getType());
       llvm::DIType TTy = getOrCreateType(T, Unit);
       llvm::Value *V = 0;
-      // Variable pointer template parameters have a value that is the address
-      // of the variable.
-      if (const VarDecl *VD = dyn_cast<VarDecl>(D))
-        V = CGM.GetAddrOfGlobalVar(VD);
-      // Member function pointers have special support for building them, though
-      // this is currently unsupported in LLVM CodeGen.
-      if (InstanceMember) {
-        if (const CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(D))
-          V = CGM.getCXXABI().EmitMemberPointer(method);
-      } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
-        V = CGM.GetAddrOfFunction(FD);
-      // Member data pointers have special handling too to compute the fixed
-      // offset within the object.
-      if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) {
-        // These five lines (& possibly the above member function pointer
-        // handling) might be able to be refactored to use similar code in
-        // CodeGenModule::getMemberPointerConstant
-        uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
-        CharUnits chars =
-            CGM.getContext().toCharUnitsFromBits((int64_t) fieldOffset);
-        V = CGM.getCXXABI().EmitMemberDataPointer(
-            cast<MemberPointerType>(T.getTypePtr()), chars);
+      if (TPList && TPList->getParam(i)->isReferenced()) {
+        // Variable pointer template parameters have a value that is the address
+        // of the variable.
+        if (const VarDecl *VD = dyn_cast<VarDecl>(D))
+          V = CGM.GetAddrOfGlobalVar(VD);
+        // Member function pointers have special support for building them,
+        // though this is currently unsupported in LLVM CodeGen.
+        if (InstanceMember) {
+          if (const CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(D))
+            V = CGM.getCXXABI().EmitMemberPointer(method);
+        } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+          V = CGM.GetAddrOfFunction(FD);
+        // Member data pointers have special handling too to compute the fixed
+        // offset within the object.
+        if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) {
+          // These five lines (& possibly the above member function pointer
+          // handling) might be able to be refactored to use similar code in
+          // CodeGenModule::getMemberPointerConstant
+          uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
+          CharUnits chars =
+              CGM.getContext().toCharUnitsFromBits((int64_t) fieldOffset);
+          V = CGM.getCXXABI().EmitMemberDataPointer(
+              cast<MemberPointerType>(T.getTypePtr()), chars);
+        }
       }
+      if (V)
+        V = V->stripPointerCasts();
       llvm::DITemplateValueParameter TVP =
-          DBuilder.createTemplateValueParameter(TheCU, Name, TTy,
-                                                V->stripPointerCasts());
+          DBuilder.createTemplateValueParameter(TheCU, Name, TTy, V);
       TemplateParams.push_back(TVP);
     } break;
     case TemplateArgument::NullPtr: {
Index: clang/test/CodeGenCXX/debug-info-template.cpp
===================================================================
--- clang/test/CodeGenCXX/debug-info-template.cpp	(revision 206253)
+++ clang/test/CodeGenCXX/debug-info-template.cpp	(working copy)
@@ -72,14 +72,23 @@
 // CHECK: [[TCNARG6]] = {{.*}}metadata !"f", metadata [[FUNPTR]], i8 0, {{.*}} ; [ DW_TAG_template_value_parameter ]
 // CHECK: [[TCNARG8]] = {{.*}}metadata !"Is", null, metadata [[EMPTY]], {{.*}} ; [ DW_TAG_GNU_template_parameter_pack ]
 
+// CHECK: [[TCNU:![0-9]*]] = {{.*}}, metadata [[TCNUARGS:![0-9]*]], metadata !"{{.*}}"} ; [ DW_TAG_structure_type ] [TC_nouses<&glb, &foo::e, &foo::f, &func>]
+// CHECK: [[TCNUARGS]] = metadata !{metadata [[TCNUARG1:![0-9]*]], metadata [[TCNUARG2:![0-9]*]], metadata [[TCNUARG3:![0-9]*]], metadata [[TCNUARG4:![0-9]*]]}
+// CHECK: [[TCNUARG1]] = {{.*}}metadata !"x", metadata [[INTPTR]], null, {{.*}} ; [ DW_TAG_template_value_parameter ]
+// CHECK: [[TCNUARG2]] = {{.*}}metadata !"a", metadata [[MEMINTPTR]], null, {{.*}} ; [ DW_TAG_template_value_parameter ]
+// CHECK: [[TCNUARG3]] = {{.*}}metadata !"b", metadata [[MEMFUNPTR]], null, {{.*}} ; [ DW_TAG_template_value_parameter ]
+// CHECK: [[TCNUARG4]] = {{.*}}metadata !"f", metadata [[FUNPTR]], null, {{.*}} ; [ DW_TAG_template_value_parameter ]
+
 // CHECK: metadata [[PTOARGS:![0-9]*]], metadata !"{{.*}}"} ; [ DW_TAG_structure_type ] [PaddingAtEndTemplate<&PaddedObj>]
 // CHECK: [[PTOARGS]] = metadata !{metadata [[PTOARG1:![0-9]*]]}
-// CHECK: [[PTOARG1]] = {{.*}}metadata !"", metadata [[CONST_PADDINGATEND_PTR:![0-9]*]], { i32, i8, [3 x i8] }* @PaddedObj, {{.*}} ; [ DW_TAG_template_value_parameter ]
+// CHECK: [[PTOARG1]] = {{.*}}metadata !"pae", metadata [[CONST_PADDINGATEND_PTR:![0-9]*]], { i32, i8, [3 x i8] }* @PaddedObj, {{.*}} ; [ DW_TAG_template_value_parameter ]
 // CHECK: [[CONST_PADDINGATEND_PTR]] = {{.*}} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from _ZTS12PaddingAtEnd]
 
 // CHECK: metadata !"[[TCNESTED]]", i32 0, i32 1, %"struct.TC<unsigned int, 2, &glb, &foo::e, &foo::f, &func, tmpl_impl, 1, 2, 3>::nested"* @tci, null} ; [ DW_TAG_variable ] [tci]
 
 // CHECK: metadata !"[[TCNT]]", i32 0, i32 1, %struct.TC* @tcn, null} ; [ DW_TAG_variable ] [tcn]
+
+
 struct foo {
   char pad[8]; // make the member pointer to 'e' a bit more interesting (nonzero)
   int e;
@@ -89,6 +98,10 @@
 template<typename T, T, int *x, int foo::*a, void (foo::*b)(), void (*f)(), template<typename> class tmpl, int ...Is>
 struct TC {
   struct nested {
+    int *p = x;
+    int foo::*q = a;
+    void (foo::*r)() = b;
+    void (*s)() = f;
   };
 };
 
@@ -102,6 +115,13 @@
 TC<unsigned, 2, &glb, &foo::e, &foo::f, &func, tmpl_impl, 1, 2, 3>::nested tci;
 TC<int, -3, nullptr, nullptr, nullptr, nullptr, tmpl_impl> tcn;
 
+template<int *x, int foo::*a, void (foo::*b)(), void (*f)()>
+struct TC_nouses {
+  struct nested_nouses {
+  };
+};
+TC_nouses<&glb, &foo::e, &foo::f, &func> tcnu;
+
 struct PaddingAtEnd {
   int i;
   char c;
@@ -109,8 +129,9 @@
 
 PaddingAtEnd PaddedObj = {};
 
-template <const PaddingAtEnd *>
+template <const PaddingAtEnd *pae>
 struct PaddingAtEndTemplate {
+  const PaddingAtEnd *z = pae;
 };
 
 PaddingAtEndTemplate<&PaddedObj> PaddedTemplateObj;
