felipeprov / include-what-you-use

Automatically exported from code.google.com/p/include-what-you-use
Other
0 stars 0 forks source link

clang::Sema::DeclareImplicitDefaultConstructor: Assertion failed: "Should not build implicit default constructor!"' #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
(running linux x86-64)

Assertion that pops up on several test cases and real code:

SemaDeclCXX.cpp:5958: clang::CXXConstructorDecl* 
clang::Sema::DeclareImplicitDefaultConstructor(clang::CXXRecordDecl*): 
Assertion `!ClassDecl->hasUserDeclaredConstructor() && "Should not build 
implicit default constructor!"' failed.

back trace:

#0  0x0000003751e32f05 in raise () from /lib64/libc.so.6
#1  0x0000003751e34a73 in abort () from /lib64/libc.so.6
#2  0x0000003751e2bef9 in __assert_fail () from /lib64/libc.so.6
#3  0x000000000076cd93 in clang::Sema::DeclareImplicitDefaultConstructor 
(this=0x12943b0, ClassDecl=0x1e6a310) at SemaDeclCXX.cpp:5957
#4  0x000000000045f531 in 
include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::Ins
tantiateImplicitMethods (this=0x1283ca0, decl=0x1e6a310)
    at iwyu.cc:647
#5  0x000000000049eb43 in 
include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::Tra
verseCXXRecordDecl (this=0x1283ca0, decl=0x1e6a310)
    at iwyu.cc:694
#6  0x000000000048e230 in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDecl 
(this=0x1283ca0, D=0x1e6a310)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/DeclNodes.inc:195
#7  0x000000000048e656 in 
include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::Tra
verseDecl (this=0x1283ca0, decl=0x1e6a310) at iwyu.cc:351
#8  0x000000000048e883 in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDeclC
ontextHelper (this=0x1283ca0, DC=0x1e5bf60)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/RecursiveASTVisitor.h:1054
#9  0x000000000048ea6e in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseNames
paceDecl (this=0x1283ca0, D=0x1e5bf30)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/RecursiveASTVisitor.h:1148
#10 0x000000000048e020 in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDecl 
(this=0x1283ca0, D=0x1e5bf30)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/DeclNodes.inc:61
#11 0x000000000048e656 in 
include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::Tra
verseDecl (this=0x1283ca0, decl=0x1e5bf30) at iwyu.cc:351
#12 0x000000000048e883 in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDeclC
ontextHelper (this=0x1283ca0, DC=0x1e5bef0)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/RecursiveASTVisitor.h:1054
#13 0x000000000048ea6e in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseNames
paceDecl (this=0x1283ca0, D=0x1e5bec0)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/RecursiveASTVisitor.h:1148
#14 0x000000000048e020 in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDecl 
(this=0x1283ca0, D=0x1e5bec0)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/DeclNodes.inc:61
#15 0x000000000048e656 in 
include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::Tra
verseDecl (this=0x1283ca0, decl=0x1e5bec0) at iwyu.cc:351
#16 0x000000000048e883 in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDeclC
ontextHelper (this=0x1283ca0, DC=0x12609d8)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/RecursiveASTVisitor.h:1054
#17 0x000000000048f052 in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseTrans
lationUnitDecl (this=0x1283ca0, D=0x12609b0)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/RecursiveASTVisitor.h:1127
#18 0x000000000048e5e0 in 
clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDecl 
(this=0x1283ca0, D=0x12609b0)
    at /home/ehren/llvm/llvm/tools/clang/tools/include-what-you-use/../../include/clang/AST/DeclNodes.inc:421
#19 0x000000000048e656 in 
include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::Tra
verseDecl (this=0x1283ca0, decl=0x12609b0) at iwyu.cc:351
#20 0x000000000048e6a7 in 
include_what_you_use::IwyuAstConsumer::HandleTranslationUnit (this=0x1283c90, 
context=@0x125e090) at iwyu.cc:3238
#21 0x0000000000657b93 in clang::ParseAST (S=@0x12943b0, PrintStats=false) at 
ParseAST.cpp:97
#22 0x0000000000518a5f in clang::ASTFrontendAction::ExecuteAction 
(this=0x1246620) at FrontendAction.cpp:376
#23 0x0000000000518b6c in clang::FrontendAction::Execute (this=0x1246620) at 
FrontendAction.cpp:296
#24 0x0000000000500768 in clang::CompilerInstance::ExecuteAction 
(this=0x124d920, Act=@0x1246620) at CompilerInstance.cpp:600
#25 0x0000000000414512 in main (argc=57, argv=0x7fffffffda48) at iwyu.cc:3628

Test cases affected:

INFO:root:tests/implicit_ctor.cc: Using iwyu flags 
['--check_also="tests/*-d1.h"']
>>> Running ../../../../Debug+Asserts/bin/include-what-you-use -Xiwyu 
--verbose=3 -Xiwyu --check_also="tests/*-d1.h" -I . tests/implicit_ctor.cc

INFO:root:tests/iwyu_stricter_than_cpp.cc: Using iwyu flags 
['--check_also="tests/*-*[^0-9].h"', '--check_also="tests/*-d2.h"']
>>> Running ../../../../Debug+Asserts/bin/include-what-you-use -Xiwyu 
--verbose=3 -Xiwyu --check_also="tests/*-*[^0-9].h" -Xiwyu 
--check_also="tests/*-d2.h" -I . tests/iwyu_stricter_than_cpp.cc

>>> Running ../../../../Debug+Asserts/bin/include-what-you-use -Xiwyu 
--verbose=3 -I . tests/templated_constructor.cc

>>> Running ../../../../Debug+Asserts/bin/include-what-you-use -Xiwyu 
--verbose=3 -I . tests/virtual_tpl_method.cc

wrt the patch, I wonder how hasUserDeclaredConstructor can be false but 
hasDeclaredDefaultConstructor can be true (maybe some dummy default constructor 
gets inserted at some point other than 
Sema::DeclareImplicitDefaultConstructor?). In any case, just changing the guard 
to match the assert seems to be safe. 

Also, I haven't looked into it but there might be similar fixes possible for 
the ifdefed 0 code just below this.

Original issue reported on code.google.com by Ehren.M on 15 May 2011 at 6:34

Attachments:

GoogleCodeExporter commented 9 years ago
I've just started noticing these as well.  There was a recent clang change to 
default constructors (to deal with c++0x, I think), that probably started 
triggering this.

I looked into this, and it looks like we need to check both: defined 
constructor to see if clang has already done this work for us, and user-defined 
constructor to see if we ought to be doing the work at all.

Even after this, I see another crash in the destructor instantiation.  It seems 
the problem is logic in iwyu that tries to instantiate these constructors and 
destructors even when the class is not fully defined (because it's a dependent 
type).  I think it's only correct to instantiate constructors/destructors when 
the 
type is being instantiated, so I added a check for that too.  All tests pass 
now.

Fixed in r230.

Original comment by csilv...@gmail.com on 15 May 2011 at 10:19