<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Clang crashes with -fblocks when _NSConcrete*Block arrays are not explicitly zeroed out"
   href="https://bugs.llvm.org/show_bug.cgi?id=33466">33466</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang crashes with -fblocks when _NSConcrete*Block arrays are not explicitly zeroed out
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>remi@qumulo.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18641" name="attach_18641" title="This is the source that caused the crash">attachment 18641</a> <a href="attachment.cgi?id=18641&action=edit" title="This is the source that caused the crash">[details]</a></span>
This is the source that caused the crash

I've been experimenting with providing my own implementation of the blocks
runtime and in my runtime I have code like follows which the compiler seems to
need exist when you use blocks:

void * _NSConcreteStackBlock[32];
void * _NSConcreteGlobalBlock[32];

When I did this, sometimes the compiler would crash (I've included the stack
below)

If I change these variables to instead be:

void * _NSConcreteStackBlock[32] = { 0 };
void * _NSConcreteGlobalBlock[32] = { 0 };

the crash goes away.

I've included the source code I compiled as an attachment.

I'm compiling this on Ubuntu 17.04 and this is my clang version:
clang version 4.0.0-1ubuntu1 (tags/RELEASE_400/rc1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

To compile the source I just ran:
/usr/bin/clang -fblocks blocks_crash.c

#0 0x00007fd8d6c73488 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/lib/llvm-4.0/bin/../lib/libLLVM-4.0.so.1+0x6ee488)
#1 0x00007fd8d6c7156e llvm::sys::RunSignalHandlers()
(/usr/lib/llvm-4.0/bin/../lib/libLLVM-4.0.so.1+0x6ec56e)
#2 0x00007fd8d6c716aa (/usr/lib/llvm-4.0/bin/../lib/libLLVM-4.0.so.1+0x6ec6aa)
#3 0x00007fd8d94f1670 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x11670)
#4 0x00007fd8d6d753d4 llvm::Value::getContext() const
(/usr/lib/llvm-4.0/bin/../lib/libLLVM-4.0.so.1+0x7f03d4)
#5 0x00007fd8d6caec04
llvm::ConstantStruct::getTypeForElements(llvm::ArrayRef<llvm::Constant*>, bool)
(/usr/lib/llvm-4.0/bin/../lib/lib
LLVM-4.0.so.1+0x729c04)
#6 0x000056373fe94908 (/usr/lib/llvm-4.0/bin/clang+0x697908)
#7 0x000056373fe94d0a
clang::CodeGen::CodeGenModule::GetAddrOfGlobalBlock(clang::BlockExpr const*,
llvm::StringRef) (/usr/lib/llvm-4.0/
bin/clang+0x697d0a)
#8 0x000056373fda2fec (/usr/lib/llvm-4.0/bin/clang+0x5a5fec)
#9 0x000056373fda397d
clang::CodeGen::CodeGenModule::EmitConstantValue(clang::APValue const&,
clang::QualType, clang::CodeGen::CodeGenF
unction*) (/usr/lib/llvm-4.0/bin/clang+0x5a697d)
#10 0x000056373fda40ef
clang::CodeGen::CodeGenModule::EmitConstantValueForMemory(clang::APValue
const&, clang::QualType, clang::CodeGen
::CodeGenFunction*) (/usr/lib/llvm-4.0/bin/clang+0x5a70ef)
#11 0x000056373fda694b
clang::CodeGen::CodeGenModule::EmitConstantInit(clang::VarDecl const&,
clang::CodeGen::CodeGenFunction*) (/usr/l
ib/llvm-4.0/bin/clang+0x5a994b)
#12 0x000056373fdfa2cc
clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*,
bool) (/usr/lib/llvm-4.0/bin/clang
+0x5fd2cc)
#13 0x000056373fe0f0bb
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*) (/usr/lib/llvm-4.0/bi
n/clang+0x6120bb)
#14 0x000056373fe0f30e clang::CodeGen::CodeGenModule::EmitDeferred()
(/usr/lib/llvm-4.0/bin/clang+0x61230e)
#15 0x000056373fe0f3e4 clang::CodeGen::CodeGenModule::Release()
(/usr/lib/llvm-4.0/bin/clang+0x6123e4)
#16 0x00005637401cfd27 (/usr/lib/llvm-4.0/bin/clang+0x9d2d27)
#17 0x00005637401cf695 (/usr/lib/llvm-4.0/bin/clang+0x9d2695)
#18 0x00005637402f15e8 clang::ParseAST(clang::Sema&, bool, bool)
(/usr/lib/llvm-4.0/bin/clang+0xaf45e8)
#19 0x00005637400a990e clang::FrontendAction::Execute()
(/usr/lib/llvm-4.0/bin/clang+0x8ac90e)
#20 0x000056374007a6f6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/usr/lib/llvm-4.0/bin/clang+0x87d6f6)
#21 0x000056374012bcd3
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/usr/lib/llvm-4.0/bin/clang+0x92ecd3)
#22 0x000056373fd404d8 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/lib/llvm-4.0/bin/clang+0x5434d8)
#23 0x000056373fd31576 main (/usr/lib/llvm-4.0/bin/clang+0x534576)
#24 0x00007fd8d57043f1 __libc_start_main
/build/glibc-cxyGtm/glibc-2.24/csu/../csu/libc-start.c:325:0
#25 0x000056373fd3e72a _start (/usr/lib/llvm-4.0/bin/clang+0x54172a)
Stack dump:
0.      Program arguments: /usr/lib/llvm-4.0/bin/clang -cc1 -triple
x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-ll
vm-verifier -discard-value-names -main-file-name blocks_crash.c
-mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath
-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array
-target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb
-resource-dir /usr/lib/llvm-4.0/bin/../lib/clang/4.0.0 -internal-isystem
/usr/local/include -internal-isystem /usr/lib/llvm-4.0/bin/../
lib/clang/4.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-is
ystem /usr/include -fdebug-compilation-dir /home/remi -ferror-limit 19
-fmessage-length 135 -fblocks -fobjc-runtime=gcc -fdiagnostics-s
how-option -fcolor-diagnostics -o /tmp/blocks_crash-df45b0.o -x c
blocks_crash.c
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      blocks_crash.c:4:15: Generating code for declaration 'f'
clang: error: unable to execute command: Segmentation fault
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 4.0.0-1ubuntu1 (tags/RELEASE_400/rc1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: PLEASE submit a bug report to
<a href="http://llvm.org/bugs/">http://llvm.org/bugs/</a> and include the crash backtrace, preprocessed source,
and associated run script.
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/blocks_crash-7c2199.c
clang: note: diagnostic msg: /tmp/blocks_crash-7c2199.sh
clang: note: diagnostic msg:

********************</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>