[cfe-dev] [Bug] Segmentation fault while getting SourceLocation of a Decl

Hugues de Lassus hugues.de-lassus at imag.fr
Mon Mar 17 10:11:32 PDT 2014


On 03/14/2014 05:44 PM, Jordan Rose wrote:
> That sounds like you're ending up with null FunctionDecl pointers—notice the "this=0x21" in your backtrace. Are you modifying the map while you're iterating over it? That's always dangerous.
>
> Jordan

Thank you Jordan for your answer. I finally found out that my error was 
coming from using std::vector::back() which has undefined behavior when 
the vector is empty.
I knew there was something wrong with this pointer value "0x21" but I 
could not figure out why it was not a null pointer. Now I understood, 
thanks again :)

>
> On Mar 14, 2014, at 8:10 , Hugues de Lassus <hugues.de-lassus at imag.fr> wrote:
>
>> Hi,
>>
>> I am iterating on an std::map whose keys are FunctionDecl's pointers. Many times I encounter no problems, but sometimes I get segfaults for specific C files and I do not manage to find out why nor where parsed C code might produces such a bug.
>>
>> Every time it happens when calling clang::FunctionDecl::getNameInfo() and then clang::Decl::getLocation()
>>
>> I am wondering whether the getNameInfo/getLocation functions are always safe or not ? Do you think it has to come from my tool ? Thanks for the help !
>>
>> Here is an example backtrace:
>>
>> Program received signal SIGSEGV, Segmentation fault.
>> 0x0000000000544bb6 in clang::Decl::getLocation (this=0x21) at /import/linux/x86_64/soft/llvm/3.4/include/clang/AST/DeclBase.h:373
>> 373      SourceLocation getLocation() const { return Loc; }
>> (gdb) bt
>> #0  0x0000000000544bb6 in clang::Decl::getLocation (this=0x21) at /import/linux/x86_64/soft/llvm/3.4/include/clang/AST/DeclBase.h:373
>> #1  0x0000000000544c14 in clang::FunctionDecl::getNameInfo (this=0x21) at /import/linux/x86_64/soft/llvm/3.4/include/clang/AST/Decl.h:1605
>> #2  0x000000000054454f in DotGraph::printDotGraph (this=0x7fffffffe260, IOInfo=0x14eb110) at DotGraph.cpp:32
>> #3  0x000000000058e27d in main (argc=4, argv=0x7fffffffe658) at main.cpp:73
>>
>> -- 
>>
>> Hugues de Lassus Saint-Geniès
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


-- 

Hugues de Lassus Saint-Geniès




More information about the cfe-dev mailing list