[cfe-dev] -Wunreachable-code and templates

Christopher Jefferson chris at bubblescope.net
Tue Jan 10 08:37:07 PST 2012


On 10 Jan 2012, at 08:20, David Blaikie wrote:
>> 
> 
> Is there a particular technique/suite/process I should use to try to
> measure the possible performance regression of performing reachable
> code analysis on all templates? (of course I may need to come up with
> my own test cases using the STL and/or boost to really grind things a
> bit)

As an experiment, I tried your most recent patch with a selection of boost headers, in particular the file below. This lead to the following segfault when I tried -Wunreachable-code (which did not occur with -Wunreachable-code, or with an unpatched clang with or without -Wunreachable-code). I can work on reducing this down to a smaller test case, but my past experience is that this is a pain with boost, so I will only do it if you would make use of it.

0  clang             0x00000001100fca92 _ZL15PrintStackTracePv + 34
1  clang             0x00000001100fcf19 _ZL13SignalHandleri + 553
2  libsystem_c.dylib 0x00007fff8ce36cfa _sigtramp + 26
3  libsystem_c.dylib 0x00007fcbd9806600 _sigtramp + 18446743851656608032
4  clang             0x000000010f482695 clang::AnalysisDeclContext::getCFG() + 133
5  clang             0x000000010f49e796 clang::reachable_code::FindUnreachableCode(clang::AnalysisDeclContext&, clang::reachable_code::Callback&) + 38
6  clang             0x000000010f16fb1b clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy, clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::BlockExpr const*) + 3579
7  clang             0x000000010f1869f2 clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy const*, clang::Decl const*, clang::BlockExpr const*) + 82
8  clang             0x000000010f20a734 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) + 1540
9  clang             0x000000010f160d28 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) + 232
10 clang             0x000000010f1244a6 clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) + 454
11 clang             0x000000010f123f3c clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) + 140
12 clang             0x000000010f139599 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, unsigned int, clang::Decl*) + 2633
13 clang             0x000000010f13877c clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, bool) + 4588
14 clang             0x000000010f12a037 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext) + 3879
15 clang             0x000000010f1620cc clang::Parser::ParseSingleDeclarationAfterTemplate(unsigned int, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) + 620
16 clang             0x000000010f161cb4 clang::Parser::ParseTemplateDeclarationOrSpecialization(unsigned int, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) + 756
17 clang             0x000000010f16190f clang::Parser::ParseDeclarationStartingWithTemplate(unsigned int, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) + 351
18 clang             0x000000010f128bb7 clang::Parser::ParseDeclaration(clang::ASTOwningVector<clang::Stmt*, 32u>&, unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) + 455
19 clang             0x000000010f169b14 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::Parser::ParsingDeclSpec*) + 1412
20 clang             0x000000010f134e2b clang::Parser::ParseInnerNamespace(std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, std::vector<clang::IdentifierInfo*, std::allocator<clang::IdentifierInfo*> >&, std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::Parser::BalancedDelimiterTracker&) + 251
21 clang             0x000000010f134a69 clang::Parser::ParseNamespace(unsigned int, clang::SourceLocation&, clang::SourceLocation) + 3289
22 clang             0x000000010f128d08 clang::Parser::ParseDeclaration(clang::ASTOwningVector<clang::Stmt*, 32u>&, unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) + 792
23 clang             0x000000010f169b14 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::Parser::ParsingDeclSpec*) + 1412
24 clang             0x000000010f169519 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 249
25 clang             0x000000010f122b2b clang::ParseAST(clang::Sema&, bool) + 299
26 clang             0x000000010f0f52fc clang::CodeGenAction::ExecuteAction() + 972
27 clang             0x000000010ef0a1f2 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 882
28 clang             0x000000010eef3b34 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3044
29 clang             0x000000010eeeb734 cc1_main(char const**, char const**, char const*, void*) + 5364
30 clang             0x000000010eef0208 main + 648
31 clang             0x000000010eeea234 start + 52
32 clang             0x0000000000000031 start + 18446744069164064305
Stack dump:
0.	Program arguments: /Users/caj/work/code/clang/build/Release/bin/clang -cc1 -triple x86_64-apple-macosx10.7.2 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name t.cc -pic-level 1 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 123.2.1 -resource-dir /Users/caj/work/code/clang/build/Release/bin/../lib/clang/3.1 -I ../../../../boost-source/boost/ -fmodule-cache-path /var/folders/c2/j2pf8rdj4w1dr624t90z2q700000gn/T/clang-module-cache -Wunreachable-code -fdeprecated-macro -fdebug-compilation-dir /Users/caj/work/code/minion/dominion/solver/source/cxxinput/dominion_language -ferror-limit 19 -fmessage-length 143 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/c2/j2pf8rdj4w1dr624t90z2q700000gn/T/t-Jf4MOB.o -x c++ t.cc 
1.	../../../../boost-source/boost/boost/aligned_storage.hpp:148:2: current parser token ';'
2.	../../../../boost-source/boost/boost/aligned_storage.hpp:29:1: parsing namespace 'boost'
3.	../../../../boost-source/boost/boost/aligned_storage.hpp:73:1: parsing struct/union/class body 'aligned_storage'
4.	../../../../boost-source/boost/boost/aligned_storage.hpp:125:5: parsing function body '~aligned_storage<size_, alignment_>'
clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang: note: diagnostic msg: Please submit a bug report to http://llvm.org/bugs/ and include command line arguments and all diagnostic information.
clang: note: diagnostic msg: Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/c2/j2pf8rdj4w1dr624t90z2q700000gn/T/t-4r1eMw.ii
clang: note: diagnostic msg: /var/folders/c2/j2pf8rdj4w1dr624t90z2q700000gn/T/t-4r1eMw.sh

Code used:

#include <boost/lexical_cast.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/spirit/include/qi.hpp>

#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/adapted/boost_tuple.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>

#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/variant/get.hpp>
#include <iostream>
#include <vector>
#include <string>

int main(void)
{ }




#include <boost/lexical_cast.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/spirit/include/qi.hpp>

#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/adapted/boost_tuple.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>

#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/variant/get.hpp>
#include <iostream>
#include <vector>
#include <string>

int main(void)
{ }






More information about the cfe-dev mailing list