When a function takes a variable number of pointer arguments, with a zero
pointer marking the end of the list, the zero *must* be cast to the pointer
type.  An un-cast zero is a 32-bit int, and at least on x86_64, gcc will
not extend the zero to 64 bits, thus allowing the upper 32 bits to be
random junk.

The new END_WITH_NULL macro may be used to annotate a such a function
so that GCC (version 4 or newer) will detect the use of un-casted zero
at compile time.

llvm-svn: 23888
diff --git a/llvm/lib/Transforms/IPO/LowerSetJmp.cpp b/llvm/lib/Transforms/IPO/LowerSetJmp.cpp
index c040025..9dd9501 100644
--- a/llvm/lib/Transforms/IPO/LowerSetJmp.cpp
+++ b/llvm/lib/Transforms/IPO/LowerSetJmp.cpp
@@ -204,32 +204,33 @@
 
   // void __llvm_sjljeh_init_setjmpmap(void**)
   InitSJMap = M.getOrInsertFunction("__llvm_sjljeh_init_setjmpmap",
-                                    Type::VoidTy, SBPPTy, NULL);
+                                    Type::VoidTy, SBPPTy, (Type *)0);
   // void __llvm_sjljeh_destroy_setjmpmap(void**)
   DestroySJMap = M.getOrInsertFunction("__llvm_sjljeh_destroy_setjmpmap",
-                                       Type::VoidTy, SBPPTy, NULL);
+                                       Type::VoidTy, SBPPTy, (Type *)0);
 
   // void __llvm_sjljeh_add_setjmp_to_map(void**, void*, unsigned)
   AddSJToMap = M.getOrInsertFunction("__llvm_sjljeh_add_setjmp_to_map",
                                      Type::VoidTy, SBPPTy, SBPTy,
-                                     Type::UIntTy, NULL);
+                                     Type::UIntTy, (Type *)0);
 
   // void __llvm_sjljeh_throw_longjmp(int*, int)
   ThrowLongJmp = M.getOrInsertFunction("__llvm_sjljeh_throw_longjmp",
-                                       Type::VoidTy, SBPTy, Type::IntTy, NULL);
+                                       Type::VoidTy, SBPTy, Type::IntTy,
+                                       (Type *)0);
 
   // unsigned __llvm_sjljeh_try_catching_longjmp_exception(void **)
   TryCatchLJ =
     M.getOrInsertFunction("__llvm_sjljeh_try_catching_longjmp_exception",
-                          Type::UIntTy, SBPPTy, NULL);
+                          Type::UIntTy, SBPPTy, (Type *)0);
 
   // bool __llvm_sjljeh_is_longjmp_exception()
   IsLJException = M.getOrInsertFunction("__llvm_sjljeh_is_longjmp_exception",
-                                        Type::BoolTy, NULL);
+                                        Type::BoolTy, (Type *)0);
 
   // int __llvm_sjljeh_get_longjmp_value()
   GetLJValue = M.getOrInsertFunction("__llvm_sjljeh_get_longjmp_value",
-                                     Type::IntTy, NULL);
+                                     Type::IntTy, (Type *)0);
   return true;
 }
 
diff --git a/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp b/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
index 58aac20..63ab333 100644
--- a/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
@@ -311,7 +311,8 @@
     if (!memcpy_func) {
       const Type *SBP = PointerType::get(Type::SByteTy);
       memcpy_func = M->getOrInsertFunction("llvm.memcpy", Type::VoidTy,SBP, SBP,
-                                           Type::UIntTy, Type::UIntTy, 0);
+                                           Type::UIntTy, Type::UIntTy,
+                                           (Type *)0);
     }
     return memcpy_func;
   }
@@ -319,7 +320,7 @@
   Function* get_floorf() {
     if (!floorf_func)
       floorf_func = M->getOrInsertFunction("floorf", Type::FloatTy,
-                                           Type::FloatTy, 0);
+                                           Type::FloatTy, (Type *)0);
     return floorf_func;
   }
   
