<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Yes, it does. In ParseDecl.cpp you can see the ParseExternalSourceSymbolAttribute function that does that.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>From:</b> Yafei Liu <yfliu@mobvoi.com> <br>
<b>Sent:</b> Monday, August 10, 2020 6:53 PM<br>
<b>To:</b> Keane, Erich <erich.keane@intel.com><br>
<b>Cc:</b> cfe-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [cfe-dev] custom attribute crashed due to "Arg access out of range"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hi Erich, do you mean that ExternalSourceSymbol has extra parsing moves to handle the syntax key="value"?<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Mon, Aug 10, 2020 at 8:57 PM Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">checkAttributeAtLeastNumArgs /checkAttributeAtMostNumArgs returns false on error. In your code, you are ensuring that there is at least 1, but no more than 3 arguments.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">SO, you have only made sure that you have 1, 2, OR 3 arguments.
<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">When you attempt to get the 2<sup>nd</sup> argument (AL.getArgAsExpr(1), BUT only have a single argument, you get an assertion, because there IS NOT a 2<sup>nd</sup> argument.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">In your attempt to use a designated initializer type signature (Type=”int”), you get the error because your argument list in the MEItem Attr.td entry you’ve said that you take only
strings. You’d likely have to do some custom parsing to make that syntax work.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b>From:</b> cfe-dev <<a href="mailto:cfe-dev-bounces@lists.llvm.org" target="_blank">cfe-dev-bounces@lists.llvm.org</a>>
<b>On Behalf Of </b>Yafei Liu via cfe-dev<br>
<b>Sent:</b> Monday, August 10, 2020 5:23 AM<br>
<b>To:</b> Clang Dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>><br>
<b>Subject:</b> [cfe-dev] custom attribute crashed due to "Arg access out of range"<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I'm adding a custom attribute followed by this <a href="http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute" target="_blank">http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute</a>,
here's my def:<o:p></o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">def MEItem : InheritableParamAttr {<br>
let Spellings = [CXX11<"me", "type">, C2x<"me", "type">];<br>
let Args = [StringArgument<"Type", 1>, StringArgument<"Getter", 1>, StringArgument<"Setter", 1>];<br>
let Subjects = SubjectList<[Field]>;<br>
let Documentation = [Undocumented];<br>
}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I just copied what ExternalSourceSymbol does, so the handling code is like this:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">static void handleMEItemAttr(Sema &S, Decl *D, const ParsedAttr &AL) {<br>
if (!checkAttributeAtLeastNumArgs(S, AL, 1))<br>
return;<br>
assert(checkAttributeAtMostNumArgs(S, AL, 3) &&<br>
"Invalid number of arguments in an item attribute");<br>
<br>
StringRef Type;<br>
if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(0)))<br>
Type = SE->getString();<br>
<br>
StringRef Getter;<br>
if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(1)))<br>
Getter = SE->getString();<br>
<br>
StringRef Setter;<br>
if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(2)))<br>
Setter = SE->getString();<br>
<br>
D->addAttr(::new (S.Context) MEItemAttr(S.Context, AL, Type, Getter, Setter));<br>
}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">but if I use this attribute in my code, for example [[me::type("int")]], the code crashed at AL.getArgAsExpr(1): <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">clang::ArgsUnion clang::ParsedAttr::getArg(unsigned int) const: Assertion `Arg < NumArgs && "Arg access out of range!"' failed.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">then I tried this: [[me::type(Type="int", Getter="xxx", Setter="xxx")]]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">error: use of undeclared identifier 'Type' [[me::type(Type="int", Getter="xxx", Setter="xxx")]]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">So what did I miss?<o:p></o:p></p>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</body>
</html>