<div dir="ltr"><div>Hi,<br></div>I hope this is the right list for this question.<br><br><div class="gmail-post-text">
<p>I wrote a Clang/LLVM plugin as a function pass to do some application specific optimazations on my C/C++ code.</p>
<p>To exclude functions from this optimazation pass I want to use C++11 custom function attributes and want to set <em>"plugin_do_not_optimize"</em> like this. I want to check it in my pass and if it is set, simply skip the pass.</p>
<pre class="gmail-lang-cpp gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-kwd">void</span><span class="gmail-pln">
foo</span><span class="gmail-pun">(</span><span class="gmail-pln"> </span><span class="gmail-kwd">void</span><span class="gmail-pln"> </span><span class="gmail-pun">) </span><span class="gmail-pln">__attribute__</span><span class="gmail-pun">((</span><span class="gmail-pln"> plugin_do_not_optimize </span><span class="gmail-pun">))</span><span class="gmail-pln">
</span><span class="gmail-pun">{</span><span class="gmail-pln">
printf</span><span class="gmail-pun">(</span><span class="gmail-pln"> </span><span class="gmail-str">"Hello world. \n"</span><span class="gmail-pln"> </span><span class="gmail-pun">);</span><span class="gmail-pln">
</span><span class="gmail-pun">}</span></code></pre>
<p>I found the AttributBuilder in the docs but cant get rid of it, catching my attribute.</p>
<p>I already tried </p>
<pre class="gmail-lang-cpp gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-pln">f</span><span class="gmail-pun">.</span><span class="gmail-pln">hasFnAttribute</span><span class="gmail-pun">(</span><span class="gmail-str">"plugin_do_not_optimize"</span><span class="gmail-pun">);</span></code></pre>
<p>but it does not return true on the function above and I get the following error:<br></p>
<pre class="gmail-lang-cpp gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-pln">test</span><span class="gmail-pun">.</span><span class="gmail-pln">cpp</span><span class="gmail-pun">:</span><span class="gmail-lit">4</span><span class="gmail-pun">:</span><span class="gmail-lit">28</span><span class="gmail-pun">:</span><span class="gmail-pln"> warning</span><span class="gmail-pun">:</span><span class="gmail-pln"> unknown attribute </span><span class="gmail-str">'plugin_do_not_optimize'</span><span class="gmail-pln"> ignored </span><span class="gmail-pun">[-</span><span class="gmail-typ">Wunknown</span><span class="gmail-pun">-</span><span class="gmail-pln">attributes</span><span class="gmail-pun">]<br><br></span></code></pre><pre class="gmail-lang-cpp gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-pun">How to declare my attribute in clang and get the information if it is set in my pass?<br></span></code><br></pre><pre class="gmail-lang-cpp gmail-prettyprint gmail-prettyprinted"><code>Best regards,<br><br></code></pre><pre class="gmail-lang-cpp gmail-prettyprint gmail-prettyprinted"><code>Shixin Wang<br></code></pre><pre class="gmail-lang-cpp gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-pun"></span></code></pre>
</div></div>