<html><head><base href="x-msg://1440/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jul 4, 2011, at 8:34 AM, harsh gupta wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div class="hmmessage" style="font-size: 10pt; font-family: Tahoma; "><div dir="ltr"><font face="Courier New" size="3" style="font-family: Tahoma; font-size: 12pt; ">I am using the lexer to get a stream of tokens for a file. However if there is a nested block comment,</font><div style="font-family: Tahoma; font-size: 10pt; "><font face="Courier New" size="3" style="font-size: 12pt; "><br></font></div><div style="font-family: Tahoma; font-size: 10pt; "><font face="Courier New" size="3" style="font-size: 12pt; "> for eg /* some comment /*This is a nested comment*/ some more comment */ <br id="FontBreak"></font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="Arial">Then the lexer gives a segmentation fault. Is there any way to avoid this segmentation fault?</font><br></div></div></div></span></blockquote><div><br></div>It's hard to tell without more information, you probably don't have diagnostics set up right. Note that this is *not* a nested block comment, C doesn't have any such thing. If you run this through 'clang -E' you'll see this warning:</div><div><br></div><div>t.c:1:24: warning: '/*' within block comment [-Wcomment]</div><div><br></div><div>which is probably being mishandled.</div><div><br></div><div>-Chris</div><div><br><blockquote type="cite"><div class="hmmessage" style="font-size: 10pt; font-family: Tahoma; "><div dir="ltr"><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="Arial">The code that i am using is:</font></div><div><font class="Apple-style-span" face="'Courier New'"><div> clang::DiagnosticOptions diagnosticOptions;</div><div> clang::TextDiagnosticPrinter *pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter( llvm::outs(), diagnosticOptions);</div><div> llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs;</div><div> clang::Diagnostic diagnostic(pDiagIDs,pTextDiagnosticPrinter);</div><div><br></div><div> clang::LangOptions languageOptions;</div><div> clang::FileSystemOptions fileSystemOptions;</div><div> clang::FileManager fileManager(fileSystemOptions);</div><div><br></div><div><br></div><div> clang::SourceManager sourceManager( diagnostic, fileManager);</div><div> clang::HeaderSearch headerSearch(fileManager);</div><div><br></div><div> clang::TargetOptions targetOptions;</div><div> targetOptions.Triple = llvm::sys::getHostTriple();</div><div><br></div><div> clang::TargetInfo *pTargetInfo = </div><div> clang::TargetInfo::CreateTargetInfo( diagnostic, targetOptions);</div><div><br></div><div> clang::Preprocessor preprocessor( diagnostic, languageOptions, *pTargetInfo, sourceManager, headerSearch);</div><div><br></div></font><span class="Apple-style-span" style="font-family: 'Courier New'; "> const clang::FileEntry *pFile = fileManager.getFile( _outFilename);</span><font class="Apple-style-span" face="'Courier New'"><div> sourceManager.createMainFileID(pFile);</div><div> preprocessor.EnterMainSourceFile();</div><div><br></div><div> std::vector<GeneralCommand> cmdvect;</div><div> GeneralCommand cmd;</div><div> clang::Token token;</div><div> do {</div><div> preprocessor.Lex(token);</div><div> if( diagnostic.hasErrorOccurred())</div><div> {</div><div> break;</div><div> }</div><div><br></div></font><span class="Apple-style-span" style="font-family: 'Courier New'; "> } while(token.isNot(clang::tok::eof));</span><div style="font-family: 'Courier New'; "><br></div><div style="font-family: 'Courier New'; "><br></div><div style="font-family: 'Courier New'; "><br></div><div><font class="Apple-style-span" face="Arial">And the backtrace is:</font></div><div style="font-family: 'Courier New'; "><br></div><div style="font-family: 'Courier New'; "><div>Program received signal SIGSEGV, Segmentation fault.</div><div>0x00000000004708fc in clang::LangOptions::LangOptions (this=0x7fffffffbc38) at /home/harsh/Desktop/llvm/tools/clang/lib/Sema/../../include/clang/Basic/LangOptions.h:24</div><div>24<span class="Apple-tab-span" style="white-space: pre; "> </span>class LangOptions {</div><div>(gdb) bt</div><div>#0 0x00000000004708fc in clang::LangOptions::LangOptions (this=0x7fffffffbc38) at /home/harsh/Desktop/llvm/tools/clang/lib/Sema/../../include/clang/Basic/LangOptions.h:24</div><div>#1 0x00000000007502c2 in clang::Lexer::Lexer (this=0x7fffffffbbb0, fileloc=..., features=..., </div><div> BufStart=0x12a32cc8 "\n//#include <sys/wait.h>\n\n\n//#include <stdio.h>\n//#include <stdlib.h>\n//#include <errno.h>\n//#include <string.h>\n//#include <fcntl.h>\n//#include <sys/types.h>\n//#include <sys/stat.h>\n//#include <unist"..., </div><div> BufPtr=0x12a338c4 "/*printf(\"God mode wasted<span class="Apple-converted-space"> </span><a href="smb://n/">\\n\</a>")*/;\n/*\n\tswitch (gbuf[0]) \n\t\t{\n\t\t\tcase('h') :\n\t\t\t\tread(0,gbuf,6);\n\t\t\t\twrite(harpipe[1],gbuf,6);\n\t\t\tcase('t') :\n\t\t\t\tread(0,gbuf,6);\n\t\t\t\twrite(turpipe[1],gbuf,6);\n\t\t\tdefault"..., BufEnd=0x12a3411a "") at Lexer.cpp:117</div><div>#2 0x0000000000750ae8 in clang::Lexer::MeasureTokenLength (Loc=..., SM=..., LangOpts=...) at Lexer.cpp:349</div><div>#3 0x0000000000744116 in clang::TextDiagnosticPrinter::EmitCaretDiagnostic (this=0x12a0ab30, Loc=..., Ranges=0x7fffffffc010, NumRanges=0, SM=..., Hints=0x0, NumHints=0, Columns=0, OnMacroInst=0, </div><div> MacroSkipStart=0, MacroSkipEnd=0) at TextDiagnosticPrinter.cpp:382</div><div>#4 0x0000000000746a4d in clang::TextDiagnosticPrinter::HandleDiagnostic (this=0x12a0ab30, Level=clang::Diagnostic::Warning, Info=...) at TextDiagnosticPrinter.cpp:1041</div><div>#5 0x0000000000921c04 in clang::DiagnosticIDs::ProcessDiag (this=0x0, Diag=...) at DiagnosticIDs.cpp:582</div><div>#6 0x000000000091cc03 in clang::Diagnostic::ProcessDiag (this=0x7fffffffd410) at /home/harsh/Desktop/llvm/tools/clang/lib/Basic/../../include/clang/Basic/Diagnostic.h:608</div><div>#7 0x000000000091b4a2 in clang::DiagnosticBuilder::Emit (this=0x7fffffffc460) at Diagnostic.cpp:225</div><div>#8 0x0000000000421ee2 in clang::DiagnosticBuilder::~DiagnosticBuilder (this=0x7fffffffc460, __in_chrg=<value optimized out>)</div><div> at /home/harsh/Desktop/llvm/tools/clang/lib/Sema/../../include/clang/Basic/Diagnostic.h:696</div><div>#9 0x000000000075369d in clang::Lexer::SkipBlockComment (this=0x129db190, Result=..., </div><div> CurPtr=0x12a338c5 "*printf(\"God mode wasted<span class="Apple-converted-space"> </span><a href="smb://n/">\\n\</a>")*/;\n/*\n\tswitch (gbuf[0]) \n\t\t{\n\t\t\tcase('h') :\n\t\t\t\tread(0,gbuf,6);\n\t\t\t\twrite(harpipe[1],gbuf,6);\n\t\t\tcase('t') :\n\t\t\t\tread(0,gbuf,6);\n\t\t\t\twrite(turpipe[1],gbuf,6);\n\t\t\tdefault "...) at Lexer.cpp:1629</div><div>#10 0x0000000000754fd8 in clang::Lexer::LexTokenInternal (this=0x129db190, Result=...) at Lexer.cpp:2248</div><div>#11 0x00000000007101e8 in clang::Lexer::Lex (this=0x129db190, Result=...) at /home/harsh/Desktop/llvm/tools/clang/lib/Frontend/../../include/clang/Lex/Lexer.h:131</div><div>#12 0x00000000007102d5 in clang::Preprocessor::Lex (this=0x7fffffffc650, Result=...) at /home/harsh/Desktop/llvm/tools/clang/lib/Frontend/../../include/clang/Lex/Preprocessor.h:507</div><div>#13 0x00000000007c2c84 in MyRewriter::getLexerTokens (this=0x7fffffffd750) at MyRewriter.cpp:304</div><div>#14 0x00000000007c2847 in MyRewriter::getParseTrees (this=0x7fffffffd750) at MyRewriter.cpp:263</div><div>#15 0x00000000007bdf26 in GeneralCandidate::parse (this=0xff09160) at GeneralCandidate.cpp:15</div><div>#16 0x00000000007e3a10 in main () at CPPMain.cpp:1111</div></div><div style="font-family: 'Courier New'; "><br></div></div><div><font class="Apple-style-span" face="Tahoma" size="2">Harsh Gupta</font><br></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div></div>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br></div></blockquote></div><br></body></html>