[llvm-bugs] [Bug 33466] New: Clang crashes with -fblocks when _NSConcrete*Block arrays are not explicitly zeroed out

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 14 18:58:05 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=33466

            Bug ID: 33466
           Summary: Clang crashes with -fblocks when _NSConcrete*Block
                    arrays are not explicitly zeroed out
           Product: clang
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: remi at qumulo.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 18641
  --> https://bugs.llvm.org/attachment.cgi?id=18641&action=edit
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
http://llvm.org/bugs/ 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:

********************

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170615/91dbbd80/attachment.html>


More information about the llvm-bugs mailing list