[cfe-commits] r161698 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/Stmt.cpp lib/Sema/SemaStmt.cpp
Chad Rosier
mcrosier at apple.com
Fri Aug 10 14:06:19 PDT 2012
Author: mcrosier
Date: Fri Aug 10 16:06:19 2012
New Revision: 161698
URL: http://llvm.org/viewvc/llvm-project?rev=161698&view=rev
Log:
[ms-inline asm] Fix a memory leak introduced in r161686.
Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/Stmt.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=161698&r1=161697&r2=161698&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Aug 10 16:06:19 2012
@@ -1633,13 +1633,13 @@
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 @@
//===--- 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);
Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=161698&r1=161697&r2=161698&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Fri Aug 10 16:06:19 2012
@@ -586,7 +586,7 @@
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 @@
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,
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=161698&r1=161697&r2=161698&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Aug 10 16:06:19 2012
@@ -2883,7 +2883,7 @@
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()) {
More information about the cfe-commits
mailing list