<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body>
If a symbol (SymExpr object) `$p` is an unknown numeric value of a
memory address, then a symbolic region (i.e., SymbolicRegion object)
`SymRegion{$p}` represents the segment of memory that starts at
address $p and ends at another unknown position, and a pointer value
(loc::MemRegionVal object) `&SymRegion{$p}` represents, well, a
value of a pointer to the beginning of symbolic region
`SymRegion{$p}`.<br>
<br>
All three are basically the same thing. `SymRegion{$p}` is slightly
different because it implies the existence of the other end of the
segment (even if it's unknown) but `&SymRegion{$p}` is basically
the same thing as `$p`, just represented as an object of a different
type (SVal as opposed to SymExpr).<br>
<br>
Think of SymbolicRegion and loc::MemRegionVal as adaptors; they
don't change the meaning behind the object, they only represent it
in a different manner, like a different point of view on the same
entity. The important technical difference between
`&SymRegion{$p}` and `$p` is that the former is Loc and the
latter is NonLoc.<br>
<br>
There's another such adaptor, nonloc::SymbolVal, that represents
SymExprs as SVals directly. For any symbol `$p` of pointer type,
nonloc::SymbolVal of `$p` is ill-formed; it is always going to be
canonically represented as loc::MemRegionVal `&SymRegion{$p}`
instead. So nonloc::SymbolVal can only be used on regular integers.
This ensures that Loc values are always used for representing
pointers (or references, or values of glvalue expressions) and
NonLoc values are always used for representing integers and other
prvalues of non-pointer type.<br>
<br>
This entire system of adaptors might seem unnecessarily complicated
and it probably is but i can't say we suffer too much from its
existence and i don't have anything better in mind and i believe it
adds a bit of type safety that helps us avoid introducing bugs in
the code.<br>
<br>
See also
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/pipermail/cfe-dev/2017-June/054084.html">http://lists.llvm.org/pipermail/cfe-dev/2017-June/054084.html</a><br>
<br>
<br>
> `clang_analyzer_dump()` says it is an element region<br>
<br>
It doesn't. It says "&Element", not "Element". This should be
read as "address of element" and indicates that the dumped value is
a loc::MemRegionVal, i.e. a pointer value. That's exactly how
explainer works as well, which is why it says "pointer to".<br>
<br>
<br>
<br>
<div class="moz-cite-prefix">On 6/18/20 12:57 PM, Ádám Balogh via
cfe-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:VI1PR0702MB3663DB8A8F770041402703CF819B0@VI1PR0702MB3663.eurprd07.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<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:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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]-->
<div class="WordSection1">
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am trying to understand how to
distinguish the value of the pointer itself and the pointed
region. However, I experience some contradictions while
testing. Look at the following piece of code:<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal">const int* get_ptr();<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">void f() {<o:p></o:p></p>
<p class="MsoNormal"> const int *p = get_ptr();<o:p></o:p></p>
<p class="MsoNormal"> clang_analyzer_dump(p);<o:p></o:p></p>
<p class="MsoNormal"> clang_analyzer_explain(p);<o:p></o:p></p>
<p class="MsoNormal">}<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The output of this code:<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal">ptr_dump_explain.c:8:3: warning:
&SymRegion{conj_$2{const int *, LC1, S715, #1}}
[debug.ExprInspection]<o:p></o:p></p>
<p class="MsoNormal"> clang_analyzer_dump(p);<o:p></o:p></p>
<p class="MsoNormal"> ^~~~~~~~~~~~~~~~~~~~~~<o:p></o:p></p>
<p class="MsoNormal">ptr_dump_explain.c:9:3: warning: symbol of
type 'const int *' conjured at statement 'get_ptr()'
[debug.ExprInspection]<o:p></o:p></p>
<p class="MsoNormal"> clang_analyzer_explain(p);<o:p></o:p></p>
<p class="MsoNormal"> ^~~~~~~~~~~~~~~~~~~~~~~~~<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Is `p` a region or a symbol?
`clang_analyzer_dump()` says it is a region, more specifically
a symbolic region, but still a region. However,
`clang_analyzer_explain()` says it is a symbol, which I think
is wrong. According to `SValExplainer.h` it should print
something like `object at…` or `pointee of …` but not explain
the raw symbol without mentioning the region.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I tried to change the code to the
following:<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal">void f() {<o:p></o:p></p>
<p class="MsoNormal"> const int *p = get_ptr();<o:p></o:p></p>
<p class="MsoNormal"> ++p;<o:p></o:p></p>
<p class="MsoNormal"> clang_analyzer_dump(p);<o:p></o:p></p>
<p class="MsoNormal"> clang_analyzer_explain(p);<o:p></o:p></p>
<p class="MsoNormal">}<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The output changes:<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal">ptr_dump_explain.c:9:3: warning:
&Element{SymRegion{conj_$2{const int *, LC1, S715, #1}},1
S64b,int} [debug.ExprInspection]<o:p></o:p></p>
<p class="MsoNormal"> clang_analyzer_dump(p);<o:p></o:p></p>
<p class="MsoNormal"> ^~~~~~~~~~~~~~~~~~~~~~<o:p></o:p></p>
<p class="MsoNormal">ptr_dump_explain.c:10:3: warning: pointer
to element of type 'int' with index 1 of pointee of symbol of
type 'const int *' conjured at statement 'get_ptr()'
[debug.ExprInspection]<o:p></o:p></p>
<p class="MsoNormal"> clang_analyzer_explain(p);<o:p></o:p></p>
<p class="MsoNormal"> ^~~~~~~~~~~~~~~~~~~~~~~~~<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This is even stranger, because here
`clang_analyzer_dump()` says it is an element region, thus a
region of the array element. However, here
`clang_analyzer_explain()` says it is a pointer to the
element, thus not the element itself. According to
`SValExplainer.h` the output for an element region should
begin with `element of type…`. What is wrong here? Both
functions take the same type of parameter:<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal">void clang_analyzer_dump(const int*);<o:p></o:p></p>
<p class="MsoNormal">void clang_analyzer_explain(const int*);<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">What do I misunderstand here?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="HU">Ádám<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="HU"><o:p> </o:p></span></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>