Fix PR1146: parameter attributes are longer part of
the function type, instead they belong to functions
and function calls.  This is an updated and slightly
corrected version of Reid Spencer's original patch.
The only known problem is that auto-upgrading of
bitcode files doesn't seem to work properly (see
test/Bitcode/AutoUpgradeIntrinsics.ll).  Hopefully
a bitcode guru (who might that be? :) ) will fix it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44359 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp
index 6b3885e..21b0372 100644
--- a/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Module.h"
 #include "llvm/TypeSymbolTable.h"
 #include "llvm/ValueSymbolTable.h"
+#include "llvm/Instructions.h"
 #include <algorithm>
 using namespace llvm;
 
@@ -44,8 +45,10 @@
     EnumerateValue(I);
 
   // Enumerate the functions.
-  for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
+  for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
     EnumerateValue(I);
+    EnumerateParamAttrs(cast<Function>(I)->getParamAttrs());
+  }
 
   // Enumerate the aliases.
   for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
@@ -86,6 +89,10 @@
              OI != E; ++OI)
           EnumerateOperandType(*OI);
         EnumerateType(I->getType());
+        if (const CallInst *CI = dyn_cast<CallInst>(I))
+          EnumerateParamAttrs(CI->getParamAttrs());
+        else if (const InvokeInst *II = dyn_cast<InvokeInst>(I))
+          EnumerateParamAttrs(II->getParamAttrs());
       }
   }
   
@@ -220,10 +227,6 @@
   for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
        I != E; ++I)
     EnumerateType(*I);
-  
-  // If this is a function type, enumerate the param attrs.
-  if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty))
-    EnumerateParamAttrs(FTy->getParamAttrs());
 }
 
 // Enumerate the types for the specified value.  If the value is a constant,
@@ -296,6 +299,10 @@
   // Optimize the constant layout.
   OptimizeConstants(FirstFuncConstantID, Values.size());
   
+  // Add the function's parameter attributes so they are available for use in
+  // the function's instruction.
+  EnumerateParamAttrs(F.getParamAttrs());
+
   FirstInstID = Values.size();
   
   // Add all of the instructions.