ABataev created this revision.
ABataev added a reviewer: echristo.
ABataev added a subscriber: cfe-commits.

Currently debug info for types used in explicit cast only is not emitted. It 
happened after a patch for better alignment handling. This patch fixes this bug.

http://reviews.llvm.org/D13582

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenCXX/debug-info-explicit-cast.cpp

Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -799,6 +799,10 @@
     if (E->getType()->isVariablyModifiedType())
       EmitVariablyModifiedType(E->getType());
 
+    if (isa<ExplicitCastExpr>(CE))
+      if (CGDebugInfo *DI = getDebugInfo())
+        DI->EmitExplicitCastType(E->getType());
+
     switch (CE->getCastKind()) {
     // Non-converting casts (but not C's implicit conversion from void*).
     case CK_BitCast:
Index: test/CodeGenCXX/debug-info-explicit-cast.cpp
===================================================================
--- test/CodeGenCXX/debug-info-explicit-cast.cpp
+++ test/CodeGenCXX/debug-info-explicit-cast.cpp
@@ -0,0 +1,18 @@
+// RUN: %clangxx -c -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck %s
+struct Foo {
+  int a;
+  Foo() : a(1){};
+};
+
+struct Bar {
+  int b;
+  Bar() : b(2){};
+};
+
+int main() {
+  Bar *pb = new Bar;
+
+  return reinterpret_cast<Foo *>(pb)->a;
+}
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo",


Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -799,6 +799,10 @@
     if (E->getType()->isVariablyModifiedType())
       EmitVariablyModifiedType(E->getType());
 
+    if (isa<ExplicitCastExpr>(CE))
+      if (CGDebugInfo *DI = getDebugInfo())
+        DI->EmitExplicitCastType(E->getType());
+
     switch (CE->getCastKind()) {
     // Non-converting casts (but not C's implicit conversion from void*).
     case CK_BitCast:
Index: test/CodeGenCXX/debug-info-explicit-cast.cpp
===================================================================
--- test/CodeGenCXX/debug-info-explicit-cast.cpp
+++ test/CodeGenCXX/debug-info-explicit-cast.cpp
@@ -0,0 +1,18 @@
+// RUN: %clangxx -c -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s
+struct Foo {
+  int a;
+  Foo() : a(1){};
+};
+
+struct Bar {
+  int b;
+  Bar() : b(2){};
+};
+
+int main() {
+  Bar *pb = new Bar;
+
+  return reinterpret_cast<Foo *>(pb)->a;
+}
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo",
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to