This doesn't compile for my copy of gcc;

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


 ValuesClass<DataType> values(const char *Arg, DataType Val, const char *Desc,
-                             ...) {
+                             ...) END_WITH_NULL {

/llvm/llvm/include/llvm/Support/CommandLine.h:339: error: attributes are not allowed on a function-definition

gcc version 4.0.0 (Apple Computer, Inc. build 5026)

How about;

ValuesClass<DataType> END_WITH_NULL values(const char *Arg, DataType Val, const char *Desc,


Cheers,

-- Jim



On Oct 23, 2005, at 1:37 AM, Jeff Cohen wrote:



Changes in directory llvm/include/llvm/Support:

CommandLine.h updated: 1.49 -> 1.50
DataTypes.h.in updated: 1.20 -> 1.21
---
Log message:

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.


---
Diffs of the changes:  (+8 -1)

 CommandLine.h  |    3 ++-
 DataTypes.h.in |    6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)


Index: llvm/include/llvm/Support/CommandLine.h
diff -u llvm/include/llvm/Support/CommandLine.h:1.49 llvm/include/llvm/Support/CommandLine.h:1.50
--- llvm/include/llvm/Support/CommandLine.h:1.49 Thu Oct 13 19:33:05 2005
+++ llvm/include/llvm/Support/CommandLine.h Sat Oct 22 23:37:19 2005
@@ -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>
@@ -335,7 +336,7 @@

 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);


Index: llvm/include/llvm/Support/DataTypes.h.in
diff -u llvm/include/llvm/Support/DataTypes.h.in:1.20 llvm/include/llvm/Support/DataTypes.h.in:1.21
--- llvm/include/llvm/Support/DataTypes.h.in:1.20 Wed Jul 27 00:53:43 2005
+++ llvm/include/llvm/Support/DataTypes.h.in Sat Oct 22 23:37:19 2005
@@ -98,4 +98,10 @@
 # define UINT64_MAX 0xffffffffffffffffULL
 #endif

+#if __GNUC__ > 3
+#define END_WITH_NULL __attribute__((sentinel))
+#else
+#define END_WITH_NULL
+#endif
+
 #endif  /* SUPPORT_DATATYPES_H */



_______________________________________________
llvm-commits mailing list

_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to