From 2db15e2b4271d09ebc33516566ba852b8567810b Mon Sep 17 00:00:00 2001
From: Reid Spencer <rspencer@reidspencer.com>
Date: Mon, 16 Apr 2007 06:54:34 +0000
Subject: [PATCH] For PR1328: Don't assert everytime an intrinsic name isn't
 recognized. Instead, make the assert optional when callin getIntrinsicID().
 This allows the assembler to handle invalid intrinsic names gracefully.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36120 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/llvm/Function.h             | 2 +-
 lib/VMCore/Function.cpp             | 7 ++++---
 utils/TableGen/IntrinsicEmitter.cpp | 2 --
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/llvm/Function.h b/include/llvm/Function.h
index 751d1a3c4bd..90a8275bec1 100644
--- a/include/llvm/Function.h
+++ b/include/llvm/Function.h
@@ -103,7 +103,7 @@ public:
   /// The particular intrinsic functions which correspond to this value are
   /// defined in llvm/Intrinsics.h.
   ///
-  unsigned getIntrinsicID() const;
+  unsigned getIntrinsicID(bool noAssert = false) const;
   bool isIntrinsic() const { return getIntrinsicID() != 0; }
 
   /// getCallingConv()/setCallingConv(uint) - These method get and set the
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index e2a015fabbb..5176a05d760 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -224,20 +224,21 @@ void Function::dropAllReferences() {
 /// particular intrinsic functions which correspond to this value are defined in
 /// llvm/Intrinsics.h.
 ///
-unsigned Function::getIntrinsicID() const {
+unsigned Function::getIntrinsicID(bool noAssert) const {
   const ValueName *ValName = this->getValueName();
   unsigned Len = ValName->getKeyLength();
   const char *Name = ValName->getKeyData();
   
-  if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
+  if (Len <= 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
       || Name[2] != 'v' || Name[3] != 'm')
     return 0;  // All intrinsics start with 'llvm.'
 
-  assert(Len != 5 && "'llvm.' is an invalid intrinsic name!");
+  assert((Len != 5 || noAssert) && "'llvm.' is an invalid intrinsic name!");
 
 #define GET_FUNCTION_RECOGNIZER
 #include "llvm/Intrinsics.gen"
 #undef GET_FUNCTION_RECOGNIZER
+  assert(noAssert && "Invalid LLVM intrinsic name");
   return 0;
 }
 
diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp
index f884c424a71..834e1429ba4 100644
--- a/utils/TableGen/IntrinsicEmitter.cpp
+++ b/utils/TableGen/IntrinsicEmitter.cpp
@@ -103,8 +103,6 @@ EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
          << Ints[I->second].EnumName << ";\n";
   }
   OS << "  }\n";
-  OS << "  // The 'llvm.' namespace is reserved!\n";
-  OS << "  assert(0 && \"Unknown LLVM intrinsic function!\");\n";
   OS << "#endif\n\n";
 }