Index: llvm/tools/clang/lib/CodeGen/CGDebugInfo.h =================================================================== --- llvm/tools/clang/lib/CodeGen/CGDebugInfo.h +++ llvm/tools/clang/lib/CodeGen/CGDebugInfo.h @@ -267,6 +267,9 @@ /// EmitGlobalVariable - Emit global variable's debug info. void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init); + /// EmitTypeDef - Emit typedef debug info. + void EmitTypeDef(QualType Ty); + /// \brief - Emit C++ using directive. void EmitUsingDirective(const UsingDirectiveDecl &UD); Index: llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp +++ llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp @@ -3276,3 +3276,12 @@ DBuilder.finalize(); } + +void CGDebugInfo::EmitTypeDef(QualType Ty) +{ + llvm::DIType DieTy = getOrCreateType(Ty,getOrCreateMainFile()); + // Don't ignore in case of explicit cast were 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,13 @@ Value *VisitExplicitCastExpr(ExplicitCastExpr *E) { if (E->getType()->isVariablyModifiedType()) CGF.EmitVariablyModifiedType(E->getType()); + if( E->getType().getTypePtr()->getTypeClass() == Type::Typedef) + { + CGDebugInfo *DI = CGF.getDebugInfo(); + if (DI && CGF.CGM.getCodeGenOpts().getDebugInfo() + == CodeGenOptions::LimitedDebugInfo) + DI->EmitTypeDef((E->getType())); + } return VisitCastExpr(E); } Value *VisitCastExpr(CastExpr *E); Index: llvm/tools/clang/test/CodeGen/Debug-info-typedef.cpp =================================================================== --- llvm/tools/clang/test/CodeGen/Debug-info-typedef.cpp +++ llvm/tools/clang/test/CodeGen/Debug-info-typedef.cpp @@ -0,0 +1,13 @@ +// RUN: %clang -fverbose-asm -S -g %s -o - | grep DW_TAG_structure_type +// RUN: %clang -fverbose-asm -S -g %s -o - | grep DW_TAG_typedef +// RUN: %clang -fverbose-asm -S -g %s -o - | grep S +// RUN: %clang -fverbose-asm -S -g %s -o - | grep T + +typedef struct S { int i; } *T; +#define M(p) ((T) (p)) + +void +foo (void* p) +{ + M (p)->i++; +}