Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Crash when using unique_ptr with deleter #43464

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR44494
Status NEW
Importance P release blocker
Reported by Chuan Qiu (qiuc12@gmail.com)
Reported on 2020-01-08 16:51:28 -0800
Last modified on 2020-01-08 16:58:37 -0800
Version 9.0
Hardware PC Linux
CC blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Compiling the following code with c++17 crashes. clang 9.0.1(with an irrelevant
local commit)

#include <memory>

std::unique_ptr<void, void (&)(void*)> NewAligned(const size_t size) {
  void* ptr = nullptr;
  if (posix_memalign(&ptr, 4 * 1024, size) != 0) {
    return std::unique_ptr<void, void (&)(void*)>(nullptr, free);
  }
  std::unique_ptr<void, void (&)(void*)> uptr(ptr, free);
  return uptr;
}

size_t g();

void use_pointer(void *p);

void use(){
  auto x = NewAligned(g());
  use_pointer(x.get());
}

This method is used in some version of rocksdb, io_posix.cc

clang-9: /home/c/llvm-project/clang/lib/CodeGen/CodeGenFunction.h:4270: void
clang::CodeGen::CodeGenFunction::EmitCallArgs(clang::CodeGen::CallArgList&,
const T*, llvm::iterator_range<clang::Stmt::CastIterator<clang::Expr, const
clang::Expr* const, const clang::Stmt* const> >,
clang::CodeGen::CodeGenFunction::AbstractCallee, unsigned int,
clang::CodeGen::CodeGenFunction::EvaluationOrder) [with T =
clang::FunctionProtoType]: Assertion `(isGenericMethod || ((*I)-
>isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType()
|| getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() ==
getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && "type
mismatch in call argument!"' failed.
Stack dump:
0.      Program arguments: /home/c/clang/bin/clang-9 -cc1 -triple x86_64-
unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
uniq_ptr.cc -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 -coverage-
notes-file /home/c/play/uniq_ptr.gcno -resource-dir
/home/c/clang/lib/clang/9.0.1 -internal-isystem
/home/c/play/../clang/bin/../lib/gcc/x86_64-linux-
gnu/7.4.0/../../../../include/c++/7.4.0 -internal-isystem
/home/c/play/../clang/bin/../lib/gcc/x86_64-linux-
gnu/7.4.0/../../../../include/x86_64-linux-gnu/c++/7.4.0 -internal-isystem
/home/c/play/../clang/bin/../lib/gcc/x86_64-linux-
gnu/7.4.0/../../../../include/x86_64-linux-gnu/c++/7.4.0 -internal-isystem
/home/c/play/../clang/bin/../lib/gcc/x86_64-linux-
gnu/7.4.0/../../../../include/c++/7.4.0/backward -internal-isystem
/usr/local/include -internal-isystem /home/c/clang/lib/clang/9.0.1/include -
internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-
isystem /include -internal-externc-isystem /usr/include --std=c++17 -
fdeprecated-macro -fdebug-compilation-dir /home/c/play -ferror-limit 19 -
fmessage-length 0 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -
fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o uniq_ptr.o -x c++
uniq_ptr.cc
1.      uniq_ptr.cc:12:1: current parser token 'size_t'
2.      uniq_ptr.cc:3:40: LLVM IR generation of declaration 'NewAligned'
3.      uniq_ptr.cc:3:40: Generating code for declaration 'NewAligned'
4.      uniq_ptr.cc:5:50: LLVM IR generation of compound statement ('{}')
/home/c/clang/bin/clang-9(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x2a)[0x27a548a]
/home/c/clang/bin/clang-9(_ZN4llvm3sys17RunSignalHandlersEv+0x4c)[0x27a2fbc]
/home/c/clang/bin/clang-9[0x27a3129]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f56660c5390]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7f5664e37428]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f5664e3902a]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dbd7)[0x7f5664e2fbd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f5664e2fc82]
/home/c/clang/bin/clang-9[0x2ac5b32]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction22EmitCXXConstructorCallEPKNS_18CXXConstructorDeclENS_11CXXCtorTypeEbbNS0_12AggValueSlotEPKNS_16CXXConstructExprE+0x25f)[0x2b9df8f]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction20EmitCXXConstructExprEPKNS_16CXXConstructExprENS0_12AggValueSlotE+0x35f)[0x2c0387f]
/home/c/clang/bin/clang-9[0x9e59f7]
/home/c/clang/bin/clang-9[0x2bf83b0]
/home/c/clang/bin/clang-9[0x2bf9717]
/home/c/clang/bin/clang-9[0x2bf8aad]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction11EmitAggExprEPKNS_4ExprENS0_12AggValueSlotE+0xde)[0x2bf981e]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction14EmitReturnStmtERKNS_10ReturnStmtE+0x525)[0x29f66e5]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction8EmitStmtEPKNS_4StmtEN4llvm8ArrayRefIPKNS_4AttrEEE+0x5a2)[0x29f8742]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction28EmitCompoundStmtWithoutScopeERKNS_12CompoundStmtEbNS0_12AggValueSlotE+0x254)[0x29f9564]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction16EmitCompoundStmtERKNS_12CompoundStmtEbNS0_12AggValueSlotE+0x157)[0x29f9777]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction14EmitSimpleStmtEPKNS_4StmtE+0x66)[0x29fc8c6]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction8EmitStmtEPKNS_4StmtEN4llvm8ArrayRefIPKNS_4AttrEEE+0x55)[0x29f81f5]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction10EmitIfStmtERKNS_6IfStmtE+0x413)[0x29f9c43]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction8EmitStmtEPKNS_4StmtEN4llvm8ArrayRefIPKNS_4AttrEEE+0x4f3)[0x29f8693]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction28EmitCompoundStmtWithoutScopeERKNS_12CompoundStmtEbNS0_12AggValueSlotE+0x254)[0x29f9564]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction16EmitFunctionBodyEPKNS_4StmtE+0x83)[0x2a34423]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen15CodeGenFunction12GenerateCodeENS_10GlobalDeclEPN4llvm8FunctionERKNS0_14CGFunctionInfoE+0x1f3)[0x2a42f33]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen13CodeGenModule28EmitGlobalFunctionDefinitionENS_10GlobalDeclEPN4llvm11GlobalValueE+0x1fa)[0x2a7841a]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen13CodeGenModule20EmitGlobalDefinitionENS_10GlobalDeclEPN4llvm11GlobalValueE+0x2d3)[0x2a75de3]
/home/c/clang/bin/clang-9(_ZN5clang7CodeGen13CodeGenModule10EmitGlobalENS_10GlobalDeclE+0x62b)[0x2a7645b]
/home/c/clang/bin/clang-9[0x2a7bf79]
/home/c/clang/bin/clang-9[0x33c874b]
/home/c/clang/bin/clang-9[0x33beacb]
/home/c/clang/bin/clang-9(_ZN5clang8ParseASTERNS_4SemaEbb+0x218)[0x3c52c58]
/home/c/clang/bin/clang-9(_ZN5clang13CodeGenAction13ExecuteActionEv+0x4f)[0x33c503f]
/home/c/clang/bin/clang-9(_ZN5clang14FrontendAction7ExecuteEv+0x1a9)[0x2e56de9]
/home/c/clang/bin/clang-9(_ZN5clang16CompilerInstance13ExecuteActionERNS_14FrontendActionE+0x3e8)[0x2e1e0e8]
/home/c/clang/bin/clang-9(_ZN5clang25ExecuteCompilerInvocationEPNS_16CompilerInstanceE+0xac2)[0x2ef8f22]
/home/c/clang/bin/clang-9(_Z8cc1_mainN4llvm8ArrayRefIPKcEES2_Pv+0xc20)[0xb4fb10]
/home/c/clang/bin/clang-9(main+0x1229)[0xab6c29]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f5664e22830]
/home/c/clang/bin/clang-9(_start+0x29)[0xb4b819]
clang-9: error: unable to execute command: Aborted (core dumped)
clang-9: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 9.0.1 (https://github.com/llvm/llvm-project.git
75f7d0e99635153658aff5aa3c8fed2280a6d1ca)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/c/play/../clang/bin
clang-9: note: diagnostic msg: PLEASE submit a bug report to
https://bugs.llvm.org/ and include the crash backtrace, preprocessed source,
and associated run script.
clang-9: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-9: note: diagnostic msg: /tmp/uniq_ptr-650d3d.cpp
clang-9: note: diagnostic msg: /tmp/uniq_ptr-650d3d.sh
clang-9: note: diagnostic msg:

********************
Quuxplusone commented 4 years ago

use libstdc++ from gcc 7.4.0

Diagnostic msg too big to upload.

Quuxplusone commented 4 years ago
Change the return type to std::unique_ptr<char, void (&)(char*)> fixed the
problem.