From 189f311130da38acfe0a3b3b234fc10bd60e34d2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 26 Jan 2021 11:53:25 -0800 Subject: [PATCH] CGDebugInfo CreatedLimitedType: Drop file/line for RecordType with invalid location For Clang synthesized `__va_list_tag` (`CreateX86_64ABIBuiltinVaListDecl`), its DW_AT_decl_file/DW_AT_decl_line are arbitrarily set from `CurLoc`. In a stage 2 `-DCMAKE_BUILD_TYPE=Debug` clang build, I observe that in driver.cpp, DW_AT_decl_file/DW_AT_decl_line may be set to an `#include` line (the transitively included file uses va_arg (`__builtin_va_arg`)). This seems arbitrary. Drop that. Reviewed By: #debug-info, dblaikie Differential Revision: https://reviews.llvm.org/D94735 --- clang/lib/CodeGen/CGDebugInfo.cpp | 10 +++++++--- clang/test/CodeGen/X86/x86_64-arguments.c | 12 +++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 7ca230a..99944af 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -3332,10 +3332,14 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) { RecordDecl *RD = Ty->getDecl(); // Get overall information about the record type for the debug info. - llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation()); - const unsigned Line = - getLineNumber(RD->getLocation().isValid() ? RD->getLocation() : CurLoc); StringRef RDName = getClassName(RD); + const SourceLocation Loc = RD->getLocation(); + llvm::DIFile *DefUnit = nullptr; + unsigned Line = 0; + if (Loc.isValid()) { + DefUnit = getOrCreateFile(Loc); + Line = getLineNumber(Loc); + } llvm::DIScope *RDContext = getDeclContextDescriptor(RD); diff --git a/clang/test/CodeGen/X86/x86_64-arguments.c b/clang/test/CodeGen/X86/x86_64-arguments.c index b51fe01..8898feb 100644 --- a/clang/test/CodeGen/X86/x86_64-arguments.c +++ b/clang/test/CodeGen/X86/x86_64-arguments.c @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | \ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -debug-info-kind=limited -o - %s | \ // RUN: FileCheck %s -check-prefix=CHECK -check-prefix=SSE -check-prefix=NO-AVX512 -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -target-feature +avx | \ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -debug-info-kind=limited -o - %s -target-feature +avx | \ // RUN: FileCheck %s -check-prefix=CHECK -check-prefix=AVX -check-prefix=NO-AVX512 -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -target-feature +avx512f | \ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -debug-info-kind=limited -o - %s -target-feature +avx512f | \ // RUN: FileCheck %s -check-prefix=CHECK -check-prefix=AVX -check-prefix=AVX512 #include @@ -545,3 +545,9 @@ struct t65 { // AVX: @f65(<8 x float> %{{[^,)]+}}) void f65(struct t65 a0) { } + +/// The synthesized __va_list_tag does not have file/line fields. +// CHECK: = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "__va_list_tag", +// CHECK-NOT: file: +// CHECK-NOT: line: +// CHECK-SAME: size: -- 2.7.4