diff --git a/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp b/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
index 95822df..bf94943 100644
--- a/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
@@ -40,7 +40,7 @@
   const Type *PIntTy = PointerType::get(Type::IntTy);
   Function *trigMeth = M->getOrInsertFunction("trigger", Type::VoidTy,
                                               Type::IntTy, Type::IntTy,
-                                              PIntTy, PIntTy, 0);
+                                              PIntTy, PIntTy, (Type *)0);
   assert(trigMeth && "trigger method could not be inserted!");
 
   vector<Value *> trargs;
diff --git a/llvm/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp b/llvm/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
index 860b57f..020388f 100644
--- a/llvm/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
@@ -156,7 +156,8 @@
 }
 
 bool InstLoops::doInitialization (Module &M) {
-  inCountMth = M.getOrInsertFunction("llvm_first_trigger", Type::VoidTy, 0);
+  inCountMth = M.getOrInsertFunction("llvm_first_trigger", Type::VoidTy,
+                                     (Type *)0);
   return true;  // Module was modified.
 }
 
diff --git a/llvm/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp b/llvm/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
index d0d0f55..ce9e328 100644
--- a/llvm/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
@@ -189,7 +189,8 @@
     // IN THEIR INITIALIZE METHOD!!
     Function *initialize =
       F.getParent()->getOrInsertFunction("reoptimizerInitialize", Type::VoidTy,
-                                         PointerType::get(Type::IntTy), 0);
+                                         PointerType::get(Type::IntTy),
+                                         (Type *)0);
 
     std::vector<Value *> trargs;
     trargs.push_back(threshold);
diff --git a/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp
index 4093759..82e7ae7 100644
--- a/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp
@@ -26,7 +26,8 @@
   const PointerType *UIntPtr = PointerType::get(Type::UIntTy);
   Module &M = *MainFn->getParent();
   Function *InitFn = M.getOrInsertFunction(FnName, Type::IntTy, Type::IntTy,
-                                           ArgVTy, UIntPtr, Type::UIntTy, 0);
+                                           ArgVTy, UIntPtr, Type::UIntTy,
+                                           (Type *)0);
 
   // This could force argc and argv into programs that wouldn't otherwise have
   // them, but instead we just pass null values in.
diff --git a/llvm/lib/Transforms/Instrumentation/TraceBasicBlocks.cpp b/llvm/lib/Transforms/Instrumentation/TraceBasicBlocks.cpp
index 9018ee6..2d2a259 100644
--- a/llvm/lib/Transforms/Instrumentation/TraceBasicBlocks.cpp
+++ b/llvm/lib/Transforms/Instrumentation/TraceBasicBlocks.cpp
@@ -46,7 +46,7 @@
                    << "\", \"" << FnName << "\", " << BBNumber << ")\n");
   Module &M = *BB->getParent ()->getParent ();
   Function *InstrFn = M.getOrInsertFunction (FnName, Type::VoidTy,
-                                             Type::UIntTy, 0);
+                                             Type::UIntTy, (Type *)0);
   std::vector<Value*> Args (1);
   Args[0] = ConstantUInt::get (Type::UIntTy, BBNumber);
 
diff --git a/llvm/lib/Transforms/Instrumentation/TraceValues.cpp b/llvm/lib/Transforms/Instrumentation/TraceValues.cpp
index 9838ea1..eba596b 100644
--- a/llvm/lib/Transforms/Instrumentation/TraceValues.cpp
+++ b/llvm/lib/Transforms/Instrumentation/TraceValues.cpp
@@ -130,17 +130,18 @@
 
   // uint (sbyte*)
   HashPtrFunc = M.getOrInsertFunction("HashPointerToSeqNum", Type::UIntTy, SBP,
-                                      0);
+                                      (Type *)0);
 
   // void (sbyte*)
   ReleasePtrFunc = M.getOrInsertFunction("ReleasePointerSeqNum",
-                                         Type::VoidTy, SBP, 0);
+                                         Type::VoidTy, SBP, (Type *)0);
   RecordPtrFunc  = M.getOrInsertFunction("RecordPointer",
-                                         Type::VoidTy, SBP, 0);
+                                         Type::VoidTy, SBP, (Type *)0);
 
