LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 11926 - Clang segfaults during bootstrap (warning related?)
Summary: Clang segfaults during bootstrap (warning related?)
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
: 12429 12644 12657 12697 12797 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-02-05 06:07 PST by octoploid
Modified: 2012-05-11 10:17 PDT (History)
9 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description octoploid 2012-02-05 06:07:24 PST
...
llvm[1]: Compiling regexec.c for Release build
0  clang           0x000000000187a1df
1  clang           0x000000000187a530
2  libpthread.so.0 0x00002ba5e7f05190
3  clang           0x0000000000ced9e2
4  clang           0x0000000000ceec09
5  clang           0x0000000000cf06cc clang::runUninitializedVariablesAnalysis(clang::DeclContext const&, clang::CFG const&, clang::AnalysisDeclContext&, clang::UninitVariablesHandler&, clang::UninitVariablesAnalysisStats&) + 1292
6  clang           0x0000000000b472d7 clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy, clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::BlockExpr const*) + 1015
7  clang           0x00000000008c1d2c clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy const*, clang::Decl const*, clang::BlockExpr const*) + 172
8  clang           0x00000000009391cd clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) + 333
9  clang           0x000000000085aba9 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) + 169
10 clang           0x00000000008705ca clang::Parser::ParseFunctionDefinition(clang::Parser::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&) + 938
11 clang           0x000000000087e00b clang::Parser::ParseDeclGroup(clang::Parser::ParsingDeclSpec&, unsigned int, bool, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 779
12 clang           0x000000000086bc44 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsingDeclSpec&, clang::AccessSpecifier) + 132
13 clang           0x000000000086c2b5 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::AccessSpecifier) + 725
14 clang           0x000000000086f182 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::Parser::ParsingDeclSpec*) + 3330
15 clang           0x000000000086f65f clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 159
16 clang           0x0000000000845d4d clang::ParseAST(clang::Sema&, bool) + 269
17 clang           0x00000000005e96d7 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 247
18 clang           0x00000000005d365f clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1247
19 clang           0x00000000005c9505 cc1_main(char const**, char const**, char const*, void*) + 9157
20 clang           0x00000000005d24d5 main + 7573
21 libc.so.6       0x00002ba5e86dd405 __libc_start_main + 245
22 clang           0x00000000005c6ea9
Stack dump:
0.      Program arguments: /usr/local/bin/clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -main-file-name regexec.c -pic-level 2 -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu amdfam10 -target-linker-version 2.22.52.20120205 -momit-leaf-frame-pointer -coverage-file /var/tmp/build_llvm_clang/lib/Support/Release/regexec.o -resource-dir /usr/local/bin/../lib/clang/3.1 -dependency-file /var/tmp/build_llvm_clang/lib/Support/Release/regexec.d.tmp -MP -MT /var/tmp/build_llvm_clang/lib/Support/Release/regexec.o -MT /var/tmp/build_llvm_clang/lib/Support/Release/regexec.d -D NDEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /var/tmp/build_llvm_clang/include -I /var/tmp/build_llvm_clang/lib/Support -I /var/tmp/llvm/include -I /var/tmp/llvm/lib/Support -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wall -W -Wno-unused-parameter -Wwrite-strings -fconst-strings -fdebug-compilation-dir /var/tmp/build_llvm_clang/lib/Support -ferror-limit 19 -fmessage-length 149 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o /var/tmp/build_llvm_clang/lib/Support/Release/regexec.o -x c /var/tmp/llvm/lib/Support/regexec.c 
1.      /var/tmp/llvm/lib/Support/regengine.inc:482:1: current parser token 'static'
2.      /var/tmp/llvm/lib/Support/regengine.inc:297:1: parsing function body 'ldissect'
clang: error: unable to execute command: Segmentation fault
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.
llvm[1]: Compiling regfree.c for Release build
clang: note: diagnostic msg: Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/regexec-DxeKBH.i
clang: note: diagnostic msg: /tmp/regexec-DxeKBH.sh

