From af69672dc7e351f29ed9c35edafcf51f08250cfe Mon Sep 17 00:00:00 2001 From: kai Date: Tue, 28 Aug 2012 06:52:29 +0200 Subject: [PATCH] Fixed a bug regarding lifetime of C strings. The string returned by c_str() is only valid as long as the object exists. Now the object 'triple' exists until the end. --- driver/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/driver/main.cpp b/driver/main.cpp index e570907a..f768e7df 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -477,6 +477,8 @@ int main(int argc, char** argv) #endif } + std::string triple; + // did the user override the target triple? if (mTargetTriple.empty()) { @@ -485,14 +487,14 @@ int main(int argc, char** argv) error("you must specify a target triple as well with -mtriple when using the -march option"); fatal(); } - global.params.targetTriple = defaultTriple.c_str(); + triple = defaultTriple; } else { - global.params.targetTriple = llvm::Triple::normalize(mTargetTriple).c_str(); + triple = llvm::Triple::normalize(mTargetTriple); } - std::string triple = global.params.targetTriple; + global.params.targetTriple = triple.c_str(); // Allocate target machine. const llvm::Target *theTarget = NULL;