Remove builtin attribute from calls whose targets we replace

If we are replacing a function with the nobuiltin attribute, it may be called
with the builtin attribute on call sites. Remove any such attributes since it's
illegal to have a builtin call to something other than a nobuiltin function.

This fixes the current buildbot breakage (where LLDB crashes on
"expression new foo(42)").



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@186990 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/IRForTarget.cpp b/source/Expression/IRForTarget.cpp
index dc27b65..cac3fdf 100644
--- a/source/Expression/IRForTarget.cpp
+++ b/source/Expression/IRForTarget.cpp
@@ -356,6 +356,20 @@
         
         if (value_ptr)
             *value_ptr = value;
+
+        // If we are replacing a function with the nobuiltin attribute, it may
+        // be called with the builtin attribute on call sites. Remove any such
+        // attributes since it's illegal to have a builtin call to something
+        // other than a nobuiltin function.
+        if (fun->hasFnAttribute(Attribute::NoBuiltin)) {
+            Attribute builtin = Attribute::get(fun->getContext(), Attribute::Builtin);
+
+            for (auto u = fun->use_begin(), e = fun->use_end(); u != e; ++u) {
+                if (auto call = dyn_cast<CallInst>(*u)) {
+                    call->removeAttribute(AttributeSet::FunctionIndex, builtin);
+                }
+            }
+        }
         
         fun->replaceAllUsesWith(value);
     }