[cfe-dev] "Invalid region to erase" on rewriting ObjCMethodDecl

s0rcy siddarth13+clangcfe at gmail.com
Sat Mar 8 08:53:37 PST 2014


I have a RecursiveASTVisitor as below, attempting to reqrite ObjC methods:

    virtual bool VisitObjCMethodDecl(ObjCMethodDecl *mdecl) {
       
if(astContext->getSourceManager().isInMainFile(mdecl->getLocStart())) {
            if(!mdecl->isOverriding()) {
               
funclist.push_back(mdecl->getClassInterface()->getNameAsString() + " : " +
mdecl->getNameAsString());
                rewriteMeth(mdecl);
        }
        return true;
    }

    void rewriteMeth(ObjCMethodDecl *meth) {
        unsigned num = meth->getNumSelectorLocs();   
        Selector selector = meth->getSelector();
        for(unsigned i = 0; i < num; i++) {
            rewriter.ReplaceText(meth->getSelectorLoc(i),
selector.getNameForSlot(i).size(), "rewrittenMeth");
        }
    }

This works well for small programs, but for larger ones, I get an 'Assertion
failed: (Offset+NumBytes <= size() && "Invalid region to erase!"), function
erase, file
/<redacted>/llvm/tools/clang/include/clang/Rewrite/Core/RewriteRope.h, line
232.' after rewriting 3-4 methods. Changing the order of functions in the
source code causes it to fail in a different function. It appears to fail
fairly deterministically after 3-4 rewrites. Any idea what could be going
wrong?



--
View this message in context: http://clang-developers.42468.n3.nabble.com/Invalid-region-to-erase-on-rewriting-ObjCMethodDecl-tp4038347.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list