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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195155 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2013-11-19 21:12:39 +00:00
parent a49e1f55da
commit edeaa6454e
3 changed files with 12 additions and 0 deletions

View File

@ -275,6 +275,10 @@ lltok::Kind LLLexer::LexAt() {
if (CurChar == '"') { if (CurChar == '"') {
StrVal.assign(TokStart+2, CurPtr-1); StrVal.assign(TokStart+2, CurPtr-1);
UnEscapeLexed(StrVal); 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; return lltok::GlobalVar;
} }
} }

View File

@ -182,6 +182,8 @@ void Value::setName(const Twine &NewName) {
SmallString<256> NameData; SmallString<256> NameData;
StringRef NameRef = NewName.toStringRef(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? // Name isn't changing?
if (getName() == NameRef) 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
}