[UB] When attaching empty strings to the AST, use an empty StringRef

rather than forcing the bump pointer allocator to produce a viable
pointer. This also fixes UB when we would try to memcpy from the null
incoming StringRef.

llvm-svn: 243947
This commit is contained in:
Chandler Carruth 2015-08-04 03:52:58 +00:00
parent b6708d8ebf
commit f0c627d5f8
1 changed files with 2 additions and 0 deletions

View File

@ -724,6 +724,8 @@ MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
}
static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
if (str.empty())
return StringRef();
size_t size = str.size();
char *buffer = new (C) char[size];
memcpy(buffer, str.data(), size);