From 1741d118bf6aea742c37d78500539616c1ffc8af Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 25 Feb 2014 19:38:11 +0000 Subject: [PATCH] Debug info: Generate debug info for variadic functions. Paired commit with LLVM. rdar://problem/13690847 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202185 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 16 ++++++++++++++++ test/CodeGenCXX/debug-info-varargs.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/CodeGenCXX/debug-info-varargs.cpp diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index a72f9e6bf7..2de4dde127 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -765,6 +765,8 @@ llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, else if (const FunctionProtoType *FPT = dyn_cast(Ty)) { for (unsigned i = 0, e = FPT->getNumParams(); i != e; ++i) EltTys.push_back(getOrCreateType(FPT->getParamType(i), Unit)); + if (FPT->isVariadic()) + EltTys.push_back(DBuilder.createUnspecifiedParameter()); } llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(EltTys); @@ -2437,6 +2439,20 @@ llvm::DICompositeType CGDebugInfo::getOrCreateFunctionType(const Decl *D, llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts); return DBuilder.createSubroutineType(F, EltTypeArray); } + + // Variadic function. + if (const FunctionDecl *FD = dyn_cast(D)) + if (FD->isVariadic()) { + SmallVector EltTys; + EltTys.push_back(getOrCreateType(FD->getReturnType(), F)); + if (const FunctionProtoType *FPT = dyn_cast(FnType)) + for (unsigned i = 0, e = FPT->getNumParams(); i != e; ++i) + EltTys.push_back(getOrCreateType(FPT->getParamType(i), F)); + EltTys.push_back(DBuilder.createUnspecifiedParameter()); + llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(EltTys); + return DBuilder.createSubroutineType(F, EltTypeArray); + } + return llvm::DICompositeType(getOrCreateType(FnType, F)); } diff --git a/test/CodeGenCXX/debug-info-varargs.cpp b/test/CodeGenCXX/debug-info-varargs.cpp new file mode 100644 index 0000000000..de469642be --- /dev/null +++ b/test/CodeGenCXX/debug-info-varargs.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -emit-llvm -g %s -o - | FileCheck %s + +struct A +{ + // CHECK-DAG: ", i32 [[@LINE+1]], metadata ![[ATY:[0-9]+]]{{.*}}[ DW_TAG_subprogram ]{{.*}}[a] + void a(int c, ...) {} + // CHECK-DAG: ![[ATY]] ={{.*}} metadata ![[AARGS:[0-9]+]], i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] + // CHECK-DAG: ![[AARGS]] = {{.*}} metadata ![[UNSPEC:[0-9]+]]} + // CHECK-DAG: ![[UNSPEC]] = metadata !{i32 786456} +}; + + // CHECK-DAG: ", i32 [[@LINE+1]], metadata ![[BTY:[0-9]+]]{{.*}}[ DW_TAG_subprogram ]{{.*}}[b] +void b(int c, ...) { + // CHECK-DAG: ![[BTY]] ={{.*}} metadata ![[BARGS:[0-9]+]], i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] + // CHECK-DAG: ![[BARGS]] = {{.*}} metadata ![[UNSPEC:[0-9]+]]} + + A a; + + // CHECK-DAG: metadata ![[PST:[0-9]+]], i32 0, i32 0} ; [ DW_TAG_auto_variable ] [fptr] [line [[@LINE+1]]] + void (*fptr)(int, ...) = b; + // CHECK-DAG: ![[PST]] ={{.*}} metadata ![[ST:[0-9]+]]} ; [ DW_TAG_pointer_type ] + // CHECK-DAG: ![[ST]] ={{.*}} metadata ![[ARGS:[0-9]+]], i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] + // CHECK-DAG: ![[ARGS]] = {{.*}} metadata ![[UNSPEC]]} +} -- 2.40.0