Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang segmentation fault/consumes all memory #16238

Open Quuxplusone opened 11 years ago

Quuxplusone commented 11 years ago
Bugzilla Link PR16239
Status NEW
Importance P normal
Reported by Tomasz Mikolajczyk (tmmikolajczyk@gmail.com)
Reported on 2013-06-06 03:22:54 -0700
Last modified on 2019-05-24 15:56:35 -0700
Version trunk
Hardware PC Linux
CC dblaikie@gmail.com, jryans@gmail.com, llvm-bugs@lists.llvm.org, pickensd@synopsys.com, rafael@espindo.la
Fixed by commit(s)
Attachments clang_crash.tar.gz (1891 bytes, application/gzip)
Blocks
Blocked by
See also
Created attachment 10635
the code and the requested compilation output

Clang crashes compiling the following code:

template<typename T>
struct Move
{
    Move(T t);
    T rsc;
};

class Foo
{
public:
    Foo() {}
    Foo(Move<Foo> m);

private:
    // NON-CONST ARGS. CLANG DOES NOT CRASH AND REPORTS PROPER DIAGNOSTICS WHEN THEY ARE CONST
    Foo(Foo&);
    Foo& operator=(Foo&);
};

Foo create()
{
    return Foo();
}

int main()
{
    create();
    return 0;
}

Please note that when the copy constructor and assignment operator argument is
defined as const l-value ref the compiler generates proper diagnostic.

The semantic of this piece of code is irrelevant. It is a fragment of something
bigger. What is important that when compiling a wider piece I'm not able to
share, the compiler sometimes consumes all the available memory and makes the
system unresponsive eventually. It's not easy to reproduce this behavior with
an equivalent code but hopefully it concerns the same issue as observed when
compiling the attached one.

This behavior happens on clang 3.2 and also on the latest repo version (git
rev. d87bd5627e5b78cb556d6c7b5aa76ae3d55d8acf).

The attached package contains all the requested information.

My env:
OS: ArchLinux,
uname -a
Linux 3.9.4-1-ARCH #1 SMP PREEMPT Sat May 25 16:14:55 CEST 2013 x86_64 GNU/Linux
glibc: 2.17.6
Quuxplusone commented 11 years ago

Attached clang_crash.tar.gz (1891 bytes, application/gzip): the code and the requested compilation output

Quuxplusone commented 11 years ago
Simplified a bit:

struct Move2;

struct Foo
{
    Foo(const Move2&);

    // NON-CONST ARGS. CLANG DOES NOT CRASH AND REPORTS PROPER DIAGNOSTICS WHEN THEY ARE CONST
    Foo(Foo&);
};

struct Move2 {
  Move2(Foo f);
};

Foo func();

int main() {
  Foo f = func();
}

The compiler ends up infinitely recursing through these stack frames:

#396 0x0000000002357d0d in PerformConstructorInitialization (S=..., Entity=...,
Kind=..., Args=..., Step=..., ConstructorInitRequiresZeroInit=@0x7fffff8ed89f:
false, IsListInitialization=false) at .../tools/clang/lib/Sema/SemaInit.cpp:5062
#397 0x0000000002352580 in clang::InitializationSequence::Perform
(this=0x7fffff8edae8, S=..., Entity=..., Kind=..., Args=..., ResultType=0x0) at
.../tools/clang/lib/Sema/SemaInit.cpp:5824
#398 0x0000000002358aa2 in clang::Sema::PerformCopyInitialization
(this=0x486c750, Entity=..., EqualLoc=..., Init=..., TopLevelOfInitList=false,
AllowExplicit=false) at .../tools/clang/lib/Sema/SemaInit.cpp:6928
#399 0x0000000002252a4a in clang::Sema::GatherArgumentsForCall (this=0x486c750,
CallLoc=..., FDecl=0x4889500, Proto=0x48894a0, FirstProtoArg=0, Args=...,
AllArgs=..., CallType=clang::Sema::VariadicDoesNotApply, AllowExplicit=false,
IsList
Initialization=false) at .../tools/clang/lib/Sema/SemaExpr.cpp:3960
#400 0x00000000021c05f8 in clang::Sema::CompleteConstructorCall
(this=0x486c750, Constructor=0x4889500, ArgsPtr=..., Loc=...,
ConvertedArgs=..., AllowExplicit=false, IsListInitialization=false) at
.../tools/clang/lib/Sema/SemaDeclCXX.cpp:10102