diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index 1e6085b443f..3c384f5fcca 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -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; } } diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp index 62a3b31c18b..2c90383edd8 100644 --- a/lib/IR/Value.cpp +++ b/lib/IR/Value.cpp @@ -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) diff --git a/test/Assembler/invalid-name.ll b/test/Assembler/invalid-name.ll new file mode 100644 index 00000000000..d9d7a110880 --- /dev/null +++ b/test/Assembler/invalid-name.ll @@ -0,0 +1,6 @@ +; RUN: not llvm-as %s 2>&1 | FileCheck %s + +; CHECK: expected function name +define void @"zed\00bar"() { + ret void +}