Delta reduced to:

 % cat test.ii
namespace std
{
template < class, class > struct pair;
template < typename > struct DenseMapInfo;
template < typename From > struct simplify_type {
    typedef From SimpleType;
};
template < class To, class > struct cast_retty_impl {
    typedef To *ret_type;
};
template < class, class, class > struct cast_retty_wrap;
template < class To, class FromTy > struct cast_retty_wrap <To,
        FromTy,
        FromTy > {
    typedef typename cast_retty_impl < To,
            FromTy >::ret_type ret_type;
};
template < class To, class From > struct cast_retty {
    typedef typename cast_retty_wrap < To,
            From,
            typename simplify_type < From >::SimpleType >::ret_type ret_type;
};
template < class X, class Y > typename cast_retty < X,
         Y * >::ret_type dyn_cast_or_null (Y)
{
}
template < bool, typename T, typename > struct conditional {
    typedef T type;
};
class FoldingSetImpl
{
public:
    class Node
    {
    };
};
typedef FoldingSetImpl::Node FoldingSetNode;
class MDNode:FoldingSetNode
{
public:
    int getNumOperands () const {
    }
    bool isFunctionLocal () const {
    }
};

template < typename KeyT, typename ValueT, typename =
DenseMapInfo < KeyT >, typename = DenseMapInfo < ValueT >, bool =
0 > class DenseMapIterator;
template < typename KeyT, typename ValueT, typename KeyInfoT =
DenseMapInfo < KeyT >, typename = DenseMapInfo < ValueT > >class DenseMap
{
public:
    typedef DenseMapIterator < KeyT,
            KeyInfoT > iterator;
    iterator end () {
    }
    iterator find (KeyT) {
    }
    ValueT & operator[](KeyT) {
    }
};
template < typename KeyT, typename ValueT, typename, typename,
         bool > class DenseMapIterator
{
    typedef std::pair < KeyT,
            ValueT > Bucket;
    typedef DenseMapIterator ConstIterator;
    typedef typename conditional < 0,
            Bucket,
            Bucket >::type value_type;
    typedef value_type *pointer;
    pointer Ptr,
            End;

public:
    DenseMapIterator ():Ptr (), End () {
    }
    bool operator!= (ConstIterator) {
    }
};
class SlotTracker
{
    DenseMap < const MDNode *,
             int >mdnMap;
    int mdnNext;
    typedef DenseMap < const MDNode *,
            int >::iterator mdn_iterator;
    void CreateMetadataSlot (const MDNode *);
};
void SlotTracker::CreateMetadataSlot (const MDNode * N)
{
    0;
    if (!N->isFunctionLocal ()) {
        mdn_iterator I = mdnMap.find (0);

        if (I != mdnMap.end ()) ;
        int DestSlot = mdnNext++;

        mdnMap[0] = DestSlot;
    }
    for (int i, e = N->getNumOperands (); i = e;)
        if (MDNode * Op = dyn_cast_or_null < MDNode > (i)) ;
}

