r220585 - CodeGen: GLValue exprs in template parameters should have reference type

David Majnemer david.majnemer at gmail.com
Fri Oct 24 12:49:05 PDT 2014


Author: majnemer
Date: Fri Oct 24 14:49:04 2014
New Revision: 220585

URL: http://llvm.org/viewvc/llvm-project?rev=220585&view=rev
Log:
CodeGen: GLValue exprs in template parameters should have reference type

This fixes a corner-case where __uuidof as a template argument would
result in us trying to emit a GLValue as an RValue.  This would lead to
a crash down the road.

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/test/CodeGenCXX/debug-info-uuid.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=220585&r1=220584&r2=220585&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Oct 24 14:49:04 2014
@@ -1324,6 +1324,8 @@ CollectTemplateParams(const TemplatePara
     case TemplateArgument::Expression: {
       const Expr *E = TA.getAsExpr();
       QualType T = E->getType();
+      if (E->isGLValue())
+        T = CGM.getContext().getLValueReferenceType(T);
       llvm::Value *V = CGM.EmitConstantExpr(E, T);
       assert(V && "Expression in template argument isn't constant");
       llvm::DIType TTy = getOrCreateType(T, Unit);

Modified: cfe/trunk/test/CodeGenCXX/debug-info-uuid.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-uuid.cpp?rev=220585&r1=220584&r2=220585&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-uuid.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-uuid.cpp Fri Oct 24 14:49:04 2014
@@ -8,7 +8,13 @@
 // CHECK: [[CONST_GUID]] = {{.*}}, metadata [[GUID:![0-9]*]]} ; [ DW_TAG_const_type ] [line 0, size 0, align 0, offset 0] [from _GUID]
 // CHECK: [[GUID]] = {{.*}} ; [ DW_TAG_structure_type ] [_GUID]
 
+// CHECK: metadata [[TGI2ARGS:![0-9]*]], null} ; [ DW_TAG_structure_type ] [tmpl_guid2<__uuidof(uuid)>]
+// CHECK: [[TGI2ARGS]] = metadata !{metadata [[TGI2ARG1:![0-9]*]]}
+// CHECK: [[TGI2ARG1]] = metadata !{metadata !"0x30\00\00{{.*}}", {{[^,]+}}, metadata [[CONST_GUID_REF:![0-9]*]], { i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab, {{.*}} ; [ DW_TAG_template_value_parameter ]
+// CHECK: [[CONST_GUID_REF]] = {{.*}}, metadata [[CONST_GUID:![0-9]*]]} ; [ DW_TAG_reference_type ] [line 0, size 0, align 0, offset 0] [from ]
+
 // CHECK-ITANIUM: metadata !"_ZTS9tmpl_guidIXadu8__uuidoft4uuidEE"} ; [ DW_TAG_structure_type ] [tmpl_guid<&__uuidof(uuid)>]
+// CHECK-ITANIUM: metadata !"_ZTS10tmpl_guid2IXu8__uuidoft4uuidEE"} ; [ DW_TAG_structure_type ] [tmpl_guid2<__uuidof(uuid)>]
 
 struct _GUID;
 template <const _GUID *>
@@ -17,3 +23,7 @@ struct tmpl_guid {
 
 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ab}")) uuid;
 tmpl_guid<&__uuidof(uuid)> tgi;
+
+template <const _GUID &>
+struct tmpl_guid2 {};
+tmpl_guid2<__uuidof(uuid)> tgi2;





More information about the cfe-commits mailing list