[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] SourceManger::getBufferData <<INVALID SOURCE LOCATION>>
From:       Richard Smith <richard () metafoo ! co ! uk>
Date:       2014-02-28 22:12:49
Message-ID: CAOfiQqn==qaANQfyOqroT0xx11JpqhL0nixdUjMUOpCEAGK+2A () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Fri, Feb 28, 2014 at 2:06 PM, Adam T. Moody <moody20@llnl.gov> wrote:

> Hello all,
> I want to reiterate these questions, since it seems they were missed the
> first time.  I'd appreciate any help.
>
>
> I'm working with clang version 3.5 (trunk 198970) to create a tool to
> rewrite some source files. I have two questions:
>
> 1) Comments for the getEditBuffer method of the Rewriter class suggest
> that it will return the current edit buffer for a file or create and return
> a new buffer if it doesn't already exist. In the case where no insert /
> replace calls have been made, I had hoped this method would return the
> original source, but this doesn't seem to work for me. What is the
> recommended way to get a buffer containing the original source when no
> changes have been made to it?
>
>
> 2) When I have not modified the original source, I get a string like
> "<<<<<INVALID SOURCE LOCATION>>>>>", and in some of those cases, my tool
> seg faults. I wonder if there is a bug in SourceManager::getBufferData. The
> aforementioned string is hardcoded in the function (allocated on the
> stack), and it is used to initialize a StringRef object for the return
> value. Is the returned StringRef object then referencing a portion of
> memory that has been popped from the stack?
>

No; string literal objects have static storage duration.


> Thanks,
> -Adam
>
>
>
> Moody, Adam T. wrote:
>
>  Hello Clang team,
>>
>> I'm working with clang version 3.5 (trunk 198970) to create a tool to
>> rewrite some source files.  I have two questions:
>>
>>
>>
>> 1) Comments for the getEditBuffer method of the Rewriter class suggest
>> that it will return the current edit buffer for a file or create and return
>> a new buffer if it doesn't already exist.  In the case, where no insert /
>> replace calls have been made, I had hoped this method would return the
>> original source, but this doesn't seem to work for me.  What is the
>> recommended way to get a buffer containing the original source when no
>> changes have been made to it?
>>
>>
>>
>> 2) When I have not modified the original source, I get a string like
>> "<<<<<INVALID SOURCE LOCATION>>>>>", and in some of those cases, my tool
>> seg faults.  I wonder if there is a bug in SourceManager::getBufferData.
>>  The aforementioned string is hardcoded in the function (allocated on the
>> stack), and it is used to initialize a StringRef object for the return
>> value.  Is the returned StringRef object then referencing a portion of
>> memory that has been popped from the stack?
>>
>>
>>
>> Thanks for any insight,
>>
>> -Adam
>>
>>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>

[Attachment #5 (text/html)]

<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Feb 28, 2014 \
at 2:06 PM, Adam T. Moody <span dir="ltr">&lt;<a href="mailto:moody20@llnl.gov" \
target="_blank">moody20@llnl.gov</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Hello all,<br> I want to reiterate these questions, since it \
seems they were missed the first time.  I&#39;d appreciate any help.<div \
class=""><br> <br>
I&#39;m working with clang version 3.5 (trunk 198970) to create a tool to rewrite \
some source files. I have two questions:<br> <br></div>
1) Comments for the getEditBuffer method of the Rewriter class suggest that it will \
return the current edit buffer for a file or create and return a new buffer if it \
doesn&#39;t already exist. In the case where no insert / replace calls have been \
made, I had hoped this method would return the original source, but this doesn&#39;t \
seem to work for me. What is the recommended way to get a buffer containing the \
original source when no changes have been made to it?<div class=""> <br>
<br>
2) When I have not modified the original source, I get a string like \
&quot;&lt;&lt;&lt;&lt;&lt;INVALID SOURCE LOCATION&gt;&gt;&gt;&gt;&gt;&quot;, and in \
some of those cases, my tool seg faults. I wonder if there is a bug in \
SourceManager::getBufferData. The aforementioned string is hardcoded in the function \
(allocated on the stack), and it is used to initialize a StringRef object for the \
return value. Is the returned StringRef object then referencing a portion of memory \
that has been popped from the stack?<br> </div></blockquote><div><br></div><div>No; \
string literal objects have static storage duration.</div><div> </div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div class=""> </div>
Thanks,<br>
-Adam<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
Moody, Adam T. wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> Hello Clang team,<br>
<br>
I&#39;m working with clang version 3.5 (trunk 198970) to create a tool to rewrite \
some source files.  I have two questions:<br> <br>
<br>
<br>
1) Comments for the getEditBuffer method of the Rewriter class suggest that it will \
return the current edit buffer for a file or create and return a new buffer if it \
doesn&#39;t already exist.  In the case, where no insert / replace calls have been \
made, I had hoped this method would return the original source, but this doesn&#39;t \
seem to work for me.  What is the recommended way to get a buffer containing the \
original source when no changes have been made to it?<br>

<br>
<br>
<br>
2) When I have not modified the original source, I get a string like \
&quot;&lt;&lt;&lt;&lt;&lt;INVALID SOURCE LOCATION&gt;&gt;&gt;&gt;&gt;&quot;, and in \
some of those cases, my tool seg faults.  I wonder if there is a bug in \
SourceManager::getBufferData.  The aforementioned string is hardcoded in the function \
(allocated on the stack), and it is used to initialize a StringRef object for the \
return value.  Is the returned StringRef object then referencing a portion of memory \
that has been popped from the stack?<br>

<br>
<br>
<br>
Thanks for any insight,<br>
<br>
-Adam<br>
 <br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" \
target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a><br> \
</div></div></blockquote></div><br></div></div>



_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic