From 12dc3f5c2834baa432e84f140a7b82fed2c2d2dd Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Fri, 27 Jan 2012 16:49:09 -0800 Subject: [PATCH] Fixes to c++ backend for new and delete Don't include declarations of malloc/free in the generated code (get the standard ones from system headers instead). Add a cast to (uint8_t *) before calls to malloc, which C++ requires, since proper malloc returns a void *. --- cbackend.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cbackend.cpp b/cbackend.cpp index b800d4ac..314b53d6 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -2114,7 +2114,8 @@ bool CWriter::doInitialization(Module &M) { I->getName() == "memset" || I->getName() == "memset_pattern16" || I->getName() == "puts" || I->getName() == "printf" || I->getName() == "putchar" || - I->getName() == "fflush") + I->getName() == "fflush" || I->getName() == "malloc" || + I->getName() == "free") continue; // Don't redeclare ispc's own intrinsics @@ -3437,6 +3438,9 @@ void CWriter::visitCallInst(CallInst &I) { Callee = RF; } + if (Callee->getName() == "malloc") + Out << "(uint8_t *)"; + if (NeedsCast) { // Ok, just cast the pointer type. Out << "((";