[LLVMbugs] [Bug 13431] New: clang++ segfault

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jul 22 08:58:04 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13431

             Bug #: 13431
           Summary: clang++ segfault
           Product: clang
           Version: 3.1
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: mitas.piotr at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 8936
  --> http://llvm.org/bugs/attachment.cgi?id=8936
main-yIykyR.ii

clang++ segfaults when compiling the following code, copied directly from Bruce
Eckel's Thinking in C++ vol. 2:

#include <iostream>
#include <new>       // For std::bad_alloc
#include <cstring>
#include <cstddef>
using namespace std;

// A class that has two pointer members using the heap
class HasPointers {
  // A Handle class to hold the data
  struct MyData {
    const char* theString;
    const int* theInts;
    size_t numInts;
    MyData(const char* pString, const int* pInts,
      size_t nInts)
    : theString(pString), theInts(pInts), numInts(nInts) {}
  } *theData;  // The handle
  // Clone and cleanup functions:
  static MyData* clone(const char* otherString,
      const int* otherInts, size_t nInts) {
    char* newChars = new char[strlen(otherString)+1];
    int* newInts;
    try {
      newInts = new int[nInts];
    } catch(bad_alloc&) {
      delete [] newChars;
      throw;
    }
    try {
      // This example uses built-in types, so it won't
      // throw, but for class types it could throw, so we
      // use a try block for illustration. (This is the
      // point of the example!)
      strcpy(newChars, otherString);
      for(size_t i = 0; i < nInts; ++i)
    newInts[i] = otherInts[i];
    } catch(...) {
      delete [] newInts;
      delete [] newChars;
      throw;
    }
    return new MyData(newChars, newInts, nInts);
  }
  static MyData* clone(const MyData* otherData) {
    return clone(otherData->theString, otherData->theInts,
         otherData->numInts);
  }
  static void cleanup(const MyData* theData) {
    delete [] theData->theString;
    delete [] theData->theInts;
    delete theData;
  }
public:
  HasPointers(const char* someString, const int* someInts,
          size_t numInts) {
    theData = clone(someString, someInts, numInts);
  }
  HasPointers(const HasPointers& source) {
    theData = clone(source.theData);
  }
  HasPointers& operator=(const HasPointers& rhs) {
    if(this != &rhs) {
      MyData* newData = clone(rhs.theData->theString,
    rhs.theData->theInts, rhs.theData->numInts);
      cleanup(theData);
      theData = newData;
    }
    return *this;
  }
  ~HasPointers() { cleanup(theData); }
  friend ostream&
  operator<<(ostream& os, const HasPointers& obj) {
    os << obj.theData->theString << ": ";
    for(size_t i = 0; i < obj.theData->numInts; ++i)
      os << obj.theData->theInts[i] << ' ';
    return os;
  }
};

int main() {
  int someNums[] = { 1, 2, 3, 4 };
  size_t someCount = sizeof someNums / sizeof someNums[0];
  int someMoreNums[] = { 5, 6, 7 };
  size_t someMoreCount =
  sizeof someMoreNums / sizeof someMoreNums[0];
  HasPointers h1("Hello", someNums, someCount);
  HasPointers h2("Goodbye", someMoreNums, someMoreCount);
  cout << h1 << endl;  // Hello: 1 2 3 4
  h1 = h2;
  cout << h1 << endl;  // Goodbye: 5 6 7
}

---

