[cfe-dev] Assertion violation when using Rewrite::ReplaceText()

Jorge Fernández Fabeiro fabeirojorge at gmail.com
Thu Oct 4 01:39:12 PDT 2012


Hi,

I'm working in an optimization tool that does some source-to-source
rewritings over OpenCL kernels written in C. In former versions of my tool,
I could use the Rewriter class with no problem (I was using the ReplaceText
method in order to replace the text of a single Stmt with a new string
specifically composed for it).

A couple of days ago, and with no apparent reason since I've not changed
anything related with the replacement of source code lines (of course I
have already checked that both the Stmt's I'm passing into the ReplaceText
method and the replacing string are OK), some invocations to ReplaceText
result in the following assertion violation:

Application: <<path to LLVM>>/tools/clang/lib/Rewrite/RewriteRope.cpp:382:
> void<unnamed>::RopePieceBTreeLeaf::erase(unsigned int, unsigned int):
> Assertion `getPiece(StartPiece).size() > NumBytes' failed.
> Stack dump:
> 0. <eof> parser at end of file
> Aborted


I'm talking about "some" invocations because not all the invocations to
ReplaceText are leading to that violation. Obviously, when it appears the
program is forced to abort, and there is no clue of the rewritten version
of the OpenCL kernel. I've skimmed the RewriteRope.cpp file available in
Clang Doxygen pages but I've not arrived at any clear conclusion, I'm not a
very experienced C++ programmer and for me it's just a bunch of strange
code, :(

I've tried also using InsertTextAfter instead of ReplaceText in failed
invocations. In this case there is no assertion violation, the program
seems to finish properly and a file with another version of the OpenCL
kernel is generated, but this new version only reflects the changes made
with ReplaceText that not were leading to the violation before. About all
the changes that InsertTextAfter were suppose to make, there is no clue.

I'm a bit worried about this because this problem is the last hurdle I must
jump in order to finish my tool...

Thank you so much in advance for your answers.

P.S.: Sorry for my bad English, ;)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121004/0e05a60d/attachment.html>


More information about the cfe-dev mailing list