diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index cda279a39f0bb..c5560a1c82f4f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -6027,6 +6027,18 @@ bool clang::CodeGen::noSystemDebugInfo(const Decl *D, const CodeGenModule &CGM) { // Declaration is in system file if (CGM.getContext().getSourceManager().isInSystemHeader(D->getLocation())) { + // Make an exception for typedefs in system header files. Generate debug + // information for these decls because these are rare (thus they will not + // greatly increase debug size) and a user could rely on these typedefs + // during debugging. For example uid_t in in "sys/types.h" can be used in + // the gdb command: + // + // print ruid == (uid_t)-1 + // + // This occurs in GDB test gdb.reverse/getresuid-reverse.c + if (isa(D)) + return false; + // -fno-system-debug was used. Do not generate debug info. if (CGM.getCodeGenOpts().NoSystemDebug) return true; diff --git a/clang/test/CodeGen/debug-info-system-typedef.c b/clang/test/CodeGen/debug-info-system-typedef.c new file mode 100644 index 0000000000000..e87148a5f5eeb --- /dev/null +++ b/clang/test/CodeGen/debug-info-system-typedef.c @@ -0,0 +1,25 @@ +// Ensure that debug info for typedefs in system headers is still generated +// even if -fno-system-debug is used. This is justified because debug size +// savings is small, but debugging is commonly done with types that are +// typedef-ed in system headers. Thus, the increased debuggability +// is worth the small extra cost. + +// RUN: %clang -fno-system-debug -emit-llvm -S -g %s -o %t.ll + +// RUN: FileCheck %s < %t.ll + +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "gid_t", +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "__gid_t", +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "uid_t", +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "__uid_t", + +#include + +uid_t xuid; +gid_t xgid; + +int +main (void) +{ + return 0; +}