r189165 - DebugInfo: Emit info for constant expressions in template arguments

David Majnemer david.majnemer at gmail.com
Sat Aug 24 01:21:11 PDT 2013


Author: majnemer
Date: Sat Aug 24 03:21:10 2013
New Revision: 189165

URL: http://llvm.org/viewvc/llvm-project?rev=189165&view=rev
Log:
DebugInfo: Emit info for constant expressions in template arguments

Summary:
This allows us to handle the general case where a non-type template
argument evaluates to a constant expression which isn't integral or a
declaration.

This fixes PR16939.

Reviewers: dblaikie, rsmith

Reviewed By: dblaikie

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1453

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=189165&r1=189164&r2=189165&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Sat Aug 24 03:21:10 2013
@@ -1297,8 +1297,18 @@ CollectTemplateParams(const TemplatePara
               CollectTemplateParams(NULL, TA.getPackAsArray(), Unit));
       TemplateParams.push_back(TVP);
     } break;
+    case TemplateArgument::Expression: {
+      const Expr *E = TA.getAsExpr();
+      QualType T = E->getType();
+      llvm::Value *V = CGM.EmitConstantExpr(E, T);
+      assert(V && "Expression in template argument isn't constant");
+      llvm::DIType TTy = getOrCreateType(T, Unit);
+      llvm::DITemplateValueParameter TVP =
+          DBuilder.createTemplateValueParameter(TheCU, Name, TTy,
+                                                V->stripPointerCasts());
+      TemplateParams.push_back(TVP);
+    } break;
     // And the following should never occur:
-    case TemplateArgument::Expression:
     case TemplateArgument::TemplateExpansion:
     case TemplateArgument::Null:
       llvm_unreachable(

Modified: cfe/trunk/test/CodeGenCXX/debug-info-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-template.cpp?rev=189165&r1=189164&r2=189165&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-template.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-template.cpp Sat Aug 24 03:21:10 2013
@@ -1,4 +1,4 @@
-// RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++11 | FileCheck %s
+// RUN: %clang -S -emit-llvm -fms-extensions -target x86_64-unknown_unknown -g %s -o - -std=c++11 | FileCheck %s
 
 // CHECK: [[EMPTY:![0-9]*]] = metadata !{i32 0}
 
@@ -69,6 +69,12 @@
 // CHECK: [[TCNARG5]] = {{.*}}metadata !"b", metadata [[MEMFUNPTR]], i8 0, {{.*}} ; [ DW_TAG_template_value_parameter ]
 // 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: metadata [[TGIARGS:![0-9]*]]} ; [ DW_TAG_structure_type ] [tmpl_guid<&__uuidof(uuid)>]
+// CHECK: [[TGIARGS]] = metadata !{metadata [[TGIARG1:![0-9]*]]}
+// CHECK: [[TGIARG1]] = {{.*}}metadata !"", metadata [[CONST_GUID_PTR:![0-9]*]], { i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab, {{.*}} ; [ DW_TAG_template_value_parameter ]
+// CHECK: [[CONST_GUID_PTR]] = {{.*}}, metadata [[CONST_GUID:![0-9]*]]} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from ]
+// 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] [line 100, size 0, align 0, offset 0] [decl]
 struct foo {
   char pad[8]; // make the member pointer to 'e' a bit more interesting (nonzero)
   int e;
@@ -90,3 +96,11 @@ struct tmpl_impl {
 
 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;
+
+struct _GUID;
+template <_GUID *>
+struct tmpl_guid {
+};
+
+struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ab}")) uuid;
+tmpl_guid<&__uuidof(uuid)> tgi;





More information about the cfe-commits mailing list