[llvm] r195155 - Make it explicit that nulls are not allowed in names.
    Rafael Espindola 
    rafael.espindola at gmail.com
       
    Tue Nov 19 13:12:39 PST 2013
    
    
  
Author: rafael
Date: Tue Nov 19 15:12:39 2013
New Revision: 195155
URL: http://llvm.org/viewvc/llvm-project?rev=195155&view=rev
Log:
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.
Added:
    llvm/trunk/test/Assembler/invalid-name.ll
Modified:
    llvm/trunk/lib/AsmParser/LLLexer.cpp
    llvm/trunk/lib/IR/Value.cpp
Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=195155&r1=195154&r2=195155&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLLexer.cpp Tue Nov 19 15:12:39 2013
@@ -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;
       }
     }
Modified: llvm/trunk/lib/IR/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=195155&r1=195154&r2=195155&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Value.cpp (original)
+++ llvm/trunk/lib/IR/Value.cpp Tue Nov 19 15:12:39 2013
@@ -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)
Added: llvm/trunk/test/Assembler/invalid-name.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-name.ll?rev=195155&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-name.ll (added)
+++ llvm/trunk/test/Assembler/invalid-name.ll Tue Nov 19 15:12:39 2013
@@ -0,0 +1,6 @@
+; RUN: not llvm-as %s 2>&1 | FileCheck %s
+
+; CHECK: expected function name
+define void @"zed\00bar"() {
+  ret void
+}
    
    
More information about the llvm-commits
mailing list