 % /usr/local/bin/clang -cc1 -emit-obj -O0 -Wall -x c++ -o /dev/null test.ii
...
0  clang           0x000000000187a1df
1  clang           0x000000000187a530
2  libpthread.so.0 0x00007f4cb1c0b190
3  clang           0x0000000000ced9e2
4  clang           0x0000000000ceec09
5  clang           0x0000000000cf06cc clang::runUninitializedVariablesAnalysis(clang::DeclContext const&, clang::CFG const&, clang::AnalysisDeclContext&, clang::UninitVariablesHandler&, clang::UninitVariablesAnalysisStats&) + 1292
6  clang           0x0000000000b472d7 clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy, clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::BlockExpr const*) + 1015
7  clang           0x00000000008c1d2c clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy const*, clang::Decl const*, clang::BlockExpr const*) + 172
8  clang           0x00000000009391cd clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) + 333
9  clang           0x000000000085aba9 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) + 169
10 clang           0x00000000008705ca clang::Parser::ParseFunctionDefinition(clang::Parser::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&) + 938
11 clang           0x000000000087e00b clang::Parser::ParseDeclGroup(clang::Parser::ParsingDeclSpec&, unsigned int, bool, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 779
12 clang           0x000000000086bc44 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsingDeclSpec&, clang::AccessSpecifier) + 132
13 clang           0x000000000086c2b5 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::AccessSpecifier) + 725
14 clang           0x000000000086f182 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::Parser::ParsingDeclSpec*) + 3330
15 clang           0x000000000088a359 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&) + 377
16 clang           0x000000000088f1f3 clang::Parser::ParseNamespace(unsigned int, clang::SourceLocation&, clang::SourceLocation) + 1427
17 clang           0x00000000008833cc clang::Parser::ParseDeclaration(clang::ASTOwningVector<clang::Stmt*, 32u>&, unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) + 524
18 clang           0x000000000086e8db clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::Parser::ParsingDeclSpec*) + 1115
19 clang           0x000000000086f65f clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 159
20 clang           0x0000000000845d4d clang::ParseAST(clang::Sema&, bool) + 269
21 clang           0x00000000005e96d7 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 247
22 clang           0x00000000005d365f clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1247
23 clang           0x00000000005c9505 cc1_main(char const**, char const**, char const*, void*) + 9157
24 clang           0x00000000005d24d5 main + 7573
25 libc.so.6       0x00007f4cb1433405 __libc_start_main + 245
26 clang           0x00000000005c6ea9
Stack dump:
0.      Program arguments: /usr/local/bin/clang -cc1 -emit-obj -O0 -Wall -x c++ -o /dev/null test.ii 
1.      <eof> parser at end of file
2.      test.ii:1:1: parsing namespace 'std'
3.      test.ii:92:1: parsing function body 'CreateMetadataSlot'
[1]    16335 segmentation fault  /usr/local/bin/clang -cc1 -emit-obj -O0 -Wall -x c++ -o /dev/null test.ii 2>&

