[LLVMbugs] [Bug 10826] New: Code completion in macro with # operator crashes libclang

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Sep 1 06:39:32 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10826

           Summary: Code completion in macro with # operator crashes
                    libclang
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: Erik.Verbruggen at Me.com
                CC: llvmbugs at cs.uiuc.edu


It looks like MacroArgs::StringifyArgument doesn't handle # operator arguments
correctly. So when doing code-completion with:

#define A(x) "A"#x
A(<complete>)

then this causes an out-of-bounds array access.

When running c-index-test on the attached test case, the stack-trace is:

#0  0x00007fff90adece2 in __pthread_kill ()
#1  0x00007fff8afde7d2 in pthread_kill ()
#2  0x0000000100ad755f in raise (sig=6) at Signals.inc:281
#3  0x0000000100ad7590 in abort () at Signals.inc:298
#4  0x0000000100ad765d in __assert_rtn (func=0x100aff350 "operator[]",
file=0x100b88650 "/data/clang-llvm/llvm/include/llvm/ADT/SmallVector.h",
line=150, expr=0x100afb2ad "begin() + idx < end()") at Signals.inc:294
#5  0x0000000100ad4705 in llvm::SmallVectorTemplateCommon<char>::operator[]
(this=0x102ffd080, idx=1) at SmallVector.h:150
#6  0x0000000100a129cb in clang::MacroArgs::StringifyArgument
(ArgToks=0x1031091b0, PP=@0x104001a00, Charify=false, hashInstLoc={ID =
2147492696}) at MacroArgs.cpp:229
#7  0x0000000100a12fe7 in clang::MacroArgs::getStringifiedArgument
(this=0x103109170, ArgNo=0, PP=@0x104001a00, hashInstLoc={ID = 2147492696}) at
MacroArgs.cpp:300
#8  0x0000000100a4c56a in clang::TokenLexer::ExpandFunctionArguments
(this=0x103108ea0) at TokenLexer.cpp:151
#9  0x0000000100a4a8d5 in clang::TokenLexer::Init (this=0x103108ea0,
Tok=@0x10401f010, ELEnd={ID = 171}, Actuals=0x103109170) at TokenLexer.cpp:69
#10 0x0000000100a29758 in clang::Preprocessor::EnterMacro (this=0x104001a00,
Tok=@0x10401f010, ILEnd={ID = 171}, Args=0x103109170) at PPLexerChange.cpp:153
#11 0x0000000100a30b7b in clang::Preprocessor::HandleMacroExpandedIdentifier
(this=0x104001a00, Identifier=@0x10401f010, MI=0x104036770) at
PPMacroExpansion.cpp:308
#12 0x0000000100a43ea6 in clang::Preprocessor::HandleIdentifier
(this=0x104001a00, Identifier=@0x10401f010) at Preprocessor.cpp:489
#13 0x0000000100a04ee1 in clang::Lexer::LexIdentifier (this=0x103108100,
Result=@0x10401f010, CurPtr=0x1031072ba "(") at Lexer.cpp:1279
#14 0x0000000100a06f1a in clang::Lexer::LexTokenInternal (this=0x103108100,
Result=@0x10401f010) at Lexer.cpp:2481
#15 0x00000001001f281b in clang::Lexer::Lex (this=0x103108100,
Result=@0x10401f010) at Lexer.h:130
#16 0x0000000100387b35 in clang::Preprocessor::Lex (this=0x104001a00,
Result=@0x10401f010) at Preprocessor.h:548
#17 0x0000000100a189f7 in clang::Preprocessor::CachingLex (this=0x104001a00,
Result=@0x10401f010) at PPCaching.cpp:57
#18 0x0000000100387bed in clang::Preprocessor::Lex (this=0x104001a00,
Result=@0x10401f010) at Preprocessor.h:554
#19 0x00000001003a7871 in clang::Parser::ConsumeParen (this=0x10401f000) at
Parser.h:324
#20 0x00000001003c2ffc in clang::Parser::SkipUntil (this=0x10401f000,
Toks=0x102ffeab4, NumToks=1, StopAtSemi=false, DontConsume=false,
StopAtCodeCompletion=true) at Parser.cpp:264
#21 0x00000001003ceb75 in clang::Parser::SkipUntil (this=0x10401f000,
T=clang::tok::r_brace, StopAtSemi=false, DontConsume=false,
StopAtCodeCompletion=true) at Parser.h:624
#22 0x00000001003ad669 in
clang::Parser::trySkippingFunctionBodyForCodeCompletion (this=0x10401f000) at
ParseStmt.cpp:1883
#23 0x00000001003b5371 in clang::Parser::ParseFunctionStatementBody
(this=0x10401f000, Decl=0x104037410, BodyScope=@0x102ffede0) at
ParseStmt.cpp:1816
#24 0x00000001003c8f2a in clang::Parser::ParseFunctionDefinition
(this=0x10401f000, D=@0x102fff0e0, TemplateInfo=@0x102fff668) at Parser.cpp:988
#25 0x000000010035ddf5 in clang::Parser::ParseDeclGroup (this=0x10401f000,
DS=@0x102fff950, Context=0, AllowFunctionDefinitions=true, DeclEnd=0x0,
FRI=0x0) at ParseDecl.cpp:886
#26 0x00000001003c671e in clang::Parser::ParseDeclarationOrFunctionDefinition
(this=0x10401f000, DS=@0x102fff950, AS=clang::AS_none) at Parser.cpp:806
#27 0x00000001003c67c1 in clang::Parser::ParseDeclarationOrFunctionDefinition
(this=0x10401f000, attrs=@0x103000320, AS=clang::AS_none) at Parser.cpp:819
#28 0x00000001003cad60 in clang::Parser::ParseExternalDeclaration
(this=0x10401f000, attrs=@0x103000320, DS=0x0) at Parser.cpp:689
#29 0x00000001003cb2a2 in clang::Parser::ParseTopLevelDecl (this=0x10401f000,
Result=@0x1030003d8) at Parser.cpp:510
#30 0x000000010034f13b in clang::ParseAST (S=@0x10401e000, PrintStats=false) at
ParseAST.cpp:84
#31 0x00000001001c63bf in clang::ASTFrontendAction::ExecuteAction
(this=0x103100c30) at FrontendAction.cpp:403
#32 0x00000001001c6557 in clang::FrontendAction::Execute (this=0x103100c30) at
FrontendAction.cpp:323
#33 0x000000010018ec40 in clang::ASTUnit::CodeComplete (this=0x103801a00,
File={Data = 0x101c00a60
"/data/clang-llvm/llvm/tools/clang/test/Index/complete-in-macro.c", Length =
64}, Line=12, Column=11, RemappedFiles=0x103000d80, NumRemappedFiles=0,
IncludeMacros=true, IncludeCodePatterns=false, Consumer=@0x103000c00,
Diag=@0x103100490, LangOpts=@0x103100368, SourceMgr=@0x103100930,
FileMgr=@0x103100770, StoredDiagnostics=@0x1031000c0,
OwnedBuffers=@0x1031003c0) at ASTUnit.cpp:2283
#34 0x000000010014befc in clang_codeCompleteAt_Impl (UserData=0x101d80c28) at
CIndexCodeCompletion.cpp:672
#35 0x0000000100ac47d9 in llvm::CrashRecoveryContext::RunSafely
(this=0x101d80c18, Fn=0x10014ba30 <clang_codeCompleteAt_Impl>,
UserData=0x101d80c28) at CrashRecoveryContext.cpp:309
#36 0x0000000100ac44d9 in RunSafelyOnThread_Dispatch (UserData=0x101d80b58) at
CrashRecoveryContext.cpp:340
#37 0x0000000100add9a8 in ExecuteOnThread_Dispatch (Arg=0x101d80b18) at
Threading.cpp:75
#38 0x00007fff8afdc8bf in _pthread_start ()
#39 0x00007fff8afdfb75 in thread_start ()

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list