http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53147
Bug #: 53147
Summary: [4.7/4.8 Regression] gcc apparently miscompiles
clang-3.1(or trunk)
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: [email protected]
ReportedBy: [email protected]
When one builds an optimized clang-3.1(or trunk) with gcc-4.7/4.8, clang
crashes regularly (when -Wall is enabled).
For example:
$ clang++ -Wall -c test.ii
0 clang 0x00000000018c6d1f
1 clang 0x00000000018c7070
2 libpthread.so.0 0x00007ffee4b61180
3 clang 0x0000000000d3c402
4 clang 0x0000000000d3d689
5 clang 0x0000000000d3f14c
clang::runUninitializedVariablesAnalysis(clang::DeclContext const&, clang::CFG
const&, clang::AnalysisDeclContext&, clang::UninitVariablesHandler&,
clang::UninitVariablesAnalysisStats&) + 1292
6 clang 0x0000000000b70ef7
clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy,
clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::BlockExpr const*) +
1207
7 clang 0x00000000008df850
clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy
const*, clang::Decl const*, clang::BlockExpr const*) + 304
8 clang 0x000000000096e9ec
clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) + 332
9 clang 0x00000000008c037f
clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&) + 159
10 clang 0x0000000000869d40
clang::Parser::ParseFunctionDefinition(clang::Parser::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&,
llvm::SmallVector<clang::Parser::LateParsedAttribute*, 2u>*) + 960
11 clang 0x0000000000874149
clang::Parser::ParseDeclGroup(clang::Parser::ParsingDeclSpec&, unsigned int,
bool, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 809
12 clang 0x0000000000865307
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsingDeclSpec&,
clang::AccessSpecifier) + 135
13 clang 0x0000000000865965
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&,
clang::AccessSpecifier) + 773
14 clang 0x0000000000869415
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::Parser::ParsingDeclSpec*) + 3253
15 clang 0x0000000000869727
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 199
16 clang 0x0000000000860d15 clang::ParseAST(clang::Sema&, bool, bool)
+ 277
17 clang 0x00000000005f6587
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 263
18 clang 0x00000000005df87f
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1023
19 clang 0x00000000005d67e5 cc1_main(char const**, char const**, char
const*, void*) + 9029
20 clang 0x00000000005de7ec main + 7660
21 libc.so.6 0x00007ffee426c675 __libc_start_main + 245
22 clang 0x00000000005d3a89
Stack dump:
0. Program arguments: /var/tmp/llvm/build/Release/bin/clang -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free
-disable-llvm-verifier -main-file-name RenameVar.ii -mrelocation-model static
-mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables
-target-cpu x86-64 -target-linker-version 2.22.52.20120422
-momit-leaf-frame-pointer -coverage-file RenameVar.o -resource-dir
/var/tmp/llvm/build/Release/bin/../lib/clang/3.1 -Wall -fdeprecated-macro
-fdebug-compilation-dir /var/tmp/llvm/build -ferror-limit 19 -fmessage-length
149 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak
-fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -o RenameVar.o -x c++-cpp-output
/var/tmp/creduce/clang_delta/RenameVar.ii
1. RenameVar.cpp:119:1: current parser token 'bool'
2. RenameVar.cpp:107:1: parsing function body 'Initialize'
clang: error: unable to execute command: Segmentation fault
Building clang with gcc-4.6.3 fixes the crashes.
I've narrowed it down to one function in
clang/lib/Analysis/UninitializedValues.cpp :
/// This function pattern matches for a '&&' or '||' that appears at
/// the beginning of a CFGBlock that also (1) has a terminator and
/// (2) has no other elements. If such an expression is found, it is returned.
__attribute__((optimize ("-Os")))
static const BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) {
if (block->empty())
return 0;
const CFGStmt *cstmt = block->front().getAs<CFGStmt>();
if (!cstmt)
return 0;
const BinaryOperator *b = dyn_cast_or_null<BinaryOperator>(cstmt->getStmt());
if (!b || !b->isLogicalOp())
return 0;
if (block->pred_size() == 2) {
if (block->getTerminatorCondition() == b) {
if (block->succ_size() == 2)
return b;
}
else if (block->size() == 1)
return b;
}
return 0;
}
Without "__attribute__((optimize ("-Os")))" or __attribute__((optimize
("-fno-inline"))) clang crashes.
I will try to extract a workable testcase from this, however any hint or help
would be appreciated.