Re: [PATCH] D43259: Implement function attribute artificial

2018-02-13 Thread David Blaikie via cfe-commits
Maybe - though that'd actually make for larger debug info & not be much
use.

With nodebug+always_inline (which is how the intrinsics are provided) the
function call dissolves into the raw instruction it's meant to represent.
The debug info describes that instruction as if it had been written at the
point of the call.

With this artificial+always_inline a description of inlining would be
provided (DWARF's inlining description is a bit heavy/verbose) & the
debugger would step over it, rather than into it.

For longer functions (inlined or outlined), marking as artificial makes
sense, I think, but /probably/ not for those places already using
nodebug+always_inline.

On Tue, Feb 13, 2018 at 3:18 PM Reid Kleckner via Phabricator <
revi...@reviews.llvm.org> wrote:

> rnk accepted this revision.
> rnk added subscribers: probinson, aprantl, dblaikie.
> rnk added a comment.
> This revision is now accepted and ready to land.
>
> lgtm
>
> ---
>
> Clang's builtin headers use `__attribute__((__nodebug__))` for this
> purpose. Do you think we should follow this up by using artificial instead?
> It seems like it would be a representational improvement. @aprantl
> @probinson @dblaikie
>
>
>
> 
> Comment at: test/Sema/artificial.c:3
> +
> +void __attribute__((artificial)) bar() {} // expected-warning
> {{'artificial' attribute only applies to inline functions}}
> 
> I think it's worth adding the `foo` function from the CodeGen test here to
> show we don't generate warnings when the function is inline specified.
>
>
> https://reviews.llvm.org/D43259
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43259: Implement function attribute artificial

2018-02-13 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325081: Implement function attribute artificial (authored by 
erichkeane, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43259?vs=134123=134146#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43259

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/CodeGen/artificial.c
  cfe/trunk/test/Sema/artificial.c


Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -3235,7 +3235,7 @@
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
-  if (!HasDecl || D->isImplicit()) {
+  if (!HasDecl || D->isImplicit() || D->hasAttr()) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();
Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -6057,6 +6057,9 @@
   case AttributeList::AT_AlwaysInline:
 handleAlwaysInlineAttr(S, D, Attr);
 break;
+  case AttributeList::AT_Artificial:
+handleSimpleAttribute(S, D, Attr);
+break;
   case AttributeList::AT_AnalyzerNoReturn:
 handleAnalyzerNoReturnAttr(S, D, Attr);
 break;
Index: cfe/trunk/include/clang/Basic/AttrDocs.td
===
--- cfe/trunk/include/clang/Basic/AttrDocs.td
+++ cfe/trunk/include/clang/Basic/AttrDocs.td
@@ -3273,3 +3273,13 @@
 or `msvc documentation `_.
 }];
 }
+
+def ArtificialDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``artificial`` attribute is used with inline functions to treat the inline 
+function as a unit while debugging. For more information see GCC_ 
documentation.
+
+.. _GCC: https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Function-Attributes.html
+  }];
+}
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -111,6 +111,9 @@
 def GlobalVar : SubsetSubjecthasGlobalStorage()}], "global variables">;
 
+def InlineFunction : SubsetSubjectisInlineSpecified()}], "inline functions">;
+
 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
 // type to be a class, not a definition. This makes it impossible to create an
 // attribute subject which accepts a Decl. Normally, this is not a problem,
@@ -588,6 +591,12 @@
   let Documentation = [Undocumented];
 }
 
+def Artificial : InheritableAttr {
+  let Spellings = [GCC<"artificial">];
+  let Subjects = SubjectList<[InlineFunction], WarnDiag>;
+  let Documentation = [ArtificialDocs];
+}
+
 def XRayInstrument : InheritableAttr {
   let Spellings = [Clang<"xray_always_instrument">,
Clang<"xray_never_instrument">];
Index: cfe/trunk/test/Sema/artificial.c
===
--- cfe/trunk/test/Sema/artificial.c
+++ cfe/trunk/test/Sema/artificial.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+inline void __attribute__((artificial)) foo() {}
+void __attribute__((artificial)) bar() {} // expected-warning {{'artificial' 
attribute only applies to inline functions}}
Index: cfe/trunk/test/CodeGen/artificial.c
===
--- cfe/trunk/test/CodeGen/artificial.c
+++ cfe/trunk/test/CodeGen/artificial.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
+
+extern void foo();
+// CHECK: !DISubprogram(name: "foo"
+// CHECK-SAME: flags: DIFlagArtificial
+inline void __attribute__((artificial)) foo() {}
+
+void baz() {
+  foo();
+}


Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -3235,7 +3235,7 @@
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
-  if (!HasDecl || D->isImplicit()) {
+  if (!HasDecl || D->isImplicit() || D->hasAttr()) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();
Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ 

[PATCH] D43259: Implement function attribute artificial

2018-02-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added subscribers: probinson, aprantl, dblaikie.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm

---

Clang's builtin headers use `__attribute__((__nodebug__))` for this purpose. Do 
you think we should follow this up by using artificial instead? It seems like 
it would be a representational improvement. @aprantl @probinson @dblaikie




Comment at: test/Sema/artificial.c:3
+
+void __attribute__((artificial)) bar() {} // expected-warning {{'artificial' 
attribute only applies to inline functions}}

