<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 13 February 2018 at 16:14, Erich Keane via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: erichkeane<br>
Date: Tue Feb 13 16:14:07 2018<br>
New Revision: 325081<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=325081&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=325081&view=rev</a><br>
Log:<br>
Implement function attribute artificial<br>
<br>
Added support in clang for GCC function attribute 'artificial'. This attribute<br>
is used to control stepping behavior of debugger with respect to inline<br>
functions.<br>
<br>
Patch By: Elizabeth Andrews (eandrews)<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D43259" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D43259</a><br>
<br>
<br>
Added:<br>
    cfe/trunk/test/CodeGen/<wbr>artificial.c<br>
    cfe/trunk/test/Sema/<wbr>artificial.c<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/<wbr>Attr.td<br>
    cfe/trunk/include/clang/Basic/<wbr>AttrDocs.td<br>
    cfe/trunk/lib/CodeGen/<wbr>CGDebugInfo.cpp<br>
    cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>Attr.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=325081&r1=325080&r2=325081&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/Attr.td?rev=<wbr>325081&r1=325080&r2=325081&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>Attr.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>Attr.td Tue Feb 13 16:14:07 2018<br>
@@ -111,6 +111,9 @@ def SharedVar : SubsetSubject<Var,<br>
 def GlobalVar : SubsetSubject<Var,<br>
                              [{S->hasGlobalStorage()}], "global variables">;<br>
<br>
+def InlineFunction : SubsetSubject<Function,<br>
+                             [{S->isInlineSpecified()}], "inline functions">;<br>
+<br>
 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node<br>
 // type to be a class, not a definition. This makes it impossible to create an<br>
 // attribute subject which accepts a Decl. Normally, this is not a problem,<br>
@@ -588,6 +591,12 @@ def AlwaysInline : InheritableAttr {<br>
   let Documentation = [Undocumented];<br>
 }<br>
<br>
+def Artificial : InheritableAttr {<br>
+  let Spellings = [GCC<"artificial">];<br>
+  let Subjects = SubjectList<[InlineFunction], WarnDiag>;<br>
+  let Documentation = [ArtificialDocs];<br>
+}<br>
+<br>
 def XRayInstrument : InheritableAttr {<br>
   let Spellings = [Clang<"xray_always_<wbr>instrument">,<br>
                    Clang<"xray_never_instrument"><wbr>];<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>AttrDocs.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=325081&r1=325080&r2=325081&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/AttrDocs.td?rev=<wbr>325081&r1=325080&r2=325081&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>AttrDocs.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>AttrDocs.td Tue Feb 13 16:14:07 2018<br>
@@ -3273,3 +3273,13 @@ For more information see<br>
 or `msvc documentation <<a href="https://docs.microsoft.com/pl-pl/cpp/cpp/selectany" rel="noreferrer" target="_blank">https://docs.microsoft.com/<wbr>pl-pl/cpp/cpp/selectany</a>>`_.<br>
 }];<br>
 }<br>
+<br>
+def ArtificialDocs : Documentation {<br>
+  let Category = DocCatFunction;<br>
+  let Content = [{<br>
+The ``artificial`` attribute is used with inline functions to treat the inline<br>
+function as a unit while debugging. For more information see GCC_ documentation.<br></blockquote><div><br></div><div>I find this to be hard to understand. What does "treat the inline function as a unit" actually mean? How about something like:</div><div><br></div><div>The ``artificial`` attribute can be applied to an inline function. If such a function is inlined, the attribute indicates that debuggers should associate the resulting instructions with the call site, rather than with the corresponding line within the inlined callee.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+.. _GCC: <a href="https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Function-Attributes.html" rel="noreferrer" target="_blank">https://gcc.gnu.org/<wbr>onlinedocs/gcc-4.6.4/gcc/<wbr>Function-Attributes.html</a></blockquote><div><br></div><div>If you still want to reference the GCC documentation, could you pick a newer version? :)</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  }];<br>
+}<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=325081&r1=325080&r2=325081&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGDebugInfo.cpp?rev=325081&r1=<wbr>325080&r2=325081&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CGDebugInfo.cpp Tue Feb 13 16:14:07 2018<br>
@@ -3235,7 +3235,7 @@ void CGDebugInfo::<wbr>EmitFunctionStart(Glob<br>
   if (Name.startswith("\01"))<br>
     Name = Name.substr(1);<br>
<br>
-  if (!HasDecl || D->isImplicit()) {<br>
+  if (!HasDecl || D->isImplicit() || D->hasAttr<ArtificialAttr>()) {<br>
     Flags |= llvm::DINode::FlagArtificial;<br>
     // Artificial functions should not silently reuse CurLoc.<br>
     CurLoc = SourceLocation();<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=325081&r1=325080&r2=325081&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp?rev=325081&<wbr>r1=325080&r2=325081&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp Tue Feb 13 16:14:07 2018<br>
@@ -6057,6 +6057,9 @@ static void ProcessDeclAttribute(Sema &S<br>
   case AttributeList::AT_<wbr>AlwaysInline:<br>
     handleAlwaysInlineAttr(S, D, Attr);<br>
     break;<br>
+  case AttributeList::AT_Artificial:<br>
+    handleSimpleAttribute<<wbr>ArtificialAttr>(S, D, Attr);<br>
+    break;<br>
   case AttributeList::AT_<wbr>AnalyzerNoReturn:<br>
     handleAnalyzerNoReturnAttr(S, D, Attr);<br>
     break;<br>
<br>
Added: cfe/trunk/test/CodeGen/<wbr>artificial.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/artificial.c?rev=325081&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>CodeGen/artificial.c?rev=<wbr>325081&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CodeGen/<wbr>artificial.c (added)<br>
+++ cfe/trunk/test/CodeGen/<wbr>artificial.c Tue Feb 13 16:14:07 2018<br>
@@ -0,0 +1,10 @@<br>
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-<wbr>gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s<br>
+<br>
+extern void foo();<br>
+// CHECK: !DISubprogram(name: "foo"<br>
+// CHECK-SAME: flags: DIFlagArtificial<br>
+inline void __attribute__((artificial)) foo() {}<br>
+<br>
+void baz() {<br>
+  foo();<br>
+}<br>
<br>
Added: cfe/trunk/test/Sema/<wbr>artificial.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/artificial.c?rev=325081&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/Sema/<wbr>artificial.c?rev=325081&view=<wbr>auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Sema/<wbr>artificial.c (added)<br>
+++ cfe/trunk/test/Sema/<wbr>artificial.c Tue Feb 13 16:14:07 2018<br>
@@ -0,0 +1,4 @@<br>
+// RUN: %clang_cc1 -fsyntax-only -verify %s<br>
+<br>
+inline void __attribute__((artificial)) foo() {}<br>
+void __attribute__((artificial)) bar() {} // expected-warning {{'artificial' attribute only applies to inline functions}}<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>