<div>




<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px '.PingFang SC'; color: #454545}
span.s1 {font: 12.0px 'Helvetica Neue'}
</style>


<p class="p1"><font size="2">hi, Aaron</font></p><p class="p2"><font size="2"><br></font></p><p class="p1"><font size="2"><span class="Apple-converted-space">  </span>I may found a useful example. For example, I tested the alias attribute on my own Apple laptop (Target: x86_64-apple-darwin17.5.0). First, I use __has_attribute to test that the alias is usable or not. The test code is as follows:</font></p><p class="p1"><font size="2"><span class="Apple-converted-space"> </span>#include <stdio.h></font></p><p class="p1"><font size="2">void print() {</font></p><p class="p1"><font size="2">#if __has_attribute(alias)</font></p><p class="p1"><font size="2"><span class="Apple-converted-space">   </span>printf("has attribute");</font></p><p class="p1"><font size="2">#else</font></p><p class="p1"><font size="2"><span class="Apple-converted-space">   </span>printf("has not attribute");</font></p><p class="p1"><font size="2">#endif</font></p><p class="p1"><font size="2">}</font></p><p class="p1"><font size="2">int main() {</font></p><p class="p1"><font size="2"><span class="Apple-converted-space">    </span>print();</font></p><p class="p1"><font size="2"><span class="Apple-converted-space">    </span>return 0;</font></p><p class="p1"><font size="2">}</font></p><p class="p1"><font size="2">Compiled using clang, the output result is has attribute, but when i use the following code to verify</font></p><p class="p1"><font size="2">#include <stdio.h></font></p><p class="p1"><font size="2">int oldname = 1;</font></p><p class="p1"><font size="2">extern int newname __attribute__((alias("oldname"))); // declaration</font></p><p class="p1"><font size="2">void foo(void)</font></p><p class="p1"><font size="2">{</font></p><p class="p1"><font size="2"><span class="Apple-converted-space">    </span>printf("newname = %d\n", newname); // prints 1</font></p><p class="p1"><font size="2">}</font></p><p class="p1"><font size="2">int main() {</font></p><p class="p1"><font size="2"><span class="Apple-converted-space">    </span>foo();</font></p><p class="p1"><font size="2"><span class="Apple-converted-space">    </span>return 0;</font></p><p class="p1"><font size="2">}</font></p><p class="p1">




<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px '.PingFang SC'; color: #454545}
span.s1 {font: 12.0px 'Helvetica Neue'}
</style>





