I think it's worth adding the `foo` function from the CodeGen test here to show 
we don't generate warnings when the function is inline specified.


https://reviews.llvm.org/D43259



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43259: Implement function attribute artificial

2018-02-13 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: erichkeane, aaron.ballman.

Added support in clang for GCC function attribute 'artificial'. This attribute 
is used to control stepping behavior of debugger with respect to inline 
functions.


https://reviews.llvm.org/D43259

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CGDebugInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/artificial.c
  test/Sema/artificial.c


Index: test/Sema/artificial.c
===
--- /dev/null
+++ test/Sema/artificial.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void __attribute__((artificial)) bar() {} // expected-warning {{'artificial' 
attribute only applies to inline functions}}
Index: test/CodeGen/artificial.c
===
--- /dev/null
+++ test/CodeGen/artificial.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
+
+extern void foo();
+// CHECK: !DISubprogram(name: "foo"
+// CHECK-SAME: flags: DIFlagArtificial
+inline void __attribute__((artificial)) foo() {}
+
+void baz() {
+  foo();
+}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6057,6 +6057,9 @@
   case AttributeList::AT_AlwaysInline:
 handleAlwaysInlineAttr(S, D, Attr);
 break;
+  case AttributeList::AT_Artificial:
+handleSimpleAttribute(S, D, Attr);
+break;
   case AttributeList::AT_AnalyzerNoReturn:
 handleAnalyzerNoReturnAttr(S, D, Attr);
 break;
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3229,7 +3229,7 @@
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
-  if (!HasDecl || D->isImplicit()) {
+  if (!HasDecl || D->isImplicit() || D->hasAttr()) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -3273,3 +3273,13 @@
 or `msvc documentation `_.
 }];
 }
+
+def ArtificialDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``artificial`` attribute is used with inline functions to treat the inline 
+function as a unit while debugging. For more information see GCC_ 
documentation.
+
+.. _GCC: https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Function-Attributes.html
+  }];
+}
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -111,6 +111,9 @@
 def GlobalVar : SubsetSubjecthasGlobalStorage()}], "global variables">;
 
+def InlineFunction : SubsetSubjectisInlineSpecified()}], "inline functions">;
+
 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
 // type to be a class, not a definition. This makes it impossible to create an
 // attribute subject which accepts a Decl. Normally, this is not a problem,
@@ -588,6 +591,12 @@
   let Documentation = [Undocumented];
 }
 
+def Artificial : InheritableAttr {
+  let Spellings = [GCC<"artificial">];
+  let Subjects = SubjectList<[InlineFunction], WarnDiag>;
+  let Documentation = [ArtificialDocs];
+}
+
 def XRayInstrument : InheritableAttr {
   let Spellings = [Clang<"xray_always_instrument">,
Clang<"xray_never_instrument">];


Index: test/Sema/artificial.c
===
--- /dev/null
+++ test/Sema/artificial.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void __attribute__((artificial)) bar() {} // expected-warning {{'artificial' attribute only applies to inline functions}}
Index: test/CodeGen/artificial.c
===
--- /dev/null
+++ test/CodeGen/artificial.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+extern void foo();
+// CHECK: !DISubprogram(name: "foo"
+// CHECK-SAME: flags: DIFlagArtificial
+inline void __attribute__((artificial)) foo() {}
+
+void baz() {
+  foo();
+}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6057,6 +6057,9 @@
   case AttributeList::AT_AlwaysInline:
 handleAlwaysInlineAttr(S, D, Attr);
 break;
+  case AttributeList::AT_Artificial:
+