[LLVMbugs] [Bug 11917] New: Crash while parsing non-existent union field

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Feb 3 09:36:13 PST 2012


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

             Bug #: 11917
           Summary: Crash while parsing non-existent union field
           Product: clang
           Version: 3.0
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: rgacogne-free at valombre.net
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Hi,

clang revision 149695 is crashing while trying to parse an erroneous,
non-existent union field in a C source code.

This is fixed by the following patch:
Index: lib/Sema/SemaInit.cpp                                                    
===================================================================             
--- lib/Sema/SemaInit.cpp       (revision 149695)                               
+++ lib/Sema/SemaInit.cpp       (working copy)   
@@ -1510,7 +1510,8 @@
                                                  IdentifierInfo *FieldName) {
   assert(AnonField->isAnonymousStructOrUnion());
   Decl *NextDecl = AnonField->getNextDeclInContext();
-  while (IndirectFieldDecl *IF = dyn_cast<IndirectFieldDecl>(NextDecl)) {
+  IndirectFieldDecl *IF = NULL;
+  while (NextDecl && (IF = dyn_cast<IndirectFieldDecl>(NextDecl))) {
     if (FieldName && FieldName == IF->getAnonField()->getIdentifier())
       return IF;
     NextDecl = NextDecl->getNextDeclInContext();

After fixing the offending code, the error generated by the parser is : "field
designator '_erroneous_field_name_' does not refer to any field in type".

Backtrace is:

#0  clang::Decl::getKind (this=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Frontend/../../include/clang/AST/DeclBase.h:346
#1  0x00000000008984d5 in clang::IndirectFieldDecl::classof (D=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Frontend/../../include/clang/AST/Decl.h:2206
#2  0x00000000008984b5 in llvm::isa_impl<clang::IndirectFieldDecl,
clang::Decl>::doit (Val=...) at
/data/sources/clang_llvm/llvm/include/llvm/Support/Casting.h:50
#3  0x0000000000898495 in llvm::isa_impl_cl<clang::IndirectFieldDecl,
clang::Decl*>::doit (Val=0x0) at
/data/sources/clang_llvm/llvm/include/llvm/Support/Casting.h:68
#4  0x0000000000898468 in llvm::isa_impl_wrap<clang::IndirectFieldDecl,
clang::Decl*, clang::Decl*>::doit (Val=@0x7fffffff4520: 0x0) at
/data/sources/clang_llvm/llvm/include/llvm/Support/Casting.h:99
#5  0x0000000000898425 in llvm::isa<clang::IndirectFieldDecl, clang::Decl*>
(Val=@0x7fffffff4520: 0x0) at
/data/sources/clang_llvm/llvm/include/llvm/Support/Casting.h:110
#6  0x0000000000db5135 in llvm::dyn_cast<clang::IndirectFieldDecl,
clang::Decl*> (Val=@0x7fffffff4520: 0x0) at
/data/sources/clang_llvm/llvm/include/llvm/Support/Casting.h:220
#7  0x0000000000ec01c3 in FindIndirectFieldDesignator (AnonField=0x38e3520,
FieldName=0x38327a0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Sema/SemaInit.cpp:1513
#8  0x0000000000ebd279 in (anonymous
namespace)::InitListChecker::CheckDesignatedInitializer (this=0x7fffffff5930,
Entity=..., IList=0x3913ec8, DIE=0x3913e80, DesigIdx=0, CurrentObjectType=...,
NextField=0x7fffffff52c0, NextE
lementIndex=0x0, Index=@0x7fffffff5858: 2, StructuredList=0x0,
StructuredIndex=@0x7fffffff5854: 4, FinishSubobjectInit=true,
TopLevelObject=true) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Sema/SemaInit.cpp:1678
#9  0x0000000000ebb64b in (anonymous
namespace)::InitListChecker::CheckStructUnionTypes (this=0x7fffffff5930,
Entity=..., IList=0x3913ec8, DeclType=..., Field=...,
SubobjectIsDesignatorContext=true, Index=@0x7fffffff5858: 2,
StructuredList=0x0, StructuredIndex=@0x7fffffff5854: 4, TopLevelObject=true) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Sema/SemaInit.cpp:1365
#10 0x0000000000eb9eec in (anonymous
namespace)::InitListChecker::CheckListElementTypes (this=0x7fffffff5930,
Entity=..., IList=0x3913ec8, DeclType=..., SubobjectIsDesignatorContext=true,
Index=@0x7fffffff5858: 2, StructuredL
ist=0x0, StructuredIndex=@0x7fffffff5854: 4, TopLevelObject=true) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Sema/SemaInit.cpp:690
#11 0x0000000000eb879a in (anonymous
namespace)::InitListChecker::CheckExplicitInitList (this=0x7fffffff5930,
Entity=..., IList=0x3913ec8, T=..., Index=@0x7fffffff5858: 2,
StructuredList=0x0, StructuredIndex=@0x7fffffff5854:
4, TopLevelObject=true) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Sema/SemaInit.cpp:603
#12 0x0000000000eb800a in (anonymous
namespace)::InitListChecker::InitListChecker (this=0x7fffffff5930, S=...,
Entity=..., IL=0x3913ec8, T=..., VerifyOnly=true, AllowBraceElision=true) at
/data/sources/clang_llvm/llvm/tools/c
lang/lib/Sema/SemaInit.cpp:481
#13 0x0000000000ead0c3 in TryListInitialization (S=..., Entity=..., Kind=...,
InitList=0x3913ec8, Sequence=...) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Sema/SemaInit.cpp:3019
#14 0x0000000000eac39d in clang::InitializationSequence::InitializationSequence
(this=0x7fffffff60c0, S=..., Entity=..., Kind=..., Args=0x7fffffff77c8,
NumArgs=1) at /data/sources/clang_llvm/llvm/tools/clang/lib/Sema/SemaInit
.cpp:3915
#15 0x0000000000d43a3a in clang::Sema::AddInitializerToDecl (this=0x36fcc70,
RealDecl=0x3913d20, Init=0x3913ec8, DirectInit=false, TypeMayContainAuto=false)
at /data/sources/clang_llvm/llvm/tools/clang/lib/Sema/SemaDecl.cpp:6
132
#16 0x0000000000c5bdd2 in
clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes (this=0x36fe690,
D=..., TemplateInfo=...) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseDecl.cpp:1311
#17 0x0000000000c5ae52 in clang::Parser::ParseDeclGroup (this=0x36fe690,
DS=..., Context=7, AllowFunctionDefinitions=false, DeclEnd=0x7fffffff86d8,
FRI=0x0) at /data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseDecl.cpp
:1118
#18 0x0000000000c582a4 in clang::Parser::ParseSimpleDeclaration
(this=0x36fe690, Stmts=..., Context=7, DeclEnd=..., attrs=...,
RequireSemi=true, FRI=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseDecl.cpp:97
6
#19 0x0000000000c580ac in clang::Parser::ParseDeclaration (this=0x36fe690,
Stmts=..., Context=7, DeclEnd=..., attrs=...) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseDecl.cpp:930
#20 0x0000000000c2e1ca in clang::Parser::ParseStatementOrDeclaration
(this=0x36fe690, Stmts=..., OnlyStatement=false, TrailingElseLoc=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:212
#21 0x0000000000c34438 in clang::Parser::ParseCompoundStatementBody
(this=0x36fe690, isStmtExpr=false) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:765
#22 0x0000000000c33e7f in clang::Parser::ParseCompoundStatement
(this=0x36fe690, attrs=..., isStmtExpr=false, ScopeFlags=8) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:700
#23 0x0000000000c2f9d1 in clang::Parser::ParseCompoundStatement
(this=0x36fe690, Attr=..., isStmtExpr=false) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:658
#24 0x0000000000c2e359 in clang::Parser::ParseStatementOrDeclaration
(this=0x36fe690, Stmts=..., OnlyStatement=true, TrailingElseLoc=0x7fffffff9348)
at /data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:231
#25 0x0000000000c3711e in clang::Parser::ParseStatement (this=0x36fe690,
TrailingElseLoc=0x7fffffff9348) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/../../include/clang/Parse/Parser.h:1492
#26 0x0000000000c2fcc9 in clang::Parser::ParseIfStatement (this=0x36fe690,
attrs=..., TrailingElseLoc=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:940
#27 0x0000000000c2e3f8 in clang::Parser::ParseStatementOrDeclaration
(this=0x36fe690, Stmts=..., OnlyStatement=false, TrailingElseLoc=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:238
#28 0x0000000000c34438 in clang::Parser::ParseCompoundStatementBody
(this=0x36fe690, isStmtExpr=false) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:765
#29 0x0000000000c33e7f in clang::Parser::ParseCompoundStatement
(this=0x36fe690, attrs=..., isStmtExpr=false, ScopeFlags=8) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:700
#30 0x0000000000c2f9d1 in clang::Parser::ParseCompoundStatement
(this=0x36fe690, Attr=..., isStmtExpr=false) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:658
#31 0x0000000000c2e359 in clang::Parser::ParseStatementOrDeclaration
(this=0x36fe690, Stmts=..., OnlyStatement=true, TrailingElseLoc=0x7fffffffa178)
at /data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:231
#32 0x0000000000c3711e in clang::Parser::ParseStatement (this=0x36fe690,
TrailingElseLoc=0x7fffffffa178) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/../../include/clang/Parse/Parser.h:1492
#33 0x0000000000c2fcc9 in clang::Parser::ParseIfStatement (this=0x36fe690,
attrs=..., TrailingElseLoc=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:940
#34 0x0000000000c2e3f8 in clang::Parser::ParseStatementOrDeclaration
(this=0x36fe690, Stmts=..., OnlyStatement=false, TrailingElseLoc=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:238
#35 0x0000000000c34438 in clang::Parser::ParseCompoundStatementBody
(this=0x36fe690, isStmtExpr=false) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:765
#36 0x0000000000c35c33 in clang::Parser::ParseFunctionStatementBody
(this=0x36fe690, Decl=0x3913520, BodyScope=...) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseStmt.cpp:1956
#37 0x0000000000c4837f in clang::Parser::ParseFunctionDefinition
(this=0x36fe690, D=..., TemplateInfo=...) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/Parser.cpp:979
#38 0x0000000000c5ab36 in clang::Parser::ParseDeclGroup (this=0x36fe690,
DS=..., Context=0, AllowFunctionDefinitions=true, DeclEnd=0x0, FRI=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseDecl.cpp:1081
#39 0x0000000000c47379 in clang::Parser::ParseDeclarationOrFunctionDefinition
(this=0x36fe690, DS=..., AS=clang::AS_none) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/Parser.cpp:795
#40 0x0000000000c473fc in clang::Parser::ParseDeclarationOrFunctionDefinition
(this=0x36fe690, attrs=..., AS=clang::AS_none) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/Parser.cpp:808
#41 0x0000000000c46819 in clang::Parser::ParseExternalDeclaration
(this=0x36fe690, attrs=..., DS=0x0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/Parser.cpp:679
#42 0x0000000000c45b49 in clang::Parser::ParseTopLevelDecl (this=0x36fe690,
Result=...) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/Parser.cpp:492
#43 0x0000000000c1b2f2 in clang::ParseAST (S=..., PrintStats=false) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Parse/ParseAST.cpp:85
#44 0x0000000000866c28 in clang::ASTFrontendAction::ExecuteAction
(this=0x36be8e0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:414
#45 0x0000000000a2f883 in clang::CodeGenAction::ExecuteAction (this=0x36be8e0)
at /data/sources/clang_llvm/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:407
#46 0x0000000000866877 in clang::FrontendAction::Execute (this=0x36be8e0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:334
#47 0x000000000083afa1 in clang::CompilerInstance::ExecuteAction
(this=0x36ba0b0, Act=...) at
/data/sources/clang_llvm/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:653
#48 0x000000000080316f in clang::ExecuteCompilerInvocation (Clang=0x36ba0b0) at
/data/sources/clang_llvm/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:175
#49 0x00000000007ee3e9 in cc1_main (ArgBegin=0x7fffffffd3e0,
ArgEnd=0x7fffffffd718, Argv0=0x36b76c8
"/data/sources/clang_llvm/build/Debug+Asserts/bin/clang", MainAddr=0x7fcee0) at
/data/sources/clang_llvm/llvm/tools/clang/too
ls/driver/cc1_main.cpp:165
#50 0x00000000007fd12d in main (argc_=105, argv_=0x7fffffffdd18) at
/data/sources/clang_llvm/llvm/tools/clang/tools/driver/driver.cpp:352

I can produce a core dump and the offending source code or any other
information if needed.

Regards,

-- 
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