$ clang++ main.cpp 
0  libLLVM-3.1.so  0x00007f3deed1f55f
1  libLLVM-3.1.so  0x00007f3deed1f9c9
2  libpthread.so.0 0x00007f3dee4d6410
3  libLLVM-3.1.so  0x00007f3deefd9e80
llvm::ComputeValueVTs(llvm::TargetLowering const&, llvm::Type*,
llvm::SmallVectorImpl<llvm::EVT>&, llvm::SmallVectorImpl<unsigned long>*,
unsigned long) + 32
4  libLLVM-3.1.so  0x00007f3deeae2db4
llvm::SelectionDAGBuilder::visitExtractValue(llvm::ExtractValueInst const&) +
148
5  libLLVM-3.1.so  0x00007f3deeac923c llvm::SelectionDAGBuilder::visit(unsigned
int, llvm::User const&) + 220
6  libLLVM-3.1.so  0x00007f3deeaed812
llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) + 50
7  libLLVM-3.1.so  0x00007f3deeafe941
llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction
const>, llvm::ilist_iterator<llvm::Instruction const>, bool&) + 49
8  libLLVM-3.1.so  0x00007f3deeaff0e4
llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 1796
9  libLLVM-3.1.so  0x00007f3deeb002c6
llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 422
10 libLLVM-3.1.so  0x00007f3deee8b05f
llvm::FPPassManager::runOnFunction(llvm::Function&) + 575
11 libLLVM-3.1.so  0x00007f3deee8b0a3
llvm::FPPassManager::runOnModule(llvm::Module&) + 51
12 libLLVM-3.1.so  0x00007f3deee8ad24
llvm::MPPassManager::runOnModule(llvm::Module&) + 484
13 libLLVM-3.1.so  0x00007f3deee8adeb llvm::PassManagerImpl::run(llvm::Module&)
+ 107
14 clang           0x000000000070fc58
clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions
const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::Module*,
clang::BackendAction, llvm::raw_ostream*) + 1912
15 clang           0x000000000070de92
16 clang           0x00000000008357fd clang::ParseAST(clang::Sema&, bool, bool)
+ 461
17 clang           0x00000000005e4216
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 262
18 clang           0x00000000005cd562
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1042
19 clang           0x00000000005c6d75 cc1_main(char const**, char const**, char
const*, void*) + 8869
20 clang           0x00000000005c3f46 main + 7030
21 libc.so.6       0x00007f3dedc224bd __libc_start_main + 253
22 clang           0x00000000005c4951
Stack dump:
0.      Program arguments: /usr/bin/clang -cc1 -triple x86_64-pc-linux-gnu
-emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name
main.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose
-mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version
2.22 -momit-leaf-frame-pointer -resource-dir /usr/bin/../lib/clang/3.1
-fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4 -internal-isystem
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/x86_64-pc-linux-gnu
-internal-isystem
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/backward
-internal-isystem /usr/local/include -internal-isystem
/usr/bin/../lib/clang/3.1/include -internal-externc-isystem /include
-internal-externc-isystem /usr/include -fdeprecated-macro
-fdebug-compilation-dir /home/piotrek/projekty/pierdoly -ferror-limit 19
-fmessage-length 172 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc
-fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o /tmp/main-g7GEyj.o -x c++
main.cpp 
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'main.cpp'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function
'@_ZN11HasPointers5cloneEPKcPKim'
clang: error: unable to execute command: Segmentation fault (core dumped)
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: /tmp/main-yIykyR.ii
clang: note: diagnostic msg: /tmp/main-yIykyR.sh

---

$ clang -v
clang version 3.1 (branches/release_31)
Target: x86_64-pc-linux-gnu
Thread model: posix

---

$ cat /tmp/main-yIykyR.sh
 "/usr/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all
-disable-free -disable-llvm-verifier -main-file-name main.cpp
-mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases
-munwind-tables -target-cpu x86-64 -target-linker-version 2.22
-momit-leaf-frame-pointer -resource-dir /usr/bin/../lib/clang/3.1
-fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4 -internal-isystem
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/x86_64-pc-linux-gnu
-internal-isystem
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/backward
-internal-isystem /usr/local/include -internal-isystem
/usr/bin/../lib/clang/3.1/include -internal-externc-isystem /include
-internal-externc-isystem /usr/include -fdeprecated-macro
-fdebug-compilation-dir /home/piotrek/projekty/pierdoly -ferror-limit 19
-fmessage-length 172 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc
-fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o /tmp/main-g7GEyj.o -x c++
main.cpp
 "/usr/bin/x86_64-pc-linux-gnu-ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -o a.out
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/../../../../lib64/crt1.o
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/crtbegin.o
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/../../../../lib64 -L/lib/../lib64
-L/usr/lib/../lib64
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/../../../../x86_64-pc-linux-gnu/lib
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/../../.. -L/lib -L/usr/lib
/tmp/main-g7GEyj.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/crtend.o
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/../../../../lib64/crtn.o

---

gdb backtrace:

#0  getTypeID (this=<optimized out>) at
/var/tmp/portage/sys-devel/llvm-3.1-r2/work/llvm-3.1.src/include/llvm/Type.h:133
#1  classof (T=0x0) at
/var/tmp/portage/sys-devel/llvm-3.1-r2/work/llvm-3.1.src/include/llvm/DerivedTypes.h:297
#2  doit (Val=...) at
/var/tmp/portage/sys-devel/llvm-3.1-r2/work/llvm-3.1.src/include/llvm/Support/Casting.h:50
#3  doit (Val=0x0) at
/var/tmp/portage/sys-devel/llvm-3.1-r2/work/llvm-3.1.src/include/llvm/Support/Casting.h:68
#4  doit (Val=<optimized out>) at
/var/tmp/portage/sys-devel/llvm-3.1-r2/work/llvm-3.1.src/include/llvm/Support/Casting.h:99
#5  isa<llvm::StructType, llvm::Type*> (Val=<optimized out>) at
/var/tmp/portage/sys-devel/llvm-3.1-r2/work/llvm-3.1.src/include/llvm/Support/Casting.h:110
#6  dyn_cast<llvm::StructType, llvm::Type*> (Val=<optimized out>) at
/var/tmp/portage/sys-devel/llvm-3.1-r2/work/llvm-3.1.src/include/llvm/Support/Casting.h:220
#7  llvm::ComputeValueVTs (TLI=..., Ty=0x0, ValueVTs=..., Offsets=0x0,
StartingOffset=0) at Analysis.cpp:81
#8  0x00007f9f2f5a1db4 in llvm::SelectionDAGBuilder::visitExtractValue
(this=0x1ce9ff0, I=...) at SelectionDAGBuilder.cpp:3047
#9  0x00007f9f2f58823c in llvm::SelectionDAGBuilder::visit (this=0x1ce9ff0,
Opcode=<optimized out>, I=...)
    at
/var/tmp/portage/sys-devel/llvm-3.1-r2/work/llvm-3.1.src/include/llvm/Instruction.def:172
#10 0x00007f9f2f5ac812 in llvm::SelectionDAGBuilder::visit (this=0x1ce9ff0,
I=...) at SelectionDAGBuilder.cpp:925
#11 0x00007f9f2f5bd941 in llvm::SelectionDAGISel::SelectBasicBlock
(this=this at entry=0x1ce93c0, Begin=..., Begin at entry=..., End=..., End at entry=..., 
    HadTailCall=@0x7fff6251fd2f: false) at SelectionDAGISel.cpp:494
#12 0x00007f9f2f5be0e4 in llvm::SelectionDAGISel::SelectAllBasicBlocks
(this=this at entry=0x1ce93c0, Fn=...) at SelectionDAGISel.cpp:1142
#13 0x00007f9f2f5bf2c6 in llvm::SelectionDAGISel::runOnMachineFunction
(this=0x1ce93c0, mf=...) at SelectionDAGISel.cpp:369
#14 0x00007f9f2f94a05f in runOnFunction (F=..., this=0x1ce70b0) at
PassManager.cpp:1479
#15 llvm::FPPassManager::runOnFunction (this=0x1ce70b0, F=...) at
PassManager.cpp:1457
#16 0x00007f9f2f94a0a3 in llvm::FPPassManager::runOnModule (this=0x1ce70b0,
M=...) at PassManager.cpp:1499
#17 0x00007f9f2f949d24 in llvm::MPPassManager::runOnModule (this=0x1cdc9d0,
M=...) at PassManager.cpp:1553
#18 0x00007f9f2f949deb in llvm::PassManagerImpl::run (this=0x1cd2240, M=...) at
PassManager.cpp:1636
#19 0x000000000070fc58 in EmitAssembly (OS=0x16aa220, Action=<optimized out>,
this=0x7fff62520260) at BackendUtil.cpp:447
#20 clang::EmitBackendOutput (Diags=..., CGOpts=..., TOpts=..., LOpts=...,
M=<optimized out>, Action=<optimized out>, OS=0x16aa220) at BackendUtil.cpp:459
#21 0x000000000070de92 in HandleTranslationUnit (this=0x16b3750, C=...) at
CodeGenAction.cpp:160
#22 clang::BackendConsumer::HandleTranslationUnit (this=0x16b3750, C=...) at
CodeGenAction.cpp:111
#23 0x00000000008357fd in clang::ParseAST (S=..., PrintStats=false,
SkipFunctionBodies=<optimized out>) at ParseAST.cpp:108
#24 0x00000000005e4216 in clang::CompilerInstance::ExecuteAction
(this=0x1683fb0, Act=...) at CompilerInstance.cpp:676
#25 0x00000000005cd562 in clang::ExecuteCompilerInvocation (Clang=0x1683fb0) at
ExecuteCompilerInvocation.cpp:183
#26 0x00000000005c6d75 in cc1_main (ArgBegin=0x7fff62521c30,
ArgEnd=0x7fff62521e00, Argv0=<optimized out>, MainAddr=0x5cc080) at
cc1_main.cpp:165
#27 0x00000000005c3f46 in main (argc_=<optimized out>, argv_=<optimized out>)
at driver.cpp:358

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list