Skip to content

Commit

Permalink
When a function takes a variable number of pointer arguments, with a …
Browse files Browse the repository at this point in the history
…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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23888 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Jeff Cohen committed Oct 23, 2005
1 parent 8b7f14e commit 66c5fd6
Show file tree
Hide file tree
Showing 27 changed files with 290 additions and 262 deletions.
2 changes: 1 addition & 1 deletion Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ else
endif
endif

CXX.Flags += $(CXXFLAGS)
CXX.Flags += $(CXXFLAGS) -Wformat
C.Flags += $(CFLAGS)
CPP.Flags += $(CPPFLAGS)
LD.Flags += $(LDFLAGS)
Expand Down
3 changes: 2 additions & 1 deletion examples/Fibonacci/fibonacci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ using namespace llvm;
static Function *CreateFibFunction(Module *M) {
// Create the fib function and insert it into module M. This function is said
// to return an int and take an int parameter.
Function *FibF = M->getOrInsertFunction("fib", Type::IntTy, Type::IntTy, 0);
Function *FibF = M->getOrInsertFunction("fib", Type::IntTy, Type::IntTy,
(Type *)0);

// Add a basic block to the function.
BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
Expand Down
5 changes: 3 additions & 2 deletions examples/HowToUseJIT/HowToUseJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ int main() {
// Create the add1 function entry and insert this entry into module M. The
// function will have a return type of "int" and take an argument of "int".
// The '0' terminates the list of argument types.
Function *Add1F = M->getOrInsertFunction("add1", Type::IntTy, Type::IntTy, 0);
Function *Add1F = M->getOrInsertFunction("add1", Type::IntTy, Type::IntTy,
(Type *)0);

// Add a basic block to the function. As before, it automatically inserts
// because of the last argument.
Expand All @@ -76,7 +77,7 @@ int main() {

// Now we going to create function `foo', which returns an int and takes no
// arguments.
Function *FooF = M->getOrInsertFunction("foo", Type::IntTy, 0);
Function *FooF = M->getOrInsertFunction("foo", Type::IntTy, (Type *)0);

// Add a basic block to the FooF function.
BB = new BasicBlock("EntryBlock", FooF);
Expand Down
6 changes: 4 additions & 2 deletions examples/ParallelJIT/ParallelJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static Function* createAdd1(Module* M)
// Create the add1 function entry and insert this entry into module M. The
// function will have a return type of "int" and take an argument of "int".
// The '0' terminates the list of argument types.
Function *Add1F = M->getOrInsertFunction("add1", Type::IntTy, Type::IntTy, 0);
Function *Add1F = M->getOrInsertFunction("add1", Type::IntTy, Type::IntTy,
(Type *)0);

// Add a basic block to the function. As before, it automatically inserts
// because of the last argument.
Expand Down Expand Up @@ -61,7 +62,8 @@ static Function *CreateFibFunction(Module *M)
{
// Create the fib function and insert it into module M. This function is said
// to return an int and take an int parameter.
Function *FibF = M->getOrInsertFunction("fib", Type::IntTy, Type::IntTy, 0);
Function *FibF = M->getOrInsertFunction("fib", Type::IntTy, Type::IntTy,
(Type *)0);

// Add a basic block to the function.
BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Support/DataTypes.h"

namespace llvm {

Expand Down Expand Up @@ -111,7 +112,8 @@ class Module {
/// table. If it does not exist, add a prototype for the function and return
/// it. This version of the method takes a null terminated list of function
/// arguments, which makes it easier for clients to use.
Function *getOrInsertFunction(const std::string &Name, const Type *RetTy,...);
Function *getOrInsertFunction(const std::string &Name, const Type *RetTy,...)
END_WITH_NULL;

/// getFunction - Look up the specified function in the module symbol table.
/// If it does not exist, return null.
Expand Down
3 changes: 2 additions & 1 deletion include/llvm/Support/CommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define LLVM_SUPPORT_COMMANDLINE_H

#include "llvm/Support/type_traits.h"
#include "llvm/Support/DataTypes.h"
#include <string>
#include <vector>
#include <utility>
Expand Down Expand Up @@ -335,7 +336,7 @@ class ValuesClass {

template<class DataType>
ValuesClass<DataType> values(const char *Arg, DataType Val, const char *Desc,
...) {
...) END_WITH_NULL {
va_list ValueArgs;
va_start(ValueArgs, Desc);
ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
Expand Down
6 changes: 6 additions & 0 deletions include/llvm/Support/DataTypes.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,10 @@ typedef signed int ssize_t;
# define UINT64_MAX 0xffffffffffffffffULL
#endif

#if __GNUC__ > 3
#define END_WITH_NULL __attribute__((sentinel))
#else
#define END_WITH_NULL
#endif

#endif /* SUPPORT_DATATYPES_H */
Loading

0 comments on commit 66c5fd6

Please sign in to comment.