diff options
author | Chad Rosier <mcrosier@apple.com> | 2012-08-10 21:06:19 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@apple.com> | 2012-08-10 21:06:19 +0000 |
commit | e790bc32ca3eb7cc396b45071d7987776e965ed7 (patch) | |
tree | 170e01ed60a1f3174f53a8a7e59a2227459d6a78 | |
parent | bb5185c0ca3de4e7d91d011a83c902d7b02a2a1a (diff) |
[ms-inline asm] Fix a memory leak introduced in r161686.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161698 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Stmt.h | 6 | ||||
-rw-r--r-- | lib/AST/Stmt.cpp | 13 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 2 |
3 files changed, 13 insertions, 8 deletions
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 8d4bd1f583..cb2eabbaed 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -1633,13 +1633,13 @@ class MSAsmStmt : public Stmt { Token *AsmToks; unsigned *LineEnds; Stmt **Exprs; - std::string *Clobbers; + StringRef **Clobbers; public: MSAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, ArrayRef<Token> asmtoks, ArrayRef<unsigned> lineends, StringRef asmstr, - ArrayRef<std::string> clobbers, SourceLocation endloc); + ArrayRef<StringRef> clobbers, SourceLocation endloc); SourceLocation getAsmLoc() const { return AsmLoc; } void setAsmLoc(SourceLocation L) { AsmLoc = L; } @@ -1665,7 +1665,7 @@ public: //===--- Other ---===// unsigned getNumClobbers() const { return NumClobbers; } - StringRef getClobber(unsigned i) { return Clobbers[i]; } + StringRef *getClobber(unsigned i) { return Clobbers[i]; } SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(AsmLoc, EndLoc); diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 9bf9980004..c9cca556f4 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -586,7 +586,7 @@ AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, ArrayRef<Token> asmtoks, ArrayRef<unsigned> lineends, StringRef asmstr, - ArrayRef<std::string> clobbers, SourceLocation endloc) + ArrayRef<StringRef> clobbers, SourceLocation endloc) : Stmt(MSAsmStmtClass), AsmLoc(asmloc), EndLoc(endloc), AsmStr(asmstr.str()), IsSimple(issimple), IsVolatile(isvolatile), NumAsmToks(asmtoks.size()), NumLineEnds(lineends.size()), @@ -600,9 +600,14 @@ MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc, for (unsigned i = 0, e = NumLineEnds; i != e; ++i) LineEnds[i] = lineends[i]; - Clobbers = new (C) std::string[NumClobbers]; - for (unsigned i = 0, e = NumClobbers; i != e; ++i) - Clobbers[i] = clobbers[i]; + Clobbers = new (C) StringRef*[NumClobbers]; + for (unsigned i = 0, e = NumClobbers; i != e; ++i) { + // FIXME: Avoid the allocation/copy if at all possible. + size_t size = clobbers[i].size(); + char *dest = new (C) char[size]; + std::strncpy(dest, clobbers[i].data(), size); + Clobbers[i] = new (C) StringRef(dest, size); + } } ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 716f4df526..e72495fc7b 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -2883,7 +2883,7 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation EndLoc) { // MS-style inline assembly is not fully supported, so emit a warning. Diag(AsmLoc, diag::warn_unsupported_msasm); - SmallVector<std::string,4> Clobbers; + SmallVector<StringRef,4> Clobbers; // Empty asm statements don't need to instantiate the AsmParser, etc. if (AsmToks.empty()) { |