diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index ab8f6637d6ce..cc97d19a5a0f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1001,7 +1001,7 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, const Decl *D = GD.getDecl(); if (const FunctionDecl *FD = dyn_cast(D)) { Name = getFunctionName(FD); - if (Name[0] == '\01') + if (!Name.empty() && Name[0] == '\01') Name = Name.substr(1); // Use mangled name as linkage name for c/c++ functions. LinkageName = CGM.getMangledName(GD); diff --git a/clang/test/CodeGenCXX/debug-info.cpp b/clang/test/CodeGenCXX/debug-info.cpp index 705491e3a9b4..cb6e830a49e0 100644 --- a/clang/test/CodeGenCXX/debug-info.cpp +++ b/clang/test/CodeGenCXX/debug-info.cpp @@ -18,3 +18,9 @@ void f() { int B::*a = 0; void (B::*b)() = 0; } + +namespace EmptyNameCrash { + struct A { A(); }; + typedef struct { A x; } B; + B x; +}