[cfe-dev] Assertion `Index < LocalSLocEntryTable.size() && "Invalid index"' failed.

Sean Silva silvas at purdue.edu
Mon Feb 27 15:45:06 PST 2012


Could you post the whole source?

Where are you getting the SourceManager that you calling
`sm->getPresumedLoc(loc)`
on? It is important that you call that method on the same SourceManager
that is in the CompilerInstance that clang is using.

Also, you probably want to use `sm->isFromMainFile(loc)` instead of getting
the presumedloc, since the presumedloc can be modified by `#line`
directives and other stuff.
http://clang.llvm.org/doxygen/classclang_1_1SourceManager.html#ae243bd7789128f1bc5ad462f69f91579

--Sean Silva

On Mon, Feb 27, 2012 at 2:29 PM, Aditya Kumar <hiraditya at msn.com> wrote:

>  What I am trying to do is print only those macros which are defined in
> the current file.
> So whenever the PPCallback function MacroDefined is called, I test if the
> presumed file name is same as
> the file currently being processed. If it is then print macro identifier
> etc...
>
> Relevant code is as follows...
>
>     void MacroDefined(const Token &MacroNameTok, const MacroInfo* MI)
>     {
>       if(MacroIsLocal(MI->getDefinitionLoc())) {
>       //  if(MacroNameTok.getName()){
>         std::cout<<"Macro
> "<<MacroNameTok.getIdentifierInfo()->getNameStart()<<" is defined
> here\n\t";
>         //std::cout<<"Macro
> "<<tok::getTokenName(MacroNameTok.getKind())<<" is defined here\n\t";
>         if(MI->isFunctionLike())
>           std::cout<<"The macro is function like\n";
>         if(MI->isObjectLike())
>           std::cout<<"The macro is object like\n";
>       }
>     }
>
>     ///if the macro is local to the current file being processed
>     bool MacroIsLocal(SourceLocation loc)
>     {
>       /// the source manager can decode the SourceLocation information
>       PresumedLoc presumed = sm->getPresumedLoc(loc);//sm is the
> SourceManager for the current file
>       if(file_name == presumed.getFilename())
>         return true;
>       return false;
>     }
>
> When I do not call     `bool MacroIsLocal(SourceLocation loc)'
> It prints all the macros(including the predefined macros) without any
> errors.
> What could be the problem... or is there any other way to
> find out which macros are local to the file being processed.
>
>
> Thanks for the help.
> Aditya
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120227/bbb0a177/attachment.html>


More information about the cfe-dev mailing list