<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 17, 2020, at 12:01 PM, Whisperity via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important" class="">Hey!</p><p style="margin:0px 0px 1.2em!important" class="">Suppose we have a rather trivial situation with a function prototype, a usage, and then later a definition:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px" class=""><code class="language-cpp hljs" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;background:rgb(234,238,243) none repeat scroll 0% 0%;color:rgb(0,25,58)"><span class="hljs-keyword" style="font-weight:bold">int</span> foo(<span class="hljs-keyword" style="font-weight:bold">int</span> x);

<span class="hljs-keyword" style="font-weight:bold">void</span> bar() {
  foo(<span class="hljs-number">0</span>);
}

<span class="hljs-keyword" style="font-weight:bold">int</span> foo(<span class="hljs-keyword" style="font-weight:bold">int</span> x) { <span class="hljs-keyword" style="font-weight:bold">return</span> x * <span class="hljs-number">2</span>; }

<span class="hljs-keyword" style="font-weight:bold">void</span> baz() {
  foo(<span class="hljs-number">1</span>);
}
</code></pre><p style="margin:0px 0px 1.2em!important" class="">The following AST results:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px" class=""><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important" class="">|-FunctionDecl 0x55ae46421ca8 <a.cpp:1:1, col:14> col:5 used foo 'int (int)'
| `-ParmVarDecl 0x55ae46421bd0 <col:9, col:13> col:13 x 'int'
|-FunctionDecl 0x55ae46421df0 <line:2:1, col:23> col:6 bar 'void ()'
| `-CompoundStmt 0x55ae46421f90 <col:12, col:23>
|   `-CallExpr 0x55ae46421f68 <col:16, col:21> 'int'
|     |-ImplicitCastExpr 0x55ae46421f50 <col:16> 'int (*)(int)' <FunctionToPointerDecay>
|     | `-DeclRefExpr 0x55ae46421ef8 <col:16> 'int (int)' lvalue Function 0x55ae46421ca8 'foo' 'int (int)'
|     `-IntegerLiteral 0x55ae46421ed8 <col:20> 'int' 0
|-FunctionDecl 0x55ae46422058 prev 0x55ae46421ca8 <line:3:1, col:32> col:5 used foo 'int (int)'
| |-ParmVarDecl 0x55ae46421fc0 <col:9, col:13> col:13 used x 'int'
| `-CompoundStmt 0x55ae46422188 <col:16, col:32>
|   `-ReturnStmt 0x55ae46422178 <col:18, col:29>
|     `-BinaryOperator 0x55ae46422158 <col:25, col:29> 'int' '*'
|       |-ImplicitCastExpr 0x55ae46422140 <col:25> 'int' <LValueToRValue>
|       | `-DeclRefExpr 0x55ae46422100 <col:25> 'int' lvalue ParmVar 0x55ae46421fc0 'x' 'int'
|       `-IntegerLiteral 0x55ae46422120 <col:29> 'int' 2
`-FunctionDecl 0x55ae464221c0 <line:4:1, col:21> col:6 baz 'void ()'
  `-CompoundStmt 0x55ae46422328 <col:12, col:21>
    `-CallExpr 0x55ae46422300 <col:14, col:19> 'int'
      |-ImplicitCastExpr 0x55ae464222e8 <col:14> 'int (*)(int)' <FunctionToPointerDecay>
      | `-DeclRefExpr 0x55ae464222c8 <col:14> 'int (int)' lvalue Function 0x55ae46422058 'foo' 'int (int)'
      `-IntegerLiteral 0x55ae464222a8 <col:18> 'int' 1
</code></pre><p style="margin:0px 0px 1.2em!important" class="">The <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">FunctionDecl</code> knows that it is a redeclaration of a previous Decl (namely, the prototype). However, the two <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">ParmVarDecl</code>s for <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">int x</code> do not have this relationship: <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">PVD->getCanonicalDecl() == PVD</code> holds for both instances, with no connection between. <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">PVD->redecls() == {PVD}</code>, too.<br class="">What is more interesting, is that querying the parameter to which the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">CallExpr</code> gives the argument to, by iterating the number of arguments and doing <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">cast<FunctionDecl>(CE->getCalledDecl())->getParamDecl(0)</code>, we will get two separate <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">ParmVarDecl</code> instances, due to how the call before the <em class="">definition</em> of <strong class=""><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">foo()</code></strong> binds the prototype (and gives us the prototype’s <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">ParmVarDecl</code>) but the call site <em class="">after</em> the called function has been defined bind the <em class="">definition</em>.</p><p style="margin:0px 0px 1.2em!important" class="">Is this an intended behaviour?<br class="">Why isn’t the two <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">ParmVarDecl</code>s not linked into a redecl chain, considering they should mean the “same entity”, as it is the same parameter of a redecl’d function?<br class="">I obviously mean once we are past overloads, past template instantiations, etc. No “magic” should be intervening.<br class="">Or is it me who’s not grasping something from the language correctly?</p></div></div></div></blockquote>That redeclarations of functions can assign different names to their parameters is the most illuminating factor, to me.  It suggests ParmVarDecls really are private to their parent FunctionDecl, and should not be linked to anything outside it — even to another redeclaration of that function.</div><div><br class=""></div><div>Indeed, ParmVarDecls do not matter in any function declaration except a definition; only the parameter types matter, and they are enclosed in the function type.  In other words, ParmVarDecls seem to be unnecessary, semantically, in every declaration of a function except its definition.  In non-defined functions, their purpose is only to help record the name a user assigned to that slot, purely as syntactic sugar. </div><div><br class=""></div><div>Since there need not anything in common between ParmVarDecls of different redeclarations except their type — and even that is stored separately in the FunctionProtoType — I think it’s proper that each ParmVarDecl be considered completely enclosed from the world outside its particular function redeclaration.</div><div><br class=""></div><div>- Dave</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important" class="">Regards,<br class="">W.</p>
<div title="MDH:PGRpdj5IZXkhPC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj5TdXBwb3NlIHdlIGhhdmUgYSByYXRo
ZXIgdHJpdmlhbCBzaXR1YXRpb24gd2l0aCBhIGZ1bmN0aW9uIHByb3RvdHlwZSwgYSB1c2FnZSwg
YW5kIHRoZW4gbGF0ZXIgYSBkZWZpbml0aW9uOjxicj48L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2
PmBgYGNwcDwvZGl2PjxkaXY+aW50IGZvbyhpbnQgeCk7PC9kaXY+PGRpdj48YnI+PC9kaXY+PGRp
dj52b2lkIGJhcigpIHs8L2Rpdj48ZGl2PiZuYnNwOyBmb28oMCk7PC9kaXY+PGRpdj59PC9kaXY+
PGRpdj48YnI+PC9kaXY+PGRpdj5pbnQgZm9vKGludCB4KSB7IHJldHVybiB4ICogMjsgfTwvZGl2
PjxkaXY+PGJyPjwvZGl2PjxkaXY+dm9pZCBiYXooKSB7PC9kaXY+PGRpdj4mbmJzcDsgZm9vKDEp
OzwvZGl2PjxkaXY+fTxicj48L2Rpdj48ZGl2PmBgYDwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+
VGhlIGZvbGxvd2luZyBBU1QgcmVzdWx0czo8L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2PmBgYDwv
ZGl2PjxkaXY+fC1GdW5jdGlvbkRlY2wgMHg1NWFl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aGUgc2FtZSBwYXJhbWV0ZXIgb2YgYSByZWRl
Y2wnZCBmdW5jdGlvbj88L2Rpdj48ZGl2Pkkgb2J2aW91c2x5IG1lYW4gb25jZSB3ZSBhcmUgcGFz
dCBvdmVybG9hZHMsIHBhc3QgdGVtcGxhdGUgaW5zdGFudGlhdGlvbnMsIGV0Yy4gTm8gIm1hZ2lj
IiBzaG91bGQgYmUgaW50ZXJ2ZW5pbmcuPGJyPjwvZGl2PjxkaXY+T3IgaXMgaXQgbWUgd2hvJ3Mg
bm90IGdyYXNwaW5nIHNvbWV0aGluZyBmcm9tIHRoZSBsYW5ndWFnZSBjb3JyZWN0bHk/PC9kaXY+
PGRpdj48YnI+PC9kaXY+PGRpdj5SZWdhcmRzLDwvZGl2PjxkaXY+Vy48YnI+PC9kaXY+PGRpdj48
YnI+PC9kaXY+" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0" class=""></div></div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></body></html>