[llvm-bugs] [Bug 44494] New: Crash when using unique_ptr with deleter

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 8 16:51:28 PST 2020


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

            Bug ID: 44494
           Summary: Crash when using unique_ptr with deleter
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: qiuc12 at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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: 

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

-- 
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/20200109/b6918478/attachment-0001.html>


More information about the llvm-bugs mailing list