</p><p class="p3"><font size="2"><span class="s1">It told me </span>alias.c:3:35: error: aliases are not supported on darwin,but if TargetNotSupportedAttr method is used, we can avoid __has_attribute (alias) returns true, so we can tell the user more clearly that we do not support this attribute on this platform.</font></p><p class="p3"><font size="2"><br></font></p><p class="p3"><font size="2">  Thanks.</font></p><p class="p3"></p></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b> "Aaron Ballman"<aaron@aaronballman.com>;</div><div><b>发送时间:</b> 2018年5月6日(星期天) 晚上10:19</div><div><b>收件人:</b> "朴素"<772847235@qq.com>;<wbr></div><div><b>抄送:</b> "cfe-commits"<cfe-commits@lists.llvm.org>; <wbr></div><div><b>主题:</b> Re: If I want to disable certain attributes, such as"swiftcall",isthereany way to do it now?</div></div><div><br></div>On Sun, May 6, 2018 at 10:01 AM, 朴素 <772847235@qq.com> wrote:<br>> hi, Aaron<br>><br>>    Can I ask you some questions?Is there such a demand for me in the<br>> community? Does my code need to be submitted to the community?<br>>    Thanks.<br><br>Generally speaking, the community will accept production-quality<br>patches that solve a problem with the product or introduce some new,<br>desirable functionality. What you've described so far sounds like it<br>solves a specific problem you're having, but it doesn't sound like it<br>solves a problem the general public is having. Perhaps if you<br>described how you envision your solution being used in the product and<br>what immediate problems it solves, that would help me to understand<br>the situation a bit better. Basically, if you want to propose adding<br>TargetNotSupportedAttr, can you describe what attributes you would<br>propose using it on?<br><br>Thanks!<br><br>~Aaron<br><br><br>> ------------------ 原始邮件 ------------------<br>> 发件人: "Aaron Ballman"<aaron@aaronballman.com>;<br>> 发送时间: 2018年5月3日(星期四) 晚上7:40<br>> 收件人: "朴素"<772847235@qq.com>;<br>> 抄送: "cfe-commits"<cfe-commits@lists.llvm.org>;<br>> 主题: Re: If I want to disable certain attributes, such as"swiftcall",isthere<br>> any way to do it now?<br>><br>> On Thu, May 3, 2018 at 1:25 AM, 朴素 <772847235@qq.com> wrote:<br>>> hi, Aaron<br>>><br>>>   The reason why i not use of TargetSpecificAttr is as follows.If I plan<br>>> to<br>>> support a new platform, I don't want to let users use certain attributes<br>>> because of hardware or simply not want to. Yes, we can use<br>>> TargetSpecificAttr, but if we use TargetSpecificAttr that we need to<br>>> include<br>>> platforms other than unsupported platforms, but we just need to exclude<br>>> that<br>>> platform, using TargetSpecificAttr may not be a good idea.<br>><br>> Okay, that makes sense to me. Your design seems like a reasonable one.<br>><br>> ~Aaron<br>><br>>><br>>><br>>><br>>> ------------------ 原始邮件 ------------------<br>>> 发件人: "Aaron Ballman"<aaron@aaronballman.com>;<br>>> 发送时间: 2018年5月2日(星期三) 晚上10:05<br>>> 收件人: "朴素"<772847235@qq.com>;<br>>> 抄送: "cfe-commits"<cfe-commits@lists.llvm.org>;<br>>> 主题: Re: If I want to disable certain attributes, such as<br>>> "swiftcall",isthere<br>>> any way to do it now?<br>>><br>>> On Wed, May 2, 2018 at 4:59 AM, 朴素 <772847235@qq.com> wrote:<br>>>> Thanks.<br>>>><br>>>> If I remove some specific attributes, now I can think of the following<br>>>> method.First of all, let me talk about my method.<br>>>><br>>>> 1.Define target platforms that do not support attributes.such as def<br>>>> TargetPower : TargetArch<["ppc", "ppc64", "ppc64le"]>;<br>>>><br>>>> 2.Define TargetNotSupportedAttr class.such as class<br>>>> TargetNotSupportedAttr<TargetArch target> ;<br>>><br>>> Why not make use of TargetSpecificAttr to mark the attributes that are<br>>> specific to a target rather than marking the attributes not supported<br>>> by a target?<br>>><br>>>> 3.Using this approach, we need to modify the<br>>>> cfe-4.0.1.src/utils/TableGen/ClangAttrEmitter.cpp file.Modifying the code<br>>>> in<br>>>> the GenerateHasAttrSpellingStringSwitch function looks like this:<br>>>><br>>>> if(Attr->isSubClassOf("TargetNotSupportedAttr")) {   // add<br>>>><br>>>> #define GenerateTargetNotSupportedAttrChecks<br>>>> GenerateTargetSpecificAttrChecks // add<br>>>><br>>>>         const Record *R = Attr->getValueAsDef("Target");   // add<br>>>><br>>>>         std::vector<std::string> Arches =<br>>>> R->getValueAsListOfStrings("Arches"); // add<br>>>><br>>>>         GenerateTargetNotSupportedAttrChecks(R, Arches, Test, nullptr);<br>>>> // add<br>>>><br>>>>         TestStr = !Test.empty() ? Test + " ? "  + " 0 :" +<br>>>> llvm::itostr(Version) : "0"; // add<br>>>><br>>>>     } else if (Attr->isSubClassOf("TargetSpecificAttr"))<br>>>><br>>>> 4.And for classes that inherit from TargetNotSupportedAttr<> class, we<br>>>> don’t<br>>>> need to generate the attribute class, so add the following code in<br>>>> EmitClangAttrClass<br>>>><br>>>> if (R->getName() != "TargetSpecificAttr" &&<br>>>><br>>>>               R->getName() != "TargetNotSupportedAttr” &&  //add<br>>>><br>>>>               SuperName.empty())<br>>>><br>>>>         SuperName = R->getName();<br>>>><br>>>><br>>>> If I use this method, is it correct?<br>>><br>>> It seems like it would work, yes.<br>>><br>>> ~Aaron<br>>><br>>>><br>>>><br>>>><br>>>><br>>>> ------------------ 原始邮件 ------------------<br>>>> 发件人: "Aaron Ballman"<aaron@aaronballman.com>;<br>>>> 发送时间: 2018年4月29日(星期天) 凌晨3:07<br>>>> 收件人: "朴素"<772847235@qq.com>;<br>>>> 抄送: "cfe-commits"<cfe-commits@lists.llvm.org>;<br>>>> 主题: Re: If I want to disable certain attributes, such as "swiftcall",<br>>>> isthere any way to do it now?<br>>>><br>>>> On Fri, Apr 27, 2018 at 11:23 PM, 朴素 via cfe-commits<br>>>> <cfe-commits@lists.llvm.org> wrote:<br>>>>>    As the title says,thanks.<br>>>><br>>>> You could build a custom clang with specific attributes removed, but<br>>>> there are no compiler flags that allow you to disable arbitrary<br>>>> attributes like swiftcall.<br>>>><br>>>> ~Aaron<br></div>