Make it explicit that nulls are not allowed in names.

The object files we support use null terminated strings, so there is no way to
support these.

This patch adds an assert to catch bad API use and an error check in the .ll
parser.

llvm-svn: 195155
This commit is contained in:
Rafael Espindola 2013-11-19 21:12:39 +00:00
parent 92045bc37c
commit 09d689f90c
3 changed files with 12 additions and 0 deletions

View File

@ -275,6 +275,10 @@ lltok::Kind LLLexer::LexAt() {
if (CurChar == '"') {
StrVal.assign(TokStart+2, CurPtr-1);
UnEscapeLexed(StrVal);
if (StringRef(StrVal).find_first_of(0) != StringRef::npos) {
Error("Null bytes are not allowed in names");
return lltok::Error;
}
return lltok::GlobalVar;
}
}

View File

@ -182,6 +182,8 @@ void Value::setName(const Twine &NewName) {
SmallString<256> NameData;
StringRef NameRef = NewName.toStringRef(NameData);
assert(NameRef.find_first_of(0) == StringRef::npos &&
"Null bytes are not allowed in names");
// Name isn't changing?
if (getName() == NameRef)

View File

@ -0,0 +1,6 @@
; RUN: not llvm-as %s 2>&1 | FileCheck %s
; CHECK: expected function name
define void @"zed\00bar"() {
ret void
}