Segfault only happens with -Wall.
Comment 1 Ted Kremenek 2012-02-05 11:02:46 PST
Crash is in -Wuninitialized
Comment 2 Ted Kremenek 2012-02-05 11:03:42 PST
Nothing has changed in -Wuninitialized; not sure why there is a bootstrap failure.  Must be something in the code that has changed.
Comment 3 Ted Kremenek 2012-02-05 11:04:19 PST
cloned to <rdar://problem/10810366>
Comment 4 Ted Kremenek 2012-02-05 11:59:46 PST
This doesn't reproduce for me, even with the delta-reduced test case.
Comment 5 Ted Kremenek 2012-02-05 12:03:40 PST
(In reply to comment #0)

> llvm[1]: Compiling regfree.c for Release build
> clang: note: diagnostic msg: Preprocessed source(s) and associated run
> script(s) are located at:
> clang: note: diagnostic msg: /tmp/regexec-DxeKBH.i
> clang: note: diagnostic msg: /tmp/regexec-DxeKBH.sh
> 
> Delta reduced to:
> 
>  % cat test.ii
> 
> Stack dump:
> 0.      Program arguments: /usr/local/bin/clang -cc1 -emit-obj -O0 -Wall -x c++
> -o /dev/null test.ii 
> 1.      <eof> parser at end of file
> 2.      test.ii:1:1: parsing namespace 'std'
> 3.      test.ii:92:1: parsing function body 'CreateMetadataSlot'
> [1]    16335 segmentation fault  /usr/local/bin/clang -cc1 -emit-obj -O0 -Wall
> -x c++ -o /dev/null test.ii 2>&
> 
> Segfault only happens with -Wall.

This is confusing.  The original crash is on regexec.c, but the delta-reduced test case is in a C++ file.  Did this crash occur multiple times?

Others haven't reported this, and none of the buildbots are failing.  Perhaps a build issue? (e.g., llvm and clang need to be updated and rebuilt together?)
Comment 6 octoploid 2012-02-05 12:07:06 PST
(In reply to comment #5)
> (In reply to comment #0)
> 
> > llvm[1]: Compiling regfree.c for Release build
> > clang: note: diagnostic msg: Preprocessed source(s) and associated run
> > script(s) are located at:
> > clang: note: diagnostic msg: /tmp/regexec-DxeKBH.i
> > clang: note: diagnostic msg: /tmp/regexec-DxeKBH.sh
> > 
> > Delta reduced to:
> > 
> >  % cat test.ii
> > 
> > Stack dump:
> > 0.      Program arguments: /usr/local/bin/clang -cc1 -emit-obj -O0 -Wall -x c++
> > -o /dev/null test.ii 
> > 1.      <eof> parser at end of file
> > 2.      test.ii:1:1: parsing namespace 'std'
> > 3.      test.ii:92:1: parsing function body 'CreateMetadataSlot'
> > [1]    16335 segmentation fault  /usr/local/bin/clang -cc1 -emit-obj -O0 -Wall
> > -x c++ -o /dev/null test.ii 2>&
> > 
> > Segfault only happens with -Wall.
> 
> This is confusing.  The original crash is on regexec.c, but the delta-reduced
> test case is in a C++ file.  Did this crash occur multiple times?

Yes.

> 
> Others haven't reported this, and none of the buildbots are failing.  Perhaps a
> build issue? (e.g., llvm and clang need to be updated and rebuilt together?)

It only happens if configure with "--enable-optimized". A debug build shows no problems. (And yes I've updated both clang and llvm with "make update")
Comment 7 octoploid 2012-02-05 12:29:48 PST
Here is a gdb backtrace from a Release+Debug+Asserts build:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7eaf740 (LWP 10126)]
dyn_cast_or_null<clang::BinaryOperator, clang::Stmt const> (Val=0x6f00000060) at /var/tmp/llvm/include/llvm/Support/Casting.h:228
228       return (Val && isa<X>(Val)) ? cast<X>(Val) : 0;
(gdb) bt
#0  dyn_cast_or_null<clang::BinaryOperator, clang::Stmt const> (Val=0x6f00000060) at /var/tmp/llvm/include/llvm/Support/Casting.h:228
#1  getLogicalOperatorInChain (block=block@entry=0x2580378) at /var/tmp/llvm/tools/clang/lib/Analysis/UninitializedValues.cpp:175
#2  0x0000000000d5134f in runOnBlock (block=block@entry=0x2580378, cfg=..., ac=..., vals=..., wasAnalyzed=..., handler=handler@entry=0x0)
    at /var/tmp/llvm/tools/clang/lib/Analysis/UninitializedValues.cpp:624
#3  0x0000000000d534f4 in clang::runUninitializedVariablesAnalysis (dc=..., cfg=..., ac=..., handler=..., stats=...)
    at /var/tmp/llvm/tools/clang/lib/Analysis/UninitializedValues.cpp:707
#4  0x0000000000b8a01c in clang::sema::AnalysisBasedWarnings::IssueWarnings (this=<optimized out>, P=..., fscope=<optimized out>, D=0x9, 
    blkExpr=<optimized out>) at /var/tmp/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp:927
#5  0x00000000008f4aac in clang::Sema::PopFunctionScopeInfo (this=0x2547390, WP=<optimized out>, D=<optimized out>, blkExpr=<optimized out>)
    at /var/tmp/llvm/tools/clang/lib/Sema/Sema.cpp:843
#6  0x0000000000987992 in clang::Sema::ActOnFinishFunctionBody (this=0x2547390, dcl=0x25774e0, Body=<optimized out>, IsInstantiation=false)
    at /var/tmp/llvm/tools/clang/lib/Sema/SemaDecl.cpp:7317
#7  0x000000000088dc94 in clang::Parser::ParseFunctionStatementBody (this=0x2548f20, Decl=0x25774e0, BodyScope=...)
    at /var/tmp/llvm/tools/clang/lib/Parse/ParseStmt.cpp:1964
#8  0x00000000008a4203 in clang::Parser::ParseFunctionDefinition (this=0x2548f20, D=..., TemplateInfo=...)
    at /var/tmp/llvm/tools/clang/lib/Parse/Parser.cpp:979
#9  0x00000000008b3adb in clang::Parser::ParseDeclGroup (this=0x2548f20, DS=..., Context=0, AllowFunctionDefinitions=true, DeclEnd=0x0, FRI=0x0)
    at /var/tmp/llvm/tools/clang/lib/Parse/ParseDecl.cpp:1082
#10 0x000000000089de04 in clang::Parser::ParseDeclarationOrFunctionDefinition (this=this@entry=0x2548f20, DS=..., AS=AS@entry=clang::AS_none)
    at /var/tmp/llvm/tools/clang/lib/Parse/Parser.cpp:795
#11 0x000000000089e35e in clang::Parser::ParseDeclarationOrFunctionDefinition (this=this@entry=0x2548f20, attrs=..., AS=AS@entry=clang::AS_none)
    at /var/tmp/llvm/tools/clang/lib/Parse/Parser.cpp:808
#12 0x00000000008a2458 in clang::Parser::ParseExternalDeclaration (this=0x2548f20, attrs=..., DS=0x0)
    at /var/tmp/llvm/tools/clang/lib/Parse/Parser.cpp:679
#13 0x00000000008bf0f9 in clang::Parser::ParseInnerNamespace (this=this@entry=0x2548f20, IdentLoc=std::vector of length 0, capacity 0, 
    Ident=std::vector of length 0, capacity 0, NamespaceLoc=std::vector of length 0, capacity 0, index=index@entry=0, InlineLoc=..., attrs=..., 
    Tracker=...) at /var/tmp/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:193
#14 0x00000000008c344c in clang::Parser::ParseNamespace (this=0x2548f20, Context=<optimized out>, DeclEnd=..., InlineLoc=...)
    at /var/tmp/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:170
#15 0x00000000008b87b9 in clang::Parser::ParseDeclaration (this=0x2548f20, Stmts=..., Context=0, DeclEnd=..., attrs=...)
    at /var/tmp/llvm/tools/clang/lib/Parse/ParseDecl.cpp:919
#16 0x00000000008a2158 in clang::Parser::ParseExternalDeclaration (this=this@entry=0x2548f20, attrs=..., DS=DS@entry=0x0)
    at /var/tmp/llvm/tools/clang/lib/Parse/Parser.cpp:624
#17 0x00000000008a297f in clang::Parser::ParseTopLevelDecl (this=0x2548f20, Result=...) at /var/tmp/llvm/tools/clang/lib/Parse/Parser.cpp:492
#18 0x000000000087a06d in clang::ParseAST (S=..., PrintStats=false) at /var/tmp/llvm/tools/clang/lib/Parse/ParseAST.cpp:85
#19 0x0000000000745a10 in clang::CodeGenAction::ExecuteAction (this=0x2507ac0) at /var/tmp/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:407
#20 0x00000000005f90bf in clang::CompilerInstance::ExecuteAction (this=0x2504560, Act=...)
    at /var/tmp/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:653
#21 0x00000000005e176f in clang::ExecuteCompilerInvocation (Clang=0x2504560)
    at /var/tmp/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:176
#22 0x00000000005d6ad5 in cc1_main (ArgBegin=0x7fffffffd720, ArgEnd=0x7fffffffd8f8, Argv0=<optimized out>, MainAddr=0x5dd240)
    at /var/tmp/llvm/tools/clang/tools/driver/cc1_main.cpp:165
#23 0x00000000005e0419 in main (argc_=<optimized out>, argv_=<optimized out>) at /var/tmp/llvm/tools/clang/tools/driver/driver.cpp:353
(gdb)
Comment 8 octoploid 2012-02-05 13:36:33 PST
The issue above only happens if I build llvm+clang with gcc-4.7.0.
When I build with gcc-4.6.3 the following happens:

  COMPILE:   clang_linux/full-i386/i386: /var/tmp/llvm/projects/compiler-rt/lib/adddf3.c
  COMPILE:   clang_linux/full-i386/i386: /var/tmp/llvm/projects/compiler-rt/lib/addsf3.c
clang: /var/tmp/llvm/lib/Transforms/Scalar/GVN.cpp:2003: bool isOnlyReachableViaThisEdge(llvm::BasicBlock*, llvm::BasicBlock*, llvm::DominatorTree*):
 Assertion `PI != PE && *PI == Src && "No edge between these basic blocks!"' failed.
clang: /var/tmp/llvm/lib/Transforms/Scalar/GVN.cpp:2003: bool isOnlyReachableViaThisEdge(llvm::BasicBlock*, llvm::BasicBlock*, llvm::DominatorTree*):
 Assertion `PI != PE && *PI == Src && "No edge between these basic blocks!"' failed.
0  clang           0x0000000001a7efdf
0  clang           0x0000000001a7efdf
1  clang           0x0000000001a7f4e8
2  libpthread.so.0 0x00002ae2e8df4190
3  libc.so.6       0x00002ae2e95df9d5 gsignal + 53
4  libc.so.6       0x00002ae2e95e0e58 abort + 328
5  libc.so.6       0x00002ae2e95d89b2
6  libc.so.6       0x00002ae2e95d8a62
1  clang           0x0000000001a7f4e8
2  libpthread.so.0 0x00002b1cd4274190
3  libc.so.6       0x00002b1cd4a5f9d5 gsignal + 53
4  libc.so.6       0x00002b1cd4a60e58 abort + 328
5  libc.so.6       0x00002b1cd4a589b2
6  libc.so.6       0x00002b1cd4a58a62
7  clang           0x00000000016260a7
7  clang           0x00000000016260a7
8  clang           0x000000000162a677
8  clang           0x000000000162a677
9  clang           0x000000000162d408
9  clang           0x000000000162d408
10 clang           0x0000000001a144bf llvm::FPPassManager::runOnFunction(llvm::Function&) + 639
10 clang           0x0000000001a144bf llvm::FPPassManager::runOnFunction(llvm::Function&) + 639
11 clang           0x00000000017a43b7
1112 clang           clang           0x00000000017a703d 0x00000000017a43b7

13 clang           0x0000000001a141a4 llvm::MPPassManager::runOnModule(llvm::Module&) + 548
12 clang           0x00000000017a703d
13 clang           0x0000000001a141a4 llvm::MPPassManager::runOnModule(llvm::Module&) + 548
14 clang           0x0000000001a15732 llvm::PassManagerImpl::run(llvm::Module&) + 178
15 clang           0x0000000000721363 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, 
clang::LangOptions const&, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 3107
14 clang           0x0000000001a15732 llvm::PassManagerImpl::run(llvm::Module&) + 178
16 clang           0x000000000071e86e
15 clang           0x0000000000721363 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, 
clang::LangOptions const&, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 3107
17 clang           0x000000000087540f clang::ParseAST(clang::Sema&, bool) + 431
18 clang           0x00000000005db902 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 322
16 clang           0x000000000071e86e
19 clang           0x00000000005c1ceb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1387
17 clang           0x000000000087540f 20 clang          clang::ParseAST(clang::Sema&, bool) 0x00000000005b4db8 + 431 
cc1_main(char const**, char const**, char const*, void*) + 664
21 clang           0x00000000005c03a2 main + 706
22 libc.so.6       0x00002b1cd4a4c405 __libc_start_main18 + 245
 clang           0x00000000005db902 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 322
23 clang           0x00000000005b4829
Stack dump:
0.      Program arguments: /var/tmp/build_llvm_clang/Release+Debug+Asserts/bin/clang -cc1 -triple i386-unknown-linux-gnu -S -disable-free -main-file-
name adddf3.c -pic-level 2 -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.22.52.20120205 -momit-leaf-frame-pointer
 -coverage-file /tmp/adddf3-sBWUZ7.s -resource-dir /var/tmp/build_llvm_clang/Release+Debug+Asserts/bin/../lib/clang/3.1 -isysroot /var/tmp/llvm/proje
cts/compiler-rt/SDKs/linux -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /var/tmp/llvm/projects/compiler-rt/SDKs/linux/usr/local/
include -internal-isystem /var/tmp/build_llvm_clang/Release+Debug+Asserts/bin/../lib/clang/3.1/include -internal-externc-isystem /var/tmp/llvm/projec
ts/compiler-rt/SDKs/linux/include -internal-externc-isystem /var/tmp/llvm/projects/compiler-rt/SDKs/linux/usr/include -O3 -Wall -Werror -fno-dwarf-di
rectory-asm -fdebug-compilation-dir /var/tmp/build_llvm_clang/tools/clang/runtime/compiler-rt -ferror-limit 19 -fmessage-length 149 -mstackrealign 19
-fgnu-runtime -fobjc-runtime-has-arc clang           -fobjc-runtime-has-weak 0x00000000005c1ceb -fobjc-fragile-abi  -fdiagnostics-show-option clang::
ExecuteCompilerInvocation(clang::CompilerInstance*)-fcolor-diagnostics + 1387 -o
 /tmp/adddf3-sBWUZ7.s -x c /var/tmp/llvm/projects/compiler-rt/lib/adddf3.c 

Reduced:
 % cat test.i
typedef unsigned long long int uint64_t;
typedef uint64_t rep_t;
typedef double fp_t;
fp_t
__adddf3 (fp_t a, fp_t b)
{
  rep_t aRep = toRep (a);
  rep_t bRep = toRep (b);
  const rep_t aAbs =
    aRep & ((1ULL << (52 + ((sizeof (rep_t) * 8) - 52 - 1))) - 1U);
  const rep_t bAbs =
    bRep & ((1ULL << (52 + ((sizeof (rep_t) * 8) - 52 - 1))) - 1U);
  if (aAbs - 1U >=
      (((1ULL << (52 + ((sizeof (rep_t) * 8) - 52 - 1))) -
        1U) ^ ((1ULL << 52) - 1U)) - 1U
Comment 9 octoploid 2012-02-05 13:47:22 PST
Sorry (bugzilla hang):

 % cat test.i
typedef unsigned long long int uint64_t;
typedef uint64_t rep_t;
typedef double fp_t;
fp_t
__adddf3 (fp_t a, fp_t b)
{
  rep_t aRep = toRep (a);
  rep_t bRep = toRep (b);
  const rep_t aAbs =
    aRep & ((1ULL << (52 + ((sizeof (rep_t) * 8) - 52 - 1))) - 1U);
  const rep_t bAbs =
    bRep & ((1ULL << (52 + ((sizeof (rep_t) * 8) - 52 - 1))) - 1U);
  if (aAbs - 1U >=
      (((1ULL << (52 + ((sizeof (rep_t) * 8) - 52 - 1))) -
        1U) ^ ((1ULL << 52) - 1U)) - 1U
      || bAbs - 1U >=
      (((1ULL << (52 + ((sizeof (rep_t) * 8) - 52 - 1))) -
        1U) ^ ((1ULL << 52) - 1U)) - 1U)
    {
      if (!aAbs)
        {
          if (!bAbs)
            return fromRep (toRep (a) & toRep (b));
        }
    }
}
 % clang -O2 test.i
...clang: /var/tmp/llvm/lib/Transforms/Scalar/GVN.cpp:2003: bool isOnlyReachableViaThisEdge(llvm::BasicBlock*, llvm::BasicBlock*, llvm::DominatorTree*):
 Assertion `PI != PE && *PI == Src && "No edge between these basic blocks!"' failed
...
Comment 10 octoploid 2012-02-05 14:04:59 PST
The assertion above was fixed by r149839 (minutes ago).

So clang build by gcc-4.7 segfaults.
Clang build with gcc-4.6 is OK. Clang build with clang is also OK.

Will look deeper into the 4.7. issue later.
Comment 11 ojab 2012-04-16 01:04:19 PDT
*** Bug 12429 has been marked as a duplicate of this bug. ***
Comment 12 Anton Korobeynikov 2012-04-24 12:29:50 PDT
*** Bug 12644 has been marked as a duplicate of this bug. ***
Comment 13 Anton Korobeynikov 2012-04-25 14:41:12 PDT
*** Bug 12657 has been marked as a duplicate of this bug. ***
Comment 14 octoploid 2012-04-27 08:51:53 PDT
According to https://bugzilla.redhat.com/show_bug.cgi?id=791365
a simple workaround is to build clang with "-fno-tree-pre" when 
using gcc-4.7.
Comment 15 octoploid 2012-04-27 13:24:46 PDT
The following patch is enough to fix the problem:

diff --git a/clang/lib/Analysis/UninitializedValues.cpp b/clang/lib/Analysis/UninitializedValues.cpp
index 6e5da25..f86fd40 100644
--- a/clang/lib/Analysis/UninitializedValues.cpp
+++ b/clang/lib/Analysis/UninitializedValues.cpp
@@ -669,6 +669,7 @@ static bool runOnBlock(const CFGBlock *block, const CFG &cfg,
   return vals.updateValueVectorWithScratch(block);
 }
 
+__attribute__((optimize ("O1")))
 void clang::runUninitializedVariablesAnalysis(
     const DeclContext &dc,
     const CFG &cfg,

So gcc-4.7 seems to miscompile runUninitializedVariablesAnalysis at higher
optimizations.
Comment 16 octoploid 2012-04-27 13:56:33 PDT
No, that wasn't enough. This patch however seems to finally fix the issue:

 diff --git a/clang/lib/Analysis/UninitializedValues.cpp b/clang/lib/Analysis/UninitializedValues.cpp
index 6e5da25..181ed40 100644
--- a/clang/lib/Analysis/UninitializedValues.cpp
+++ b/clang/lib/Analysis/UninitializedValues.cpp
@@ -614,6 +614,7 @@ void TransferFunctions::ProcessUses(Stmt *s) {
 // High-level "driver" logic for uninitialized values analysis.
 //====------------------------------------------------------------------------//
 
+__attribute__((optimize ("-fno-inline")))
 static bool runOnBlock(const CFGBlock *block, const CFG &cfg,
                        AnalysisDeclContext &ac, CFGBlockValues &vals,
                        llvm::BitVector &wasAnalyzed,
Comment 17 octoploid 2012-04-28 05:36:09 PDT
According to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53147
 
  const CFGStmt *cstmt = block->front().getAs<CFGStmt>();

block->front() returns a temp variable which ends its life after the statement ends.

The following patch fixes this me:

diff --git a/clang/lib/Analysis/UninitializedValues.cpp b/clang/lib/Analysis/UninitializedValues.cpp
index 6e5da25..ae3030a 100644
--- a/clang/lib/Analysis/UninitializedValues.cpp
+++ b/clang/lib/Analysis/UninitializedValues.cpp
@@ -168,7 +168,8 @@ static const BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) {
   if (block->empty())
     return 0;
 
-  const CFGStmt *cstmt = block->front().getAs<CFGStmt>();
+  CFGElement bf = block->front();
+  const CFGStmt *cstmt = bf.getAs<CFGStmt>();
   if (!cstmt)
     return 0;
Comment 18 Richard Smith 2012-04-29 19:07:24 PDT
*** Bug 12697 has been marked as a duplicate of this bug. ***
Comment 19 Richard Smith 2012-04-29 19:18:27 PDT
Many thanks (to you and Andrew Pinski) for tracking this down! Fixed in r155803.
Comment 20 octoploid 2012-05-04 06:26:24 PDT
(In reply to comment #19)
> Many thanks (to you and Andrew Pinski) for tracking this down! Fixed in
> r155803.

Just a ping. This fix should also be applied to the 3.1 branch.

Thanks.
Comment 21 octoploid 2012-05-11 10:17:41 PDT
*** Bug 12797 has been marked as a duplicate of this bug. ***