From 2eb9a257c86d6194ec572d8556f86af97452bebe Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 16 Jun 2003 22:29:09 +0000 Subject: [PATCH] Actually, change it to use explicit new/delete, which is more likely to be optimized INTO an alloca git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6727 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/InstrSelection/InstrForest.cpp | 5 +++-- lib/Support/SystemUtils.cpp | 13 +++++++------ lib/Target/SparcV9/InstrSelection/InstrForest.cpp | 5 +++-- support/lib/Support/SystemUtils.cpp | 13 +++++++------ tools/bugpoint/SystemUtils.cpp | 13 +++++++------ 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp index 9ff681805bf..ea2ccadab94 100644 --- a/lib/CodeGen/InstrSelection/InstrForest.cpp +++ b/lib/CodeGen/InstrSelection/InstrForest.cpp @@ -255,7 +255,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr) // if a fixed array is too small. // int numChildren = 0; - std::vector childArray(instr->getNumOperands()); + InstrTreeNode** childArray = new InstrTreeNode*[instr->getNumOperands()]; // // Walk the operands of the instruction @@ -362,6 +362,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr) assert(n == 1); setRightChild(parent, childArray[numChildren - 1]); } - + + delete [] childArray; return treeNode; } diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp index 6ecaf2b987c..51f3d18354d 100644 --- a/lib/Support/SystemUtils.cpp +++ b/lib/Support/SystemUtils.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -33,13 +32,13 @@ std::string getUniqueFilename(const std::string &FilenameBase) { return FilenameBase; // Couldn't open the file? Use it! // Create a pattern for mkstemp... - std::vector FNBuffer(FilenameBase.size()+8); - strcpy(&FNBuffer[0], FilenameBase.c_str()); - strcpy(&FNBuffer[FilenameBase.size()], "-XXXXXX"); + char *FNBuffer = new char[FilenameBase.size()+8]; + strcpy(FNBuffer, FilenameBase.c_str()); + strcpy(FNBuffer+FilenameBase.size(), "-XXXXXX"); // Agree on a temporary file name to use.... int TempFD; - if ((TempFD = mkstemp(&FNBuffer[0])) == -1) { + if ((TempFD = mkstemp(FNBuffer)) == -1) { std::cerr << "bugpoint: ERROR: Cannot create temporary file in the current " << " directory!\n"; exit(1); @@ -48,7 +47,9 @@ std::string getUniqueFilename(const std::string &FilenameBase) { // We don't need to hold the temp file descriptor... we will trust that noone // will overwrite/delete the file while we are working on it... close(TempFD); - return std::string(&FNBuffer[0]); + std::string Result(FNBuffer); + delete[] FNBuffer; + return Result; } /// isExecutableFile - This function returns true if the filename specified diff --git a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp index 9ff681805bf..ea2ccadab94 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp @@ -255,7 +255,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr) // if a fixed array is too small. // int numChildren = 0; - std::vector childArray(instr->getNumOperands()); + InstrTreeNode** childArray = new InstrTreeNode*[instr->getNumOperands()]; // // Walk the operands of the instruction @@ -362,6 +362,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr) assert(n == 1); setRightChild(parent, childArray[numChildren - 1]); } - + + delete [] childArray; return treeNode; } diff --git a/support/lib/Support/SystemUtils.cpp b/support/lib/Support/SystemUtils.cpp index 6ecaf2b987c..51f3d18354d 100644 --- a/support/lib/Support/SystemUtils.cpp +++ b/support/lib/Support/SystemUtils.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -33,13 +32,13 @@ std::string getUniqueFilename(const std::string &FilenameBase) { return FilenameBase; // Couldn't open the file? Use it! // Create a pattern for mkstemp... - std::vector FNBuffer(FilenameBase.size()+8); - strcpy(&FNBuffer[0], FilenameBase.c_str()); - strcpy(&FNBuffer[FilenameBase.size()], "-XXXXXX"); + char *FNBuffer = new char[FilenameBase.size()+8]; + strcpy(FNBuffer, FilenameBase.c_str()); + strcpy(FNBuffer+FilenameBase.size(), "-XXXXXX"); // Agree on a temporary file name to use.... int TempFD; - if ((TempFD = mkstemp(&FNBuffer[0])) == -1) { + if ((TempFD = mkstemp(FNBuffer)) == -1) { std::cerr << "bugpoint: ERROR: Cannot create temporary file in the current " << " directory!\n"; exit(1); @@ -48,7 +47,9 @@ std::string getUniqueFilename(const std::string &FilenameBase) { // We don't need to hold the temp file descriptor... we will trust that noone // will overwrite/delete the file while we are working on it... close(TempFD); - return std::string(&FNBuffer[0]); + std::string Result(FNBuffer); + delete[] FNBuffer; + return Result; } /// isExecutableFile - This function returns true if the filename specified diff --git a/tools/bugpoint/SystemUtils.cpp b/tools/bugpoint/SystemUtils.cpp index 6ecaf2b987c..51f3d18354d 100644 --- a/tools/bugpoint/SystemUtils.cpp +++ b/tools/bugpoint/SystemUtils.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -33,13 +32,13 @@ std::string getUniqueFilename(const std::string &FilenameBase) { return FilenameBase; // Couldn't open the file? Use it! // Create a pattern for mkstemp... - std::vector FNBuffer(FilenameBase.size()+8); - strcpy(&FNBuffer[0], FilenameBase.c_str()); - strcpy(&FNBuffer[FilenameBase.size()], "-XXXXXX"); + char *FNBuffer = new char[FilenameBase.size()+8]; + strcpy(FNBuffer, FilenameBase.c_str()); + strcpy(FNBuffer+FilenameBase.size(), "-XXXXXX"); // Agree on a temporary file name to use.... int TempFD; - if ((TempFD = mkstemp(&FNBuffer[0])) == -1) { + if ((TempFD = mkstemp(FNBuffer)) == -1) { std::cerr << "bugpoint: ERROR: Cannot create temporary file in the current " << " directory!\n"; exit(1); @@ -48,7 +47,9 @@ std::string getUniqueFilename(const std::string &FilenameBase) { // We don't need to hold the temp file descriptor... we will trust that noone // will overwrite/delete the file while we are working on it... close(TempFD); - return std::string(&FNBuffer[0]); + std::string Result(FNBuffer); + delete[] FNBuffer; + return Result; } /// isExecutableFile - This function returns true if the filename specified