Make it explicit that nulls are not allowed in names.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 19 Nov 2013 21:12:39 +0000 (21:12 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 19 Nov 2013 21:12:39 +0000 (21:12 +0000)
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

lib/AsmParser/LLLexer.cpp
lib/IR/Value.cpp
test/Assembler/invalid-name.ll [new file with mode: 0644]

index 1e6085b443f221d964f178865034db178171bd81..3c384f5fcca07727ea707c9436d1234cc60c7a4c 100644 (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;
       }
     }
index 62a3b31c18b21295931f79c180244b22d5f60423..2c90383edd8c2ecff8e015ac161529f94f216758 100644 (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)
diff --git a/test/Assembler/invalid-name.ll b/test/Assembler/invalid-name.ll
new file mode 100644 (file)
index 0000000..d9d7a11
--- /dev/null
@@ -0,0 +1,6 @@
+; RUN: not llvm-as %s 2>&1 | FileCheck %s
+
+; CHECK: expected function name
+define void @"zed\00bar"() {
+  ret void
+}