[LLVMbugs] [Bug 10224] New: iostream broken in clang++

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jun 29 05:49:54 PDT 2011


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

           Summary: iostream broken in clang++
           Product: clang
           Version: trunk
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: howarth at nitro.med.uc.edu
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


The simple iostream example code...

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

is miscompiled by clang++ svn r134030 at all optimization levels. The default
optimization fails as...

[MacPro:~] howarth% /sw/opt/llvm-3.0/bin/clang++ test.cc
Stack dump:
0.    Program arguments: /sw/opt/llvm-3.0/bin/clang-3.0 -cc1 -triple
x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all -disable-free
-disable-llvm-verifier -main-file-name test.cc -pic-level 1 -mdisable-fp-elim
-masm-verbose -munwind-tables -target-cpu core2 -resource-dir
/sw/opt/llvm-3.0/bin/../lib/clang/3.0 -fdeprecated-macro -ferror-limit 19
-fmessage-length 177 -stack-protector 1 -fblocks -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o
/var/folders/1l/n78sywl52lz6kkys6nv7mnph0000gp/T/cc-47ABTv.o -x c++ test.cc 
1.    <eof> parser at end of file
2.    Code generation
3.    Running pass 'Function Pass Manager' on module 'test.cc'.
4.    Running pass 'X86 DAG->DAG Instruction Selection' on function
'@__cxx_global_var_init'
clang-3: error: unable to execute command: Segmentation fault: 11
clang-3: error: clang frontend command failed due to signal 2 (use -v to see
invocation)

which backtraces as...


[MacPro:~] howarth% gdb /sw/opt/llvm-3.0/bin/clang-3.0
GNU gdb 6.3.50-20050815 (Apple version gdb-1657) (Tue May 17 04:19:06 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared
libraries ... done

(gdb) r  -cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all
-disable-free -disable-llvm-verifier -main-file-name test.cc -pic-level 1
-mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -resource-dir
/sw/opt/llvm-3.0/bin/../lib/clang/3.0 -fdeprecated-macro -ferror-limit 19
-fmessage-length 177 -stack-protector 1 -fblocks -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o
/var/folders/1l/n78sywl52lz6kkys6nv7mnph0000gp/T/cc-47ABTv.o -x c++ test.cc 
Starting program: /sw/opt/llvm-3.0/bin/clang-3.0 -cc1 -triple
x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all -disable-free
-disable-llvm-verifier -main-file-name test.cc -pic-level 1 -mdisable-fp-elim
-masm-verbose -munwind-tables -target-cpu core2 -resource-dir
/sw/opt/llvm-3.0/bin/../lib/clang/3.0 -fdeprecated-macro -ferror-limit 19
-fmessage-length 177 -stack-protector 1 -fblocks -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o
/var/folders/1l/n78sywl52lz6kkys6nv7mnph0000gp/T/cc-47ABTv.o -x c++ test.cc
Reading symbols for shared libraries ++......................... done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x00000039010f0090
0x0000000100a95497 in llvm::MachineInstr::MachineInstr ()
(gdb) bt
#0  0x0000000100a95497 in llvm::MachineInstr::MachineInstr ()
#1  0x0000000100a8f79e in llvm::MachineFunction::CreateMachineInstr ()
#2  0x000000010079fb61 in (anonymous namespace)::X86FastISel::DoSelectCall ()
#3  0x0000000100794624 in (anonymous
namespace)::X86FastISel::TargetSelectInstruction ()
#4  0x0000000100918925 in llvm::FastISel::SelectInstruction ()
#5  0x00000001009fca59 in llvm::SelectionDAGISel::SelectAllBasicBlocks ()
#6  0x00000001009fbc19 in llvm::SelectionDAGISel::runOnMachineFunction ()
#7  0x0000000100a9339e in llvm::MachineFunctionPass::runOnFunction ()
#8  0x0000000100d88061 in llvm::FPPassManager::runOnFunction ()
#9  0x0000000100d882fb in llvm::FPPassManager::runOnModule ()
#10 0x0000000100d88496 in llvm::MPPassManager::runOnModule ()
#11 0x0000000100d88a38 in llvm::PassManagerImpl::run ()
#12 0x0000000100d88f4d in llvm::PassManager::run ()
#13 0x0000000100117786 in clang::EmitBackendOutput ()
#14 0x00000001001fd335 in clang::BackendConsumer::HandleTranslationUnit ()
#15 0x00000001002dd913 in clang::ParseAST ()
#16 0x00000001001fc555 in clang::CodeGenAction::ExecuteAction ()
#17 0x0000000100279c9a in clang::CompilerInstance::ExecuteAction ()
#18 0x00000001002aee38 in clang::ExecuteCompilerInvocation ()
#19 0x0000000100005b77 in cc1_main ()
#20 0x0000000100001526 in main ()
(gdb) 

At -O1 and higher, the compiler doesn't ICE but the resulting executable
crashes with a segmentation fault...


[MacPro:~] howarth% /sw/opt/llvm-3.0/bin/clang++ -O1 -g  test.cc
[MacPro:~] howarth% gdb ./a.out
GNU gdb 6.3.50-20050815 (Apple version gdb-1657) (Tue May 17 04:19:06 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared
libraries ... done

(gdb) r
Starting program: /Users/howarth/a.out 
Reading symbols for shared libraries ++......................... done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00007fff8f06d6cd in misaligned_stack_error_entering_dyld_stub_binder ()
(gdb) bt
#0  0x00007fff8f06d6cd in misaligned_stack_error_entering_dyld_stub_binder ()
#1  0x00000001000010b0 in pvars ()
#2  0x0000000100001030 in pvars ()
#3  0x00007fff5fc0fd1a in
__dyld__ZN16ImageLoaderMachO18doModInitFunctionsERKN11ImageLoader11LinkContextE
()
#4  0x00007fff5fc0fa66 in
__dyld__ZN16ImageLoaderMachO16doInitializationERKN11ImageLoader11LinkContextE
()
#5  0x00007fff5fc0d258 in
__dyld__ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextEjRNS_21InitializerTimingListE
()
#6  0x00007fff5fc0e02b in
__dyld__ZN11ImageLoader15runInitializersERKNS_11LinkContextERNS_21InitializerTimingListE
()
#7  0x00007fff5fc034ad in __dyld__ZN4dyld24initializeMainExecutableEv ()
#8  0x00007fff5fc07580 in __dyld__ZN4dyld5_mainEPK12macho_headermiPPKcS5_S5_ ()
#9  0x00007fff5fc01059 in __dyld__dyld_start ()
(gdb)

-- 
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