Index: llvm/tools/clang/lib/CodeGen/CGDebugInfo.h =================================================================== --- llvm/tools/clang/lib/CodeGen/CGDebugInfo.h +++ llvm/tools/clang/lib/CodeGen/CGDebugInfo.h @@ -283,6 +283,9 @@ /// \brief - Emit C++ using directive. void EmitUsingDirective(const UsingDirectiveDecl &UD); + /// EmitExplicitCastType - Emit the type explicitly casted to. + void EmitExplicitCastType(QualType Ty); + /// \brief - Emit C++ using declaration. void EmitUsingDecl(const UsingDecl &UD); Index: llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp +++ llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp @@ -3347,3 +3347,11 @@ DBuilder.finalize(); } + +void CGDebugInfo::EmitExplicitCastType(QualType Ty) { + if (CGM.getCodeGenOpts().getDebugInfo() < CodeGenOptions::LimitedDebugInfo) + return; + llvm::DIType DieTy = getOrCreateType(Ty, getOrCreateMainFile()); + // Don't ignore in case of explicit cast where it is referenced indirectly. + DBuilder.retainType(DieTy); +} Index: llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp =================================================================== --- llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp +++ llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp @@ -274,6 +274,10 @@ Value *VisitExplicitCastExpr(ExplicitCastExpr *E) { if (E->getType()->isVariablyModifiedType()) CGF.EmitVariablyModifiedType(E->getType()); + + if (CGDebugInfo *DI = CGF.getDebugInfo()) + DI->EmitExplicitCastType(E->getType()); + return VisitCastExpr(E); } Value *VisitCastExpr(CastExpr *E); Index: llvm/tools/clang/test/CodeGen/debug-info-explicitcast.c =================================================================== --- llvm/tools/clang/test/CodeGen/debug-info-explicitcast.c +++ llvm/tools/clang/test/CodeGen/debug-info-explicitcast.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm -g %s -o - | FileCheck %s + +struct S { + int i; +}; +void foo(void *p) { ((struct S *)p)->i++; } + +// CHECK: DW_TAG_structure_type ] [S] +