r272859 - Allow 'nodebug' on local variables.

Paul Robinson via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 15 17:42:36 PDT 2016


Author: probinson
Date: Wed Jun 15 19:42:36 2016
New Revision: 272859

URL: http://llvm.org/viewvc/llvm-project?rev=272859&view=rev
Log:
Allow 'nodebug' on local variables.
Parameters and non-static members of aggregates are still excluded,
and probably should remain that way.

Differential Revision: http://reviews.llvm.org/D19754

Added:
    cfe/trunk/test/CodeGenObjC/debug-info-nodebug.m
Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/include/clang/Basic/AttrDocs.td
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/test/CodeGenCXX/debug-info-nodebug.cpp
    cfe/trunk/test/Sema/attr-nodebug.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=272859&r1=272858&r2=272859&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Jun 15 19:42:36 2016
@@ -82,6 +82,8 @@ def NormalVar : SubsetSubject<Var,
                                 S->getKind() != Decl::ImplicitParam &&
                                 S->getKind() != Decl::ParmVar &&
                                 S->getKind() != Decl::NonTypeTemplateParm}]>;
+def NonParmVar : SubsetSubject<Var,
+                               [{S->getKind() != Decl::ParmVar}]>;
 def NonBitField : SubsetSubject<Field,
                                 [{!S->isBitField()}]>;
 
@@ -994,8 +996,8 @@ def NoCommon : InheritableAttr {
 
 def NoDebug : InheritableAttr {
   let Spellings = [GCC<"nodebug">];
-  let Subjects = SubjectList<[FunctionLike, ObjCMethod, GlobalVar], WarnDiag,
-                              "ExpectedFunctionGlobalVarMethodOrProperty">;
+  let Subjects = SubjectList<[FunctionLike, ObjCMethod, NonParmVar], WarnDiag,
+                              "ExpectedVariableOrFunction">;
   let Documentation = [NoDebugDocs];
 }
 

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=272859&r1=272858&r2=272859&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed Jun 15 19:42:36 2016
@@ -524,8 +524,8 @@ def NoDebugDocs : Documentation {
   let Category = DocCatVariable;
   let Content = [{
 The ``nodebug`` attribute allows you to suppress debugging information for a
-function, or for a variable declared with static storage duration, such as
-globals, class static data members, and static locals.
+function or method, or for a variable that is not a parameter or a non-static
+data member.
   }];
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=272859&r1=272858&r2=272859&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Jun 15 19:42:36 2016
@@ -3019,6 +3019,8 @@ void CGDebugInfo::EmitDeclare(const VarD
                               CGBuilderTy &Builder) {
   assert(DebugKind >= codegenoptions::LimitedDebugInfo);
   assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
+  if (VD->hasAttr<NoDebugAttr>())
+    return;
 
   bool Unwritten =
       VD->isImplicit() || (isa<Decl>(VD->getDeclContext()) &&
@@ -3163,6 +3165,8 @@ void CGDebugInfo::EmitDeclareOfBlockDecl
 
   if (Builder.GetInsertBlock() == nullptr)
     return;
+  if (VD->hasAttr<NoDebugAttr>())
+    return;
 
   bool isByRef = VD->hasAttr<BlocksAttr>();
 

Modified: cfe/trunk/test/CodeGenCXX/debug-info-nodebug.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-nodebug.cpp?rev=272859&r1=272858&r2=272859&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-nodebug.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-nodebug.cpp Wed Jun 15 19:42:36 2016
@@ -44,9 +44,12 @@ void func3() {
 // YESINFO-DAG: !DIDerivedType({{.*}} name: "static_const_member"
 // NOINFO-NOT:  !DIDerivedType({{.*}} name: "static_const_member"
 
-// Function-local static variable.
+// Function-local static and auto variables.
 void func4() {
   NODEBUG static int static_local = 6;
+  NODEBUG        int normal_local = 7;
 }
 // YESINFO-DAG: !DIGlobalVariable(name: "static_local"
 // NOINFO-NOT:  !DIGlobalVariable(name: "static_local"
+// YESINFO-DAG: !DILocalVariable(name: "normal_local"
+// NOINFO-NOT:  !DILocalVariable(name: "normal_local"

Added: cfe/trunk/test/CodeGenObjC/debug-info-nodebug.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/debug-info-nodebug.m?rev=272859&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/debug-info-nodebug.m (added)
+++ cfe/trunk/test/CodeGenObjC/debug-info-nodebug.m Wed Jun 15 19:42:36 2016
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple arm-apple-ios -emit-llvm -debug-info-kind=limited -fblocks  %s -o - | FileCheck %s
+// Objective-C code cargo-culted from debug-info-lifetime-crash.m.
+ at protocol NSObject
+- (id)copy;
+ at end
+ at class W;
+ at interface View1
+ at end
+ at implementation Controller {
+    void (^Block)(void);
+}
+- (void)View:(View1 *)View foo:(W *)W
+{
+  // The reference from inside the block implicitly creates another
+  // local variable for the referenced member. That is what gets
+  // suppressed by the attribute.  It still gets debug info as a
+  // member, though.
+  // CHECK-NOT: !DILocalVariable(name: "weakSelf"
+  // CHECK:     !DIDerivedType({{.*}} name: "weakSelf"
+  // CHECK-NOT: !DILocalVariable(name: "weakSelf"
+  __attribute__((nodebug)) __typeof(self) weakSelf = self;
+  Block = [^{
+    __typeof(self) strongSelf = weakSelf;
+    } copy];
+}
+ at end

Modified: cfe/trunk/test/Sema/attr-nodebug.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-nodebug.c?rev=272859&r1=272858&r2=272859&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-nodebug.c (original)
+++ cfe/trunk/test/Sema/attr-nodebug.c Wed Jun 15 19:42:36 2016
@@ -2,8 +2,8 @@
 
 int a __attribute__((nodebug));
 
-void b() {
-  int b __attribute__((nodebug)); // expected-warning {{'nodebug' attribute only applies to functions and global variables}}
+void b(int p __attribute__((nodebug))) { // expected-warning {{'nodebug' attribute only applies to variables and functions}}
+  int b __attribute__((nodebug));
 }
 
 void t1() __attribute__((nodebug));




More information about the cfe-commits mailing list