-  PushOnEntryFunc = M.getOrInsertFunction("PushPointerSet", Type::VoidTy, 0);
+  PushOnEntryFunc = M.getOrInsertFunction("PushPointerSet", Type::VoidTy,
+                                          (Type *)0);
   ReleaseOnReturnFunc = M.getOrInsertFunction("ReleasePointersPopSet",
-                                              Type::VoidTy, 0);
+                                              Type::VoidTy, (Type *)0);
 }
 
 
diff --git a/llvm/lib/Transforms/Scalar/LowerAllocations.cpp b/llvm/lib/Transforms/Scalar/LowerAllocations.cpp
index 1502fab..f1721b3 100644
--- a/llvm/lib/Transforms/Scalar/LowerAllocations.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerAllocations.cpp
@@ -83,7 +83,7 @@
     MallocFunc = M.getOrInsertFunction("malloc", FT);
   }
   if (FreeFunc == 0)
-    FreeFunc = M.getOrInsertFunction("free"  , Type::VoidTy, SBPTy, 0);
+    FreeFunc = M.getOrInsertFunction("free"  , Type::VoidTy, SBPTy, (Type *)0);
 
   return true;
 }
diff --git a/llvm/lib/Transforms/Scalar/LowerGC.cpp b/llvm/lib/Transforms/Scalar/LowerGC.cpp
index 345fafb..e346c23 100644
--- a/llvm/lib/Transforms/Scalar/LowerGC.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerGC.cpp
@@ -109,10 +109,11 @@
   // If the program is using read/write barriers, find the implementations of
   // them from the GC runtime library.
   if (GCReadInt)        // Make:  sbyte* %llvm_gc_read(sbyte**)
-    GCRead = M.getOrInsertFunction("llvm_gc_read", VoidPtr, VoidPtr, VoidPtrPtr, 0);
+    GCRead = M.getOrInsertFunction("llvm_gc_read", VoidPtr, VoidPtr, VoidPtrPtr,
+                                   (Type *)0);
   if (GCWriteInt)       // Make:  void %llvm_gc_write(sbyte*, sbyte**)
     GCWrite = M.getOrInsertFunction("llvm_gc_write", Type::VoidTy,
-                                    VoidPtr, VoidPtr, VoidPtrPtr, 0);
+                                    VoidPtr, VoidPtr, VoidPtrPtr, (Type *)0);
 
   // If the program has GC roots, get or create the global root list.
   if (GCRootInt) {
diff --git a/llvm/lib/Transforms/Scalar/LowerInvoke.cpp b/llvm/lib/Transforms/Scalar/LowerInvoke.cpp
index 4496b3d..7039a4b 100644
--- a/llvm/lib/Transforms/Scalar/LowerInvoke.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerInvoke.cpp
@@ -124,14 +124,14 @@
                                       Constant::getNullValue(PtrJBList),
                                       "llvm.sjljeh.jblist", &M);
     SetJmpFn = M.getOrInsertFunction("llvm.setjmp", Type::IntTy,
-                                     PointerType::get(JmpBufTy), NULL);
+                                     PointerType::get(JmpBufTy), (Type *)0);
     LongJmpFn = M.getOrInsertFunction("llvm.longjmp", Type::VoidTy,
                                       PointerType::get(JmpBufTy),
-                                      Type::IntTy, NULL);
+                                      Type::IntTy, (Type *)0);
   }
 
   // We need the 'write' and 'abort' functions for both models.
-  AbortFn = M.getOrInsertFunction("abort", Type::VoidTy, NULL);
+  AbortFn = M.getOrInsertFunction("abort", Type::VoidTy, (Type *)0);
 
   // Unfortunately, 'write' can end up being prototyped in several different
   // ways.  If the user defines a three (or more) operand function named 'write'
@@ -148,7 +148,7 @@
       WriteFn = 0;
   } else {
     WriteFn = M.getOrInsertFunction("write", Type::VoidTy, Type::IntTy,
-                                    VoidPtrTy, Type::IntTy, NULL);
+                                    VoidPtrTy, Type::IntTy, (Type *)0);
   }
   return true;
 }