From 15d397ff14e322428f9d7cda7b9a8d4087ef1b62 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Sat, 8 Jun 2019 00:01:21 +0000 Subject: [PATCH] DebugInfo: Add support for 'nodebug' attribute on typedefs and alias templates Seems like a logical extension to me - and of interest because it might help reduce the debug info size of libc++ by applying this attribute to type traits that have a disproportionate debug info cost compared to the benefit (& possibly harm/confusion) they cause users. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362856 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Attr.td | 2 +- lib/CodeGen/CGDebugInfo.cpp | 24 ++++++++++++------- test/CodeGenCXX/debug-info-nodebug.cpp | 16 +++++++++++-- ...a-attribute-supported-attributes-list.test | 2 +- test/Sema/attr-nodebug.c | 2 +- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index c20a56532d..9e2d5c63fb 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -1434,7 +1434,7 @@ def NoCommon : InheritableAttr { def NoDebug : InheritableAttr { let Spellings = [GCC<"nodebug">]; - let Subjects = SubjectList<[FunctionLike, ObjCMethod, NonParmVar]>; + let Subjects = SubjectList<[TypedefName, FunctionLike, ObjCMethod, NonParmVar]>; let Documentation = [NoDebugDocs]; } diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index a297025547..549056dad4 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1091,15 +1091,18 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty, assert(Ty->isTypeAlias()); llvm::DIType *Src = getOrCreateType(Ty->getAliasedType(), Unit); + auto *AliasDecl = + cast(Ty->getTemplateName().getAsTemplateDecl()) + ->getTemplatedDecl(); + + if (AliasDecl->hasAttr()) + return Src; + SmallString<128> NS; llvm::raw_svector_ostream OS(NS); Ty->getTemplateName().print(OS, getPrintingPolicy(), /*qualified*/ false); printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy()); - auto *AliasDecl = - cast(Ty->getTemplateName().getAsTemplateDecl()) - ->getTemplatedDecl(); - SourceLocation Loc = AliasDecl->getLocation(); return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc), getLineNumber(Loc), @@ -1108,15 +1111,20 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty, llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty, llvm::DIFile *Unit) { + llvm::DIType *Underlying = + getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit); + + if (Ty->getDecl()->hasAttr()) + return Underlying; + // We don't set size information, but do specify where the typedef was // declared. SourceLocation Loc = Ty->getDecl()->getLocation(); // Typedefs are derived from some other type. - return DBuilder.createTypedef( - getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit), - Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc), - getDeclContextDescriptor(Ty->getDecl())); + return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(), + getOrCreateFile(Loc), getLineNumber(Loc), + getDeclContextDescriptor(Ty->getDecl())); } static unsigned getDwarfCC(CallingConv CC) { diff --git a/test/CodeGenCXX/debug-info-nodebug.cpp b/test/CodeGenCXX/debug-info-nodebug.cpp index 9f140efaed..1962b8cf57 100644 --- a/test/CodeGenCXX/debug-info-nodebug.cpp +++ b/test/CodeGenCXX/debug-info-nodebug.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -DSETNODEBUG=0 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=YESINFO -// RUN: %clang_cc1 -DSETNODEBUG=1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=NOINFO +// RUN: %clang_cc1 -DSETNODEBUG=0 -emit-llvm -std=c++14 -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=YESINFO +// RUN: %clang_cc1 -DSETNODEBUG=1 -emit-llvm -std=c++14 -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=NOINFO #if SETNODEBUG #define NODEBUG __attribute__((nodebug)) @@ -53,3 +53,15 @@ void func4() { // NOINFO-NOT: !DIGlobalVariable(name: "static_local" // YESINFO-DAG: !DILocalVariable(name: "normal_local" // NOINFO-NOT: !DILocalVariable(name: "normal_local" + +template +using y NODEBUG = int; +void func5() { + NODEBUG typedef int x; + x a; + y b; +} +// YESINFO-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "x" +// NOINFO-NOT: !DIDerivedType(tag: DW_TAG_typedef, name: "x" +// YESINFO-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "y" +// NOINFO-NOT: !DIDerivedType(tag: DW_TAG_typedef, name: "y" diff --git a/test/Misc/pragma-attribute-supported-attributes-list.test b/test/Misc/pragma-attribute-supported-attributes-list.test index 6e07e8e811..aa71e0bc8f 100644 --- a/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/test/Misc/pragma-attribute-supported-attributes-list.test @@ -72,7 +72,7 @@ // CHECK-NEXT: NSConsumesSelf (SubjectMatchRule_objc_method) // CHECK-NEXT: Naked (SubjectMatchRule_function) // CHECK-NEXT: NoCommon (SubjectMatchRule_variable) -// CHECK-NEXT: NoDebug (SubjectMatchRule_hasType_functionType, SubjectMatchRule_objc_method, SubjectMatchRule_variable_not_is_parameter) +// CHECK-NEXT: NoDebug (SubjectMatchRule_type_alias, SubjectMatchRule_hasType_functionType, SubjectMatchRule_objc_method, SubjectMatchRule_variable_not_is_parameter) // CHECK-NEXT: NoDestroy (SubjectMatchRule_variable) // CHECK-NEXT: NoDuplicate (SubjectMatchRule_function) // CHECK-NEXT: NoEscape (SubjectMatchRule_variable_is_parameter) diff --git a/test/Sema/attr-nodebug.c b/test/Sema/attr-nodebug.c index 355778411d..3ae894a8d0 100644 --- a/test/Sema/attr-nodebug.c +++ b/test/Sema/attr-nodebug.c @@ -2,7 +2,7 @@ int a __attribute__((nodebug)); -void b(int p __attribute__((nodebug))) { // expected-warning {{'nodebug' attribute only applies to functions, function pointers, Objective-C methods, and variables}} +void b(int p __attribute__((nodebug))) { // expected-warning {{'nodebug' attribute only applies to typedefs, functions, function pointers, Objective-C methods, and variables}} int b __attribute__((nodebug)); } -- 2.40.0