Testcases are not compiled with -Wcast-qual.
Introduce CONST_CAST macro to work around in the few spots
where a cast that drops type qualifiers is needed.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14652
CXXFLAGS += -Wno-unused-private-field # drd/tests/tsan_unittest.cpp
endif
+# Compile testcases without -Wcast-qual
+CFLAGS += -Wno-cast-qual
+CXXFLAGS += -Wno-cast-qual
+
check-local: build-noinst_DSYMS
clean-local: clean-noinst_DSYMS
])
CFLAGS=$safe_CFLAGS
+# does this compiler support -Wcast-qual ?
+AC_MSG_CHECKING([if gcc accepts -Wcast-qual])
+
+safe_CFLAGS=$CFLAGS
+CFLAGS="-Wcast-qual"
+
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
+ return 0;
+]])], [
+cast_qual=yes
+AC_MSG_RESULT([yes])
+], [
+cast_qual=no
+AC_MSG_RESULT([no])
+])
+CFLAGS=$safe_CFLAGS
+
+AM_CONDITIONAL(HAS_CAST_QUAL_WARNING, test x$cast_qual = xyes)
+
+if test x$cast_qual = xyes; then
+ CFLAGS="$CFLAGS -Wcast-qual"
+ CXXFLAGS="$CXXFLAGS -Wcast-qual"
+fi
+
# does this compiler support -fno-stack-protector ?
AC_MSG_CHECKING([if gcc accepts -fno-stack-protector])
ht_elt.key = VG_(adler32) (ht_elt.key, elt, eltSzB);
ht_elt.eltSzB = eltSzB;
- ht_elt.elt = (void *)elt;
+ ht_elt.elt = CONST_CAST(void *,elt);
ht_ins = VG_(HT_gen_lookup) (ddpa->ht_elements, &ht_elt, cmp_pool_elt);
if (ht_ins)
if (!converted) str = str0; // If nothing converted, endptr points to
if (neg) n = -n; // the start of the string.
- if (endptr) *endptr = (HChar *)str; // Record first failing character.
+ if (endptr)
+ *endptr = CONST_CAST(HChar *,str); // Record first failing character.
return n;
}
if (!converted) str = str0; // If nothing converted, endptr points to
// the start of the string.
- if (endptr) *endptr = (HChar *)str; // Record first failing character.
+ if (endptr)
+ *endptr = CONST_CAST(HChar *,str); // Record first failing character.
return n;
}
if (!converted) str = str0; // If nothing converted, endptr points to
if (neg) n = -n; // the start of the string.
- if (endptr) *endptr = (HChar *)str; // Record first failing character.
+ if (endptr)
+ *endptr = CONST_CAST(HChar *,str); // Record first failing character.
return n;
}
if (!converted) str = str0; // If nothing converted, endptr points to
// the start of the string.
- if (endptr) *endptr = (HChar *)str; // Record first failing character.
+ if (endptr)
+ *endptr = CONST_CAST(HChar *,str); // Record first failing character.
return n;
}
n += frac;
if (neg) n = -n;
- if (endptr) *endptr = (HChar *)str; // Record first failing character.
+ if (endptr)
+ *endptr = CONST_CAST(HChar *,str); // Record first failing character.
return n;
}
a = accpt;
while (*a)
if (*a++ == *s)
- return (HChar *)s;
+ return CONST_CAST(HChar *,s);
s++;
}
return NULL;
if (haystack[0] == 0)
return NULL;
if (VG_(strncmp)(haystack, needle, n) == 0)
- return (HChar*)haystack;
+ return CONST_CAST(HChar *,haystack);
haystack++;
}
}
if (haystack[0] == 0)
return NULL;
if (VG_(strncasecmp)(haystack, needle, n) == 0)
- return (HChar*)haystack;
+ return CONST_CAST(HChar *,haystack);
haystack++;
}
}
HChar* VG_(strchr) ( const HChar* s, HChar c )
{
while (True) {
- if (*s == c) return (HChar *)s;
+ if (*s == c) return CONST_CAST(HChar *,s);
if (*s == 0) return NULL;
s++;
}
{
Int n = VG_(strlen)(s);
while (--n > 0) {
- if (s[n] == c) return (HChar *)s + n;
+ if (s[n] == c) return CONST_CAST(HChar *,s) + n;
}
return NULL;
}
if (pid == 0) {
/* child */
const HChar* argv[4] = { "/bin/sh", "-c", cmd, 0 };
- VG_(execv)(argv[0], (HChar **)argv);
+ VG_(execv)(argv[0], CONST_CAST(HChar **,argv));
/* If we're still alive here, execv failed. */
VG_(exit)(1);
vg_assert(topSpecs->next == NULL);
vg_assert(topSpecs->seginfo == NULL);
/* FIXED PARTS */
- spec->from_sopatt = (HChar *)sopatt;
- spec->from_fnpatt = (HChar *)fnpatt;
+ spec->from_sopatt = CONST_CAST(HChar *,sopatt);
+ spec->from_fnpatt = CONST_CAST(HChar *,fnpatt);
spec->to_addr = to_addr;
spec->isWrap = False;
spec->mandatory = mandatory;
const HChar* last = NULL; \
while (True) { \
if (*p == ch) last = p; \
- if (*p == 0) return (HChar *)last; \
+ if (*p == 0) return CONST_CAST(HChar *,last); \
p++; \
} \
}
HChar ch = (HChar)c ; \
const HChar* p = s; \
while (True) { \
- if (*p == ch) return (HChar *)p; \
+ if (*p == ch) return CONST_CAST(HChar *,p); \
if (*p == 0) return NULL; \
p++; \
} \
{ \
SizeT i; \
UChar c0 = (UChar)c; \
- const UChar* p = (const UChar*)s; \
+ const UChar* p = s; \
for (i = 0; i < n; i++) \
- if (p[i] == c0) return (void*)(&p[i]); \
+ if (p[i] == c0) return CONST_CAST(void *,&p[i]); \
return NULL; \
}
UChar c = (UChar)c_in; \
const UChar* char_ptr = s; \
while (1) { \
- if (*char_ptr == c) return (void *)char_ptr; \
+ if (*char_ptr == c) return CONST_CAST(void *,char_ptr); \
char_ptr++; \
} \
}
while (n[nlen]) nlen++; \
\
/* if n is the empty string, match immediately. */ \
- if (nlen == 0) return (HChar *)h; \
+ if (nlen == 0) return CONST_CAST(HChar *,h); \
\
/* assert(nlen >= 1); */ \
HChar n0 = n[0]; \
} \
/* assert(i >= 0 && i <= nlen); */ \
if (i == nlen) \
- return (HChar *)h; \
+ return CONST_CAST(HChar *,h); \
\
h++; \
} \
break; \
for (i = 0; i < nacc; i++) { \
if (sc == accept[i]) \
- return (HChar *)s; \
+ return CONST_CAST(HChar *,s); \
} \
s++; \
} \
#define PRINTF_CHECK(x, y)
#endif
+// Macro to "cast" away constness (from type const T to type T) without
+// GCC complaining about it. This macro should be used RARELY.
+// x is expected to have type const T
+#define CONST_CAST(T,x) \
+ ({ \
+ union { \
+ const T in; \
+ T out; \
+ } var = { .in = x }; var.out; \
+ })
#endif /* __PUB_TOOL_BASICS_H */
const HChar* last = NULL; \
while (True) { \
if (*p == ch) last = p; \
- if (*p == 0) return (HChar *)last; \
+ if (*p == 0) return CONST_CAST(HChar *,last); \
p++; \
} \
}
HChar ch = (HChar)c ; \
const HChar* p = s; \
while (True) { \
- if (*p == ch) return (HChar *)p; \
+ if (*p == ch) return CONST_CAST(HChar *,p); \
if (*p == 0) return NULL; \
p++; \
} \
{ \
SizeT i; \
UChar c0 = (UChar)c; \
- UChar* p = (UChar*)s; \
+ const UChar* p = s; \
for (i = 0; i < n; i++) \
- if (p[i] == c0) return (void*)(&p[i]); \
+ if (p[i] == c0) return CONST_CAST(void *,&p[i]); \
return NULL; \
}
{ \
SizeT i; \
UChar c0 = (UChar)c; \
- UChar* p = (UChar*)s; \
+ const UChar* p = s; \
for (i = 0; i < n; i++) \
- if (p[n-1-i] == c0) return (void*)(&p[n-1-i]); \
+ if (p[n-1-i] == c0) return CONST_CAST(void *,&p[n-1-i]); \
return NULL; \
}
char* VG_REPLACE_FUNCTION_EZU(20250,soname,fnname) \
(const char* s, int c_in) \
{ \
- UChar c = (UChar) c_in; \
- UChar* char_ptr = (UChar *)s; \
+ HChar c = (HChar) c_in; \
+ const HChar* char_ptr = s; \
while (1) { \
- if (*char_ptr == 0) return (HChar *)char_ptr; \
- if (*char_ptr == c) return (HChar *)char_ptr; \
+ if (*char_ptr == 0) return CONST_CAST(HChar *,char_ptr); \
+ if (*char_ptr == c) return CONST_CAST(HChar *,char_ptr); \
char_ptr++; \
} \
}
UChar c = (UChar) c_in; \
const UChar* char_ptr = s; \
while (1) { \
- if (*char_ptr == c) return (void *)char_ptr; \
+ if (*char_ptr == c) return CONST_CAST(void *,char_ptr); \
char_ptr++; \
} \
}
while (n[nlen]) nlen++; \
\
/* if n is the empty string, match immediately. */ \
- if (nlen == 0) return (HChar *)h; \
+ if (nlen == 0) return CONST_CAST(HChar *,h); \
\
/* assert(nlen >= 1); */ \
HChar n0 = n[0]; \
} \
/* assert(i >= 0 && i <= nlen); */ \
if (i == nlen) \
- return (HChar *)h; \
+ return CONST_CAST(HChar *,h); \
\
h++; \
} \
break; \
for (i = 0; i < nacc; i++) { \
if (sc == accept[i]) \
- return (HChar *)s; \
+ return CONST_CAST(HChar *,s); \
} \
s++; \
} \
while (n[nlen]) nlen++; \
\
/* if n is the empty string, match immediately. */ \
- if (nlen == 0) return (HChar *)h; \
+ if (nlen == 0) return CONST_CAST(HChar *,h); \
\
/* assert(nlen >= 1); */ \
UChar n0 = tolower(n[0]); \
} \
/* assert(i >= 0 && i <= nlen); */ \
if (i == nlen) \
- return (HChar *)h; \
+ return CONST_CAST(HChar *,h); \
\
h++; \
} \
Int* VG_REPLACE_FUNCTION_EZU(20400,soname,fnname) ( const Int* s, Int c ); \
Int* VG_REPLACE_FUNCTION_EZU(20400,soname,fnname) ( const Int* s, Int c ) \
{ \
- Int* p = (Int*)s; \
+ const Int* p = s; \
while (True) { \
- if (*p == c) return p; \
+ if (*p == c) return CONST_CAST(Int *,p); \
if (*p == 0) return NULL; \
p++; \
} \
Int* VG_REPLACE_FUNCTION_EZU(20410,soname,fnname)( const Int* s, Int c ); \
Int* VG_REPLACE_FUNCTION_EZU(20410,soname,fnname)( const Int* s, Int c ) \
{ \
- Int* p = (Int*) s; \
- Int* last = NULL; \
+ const Int* p = s; \
+ const Int* last = NULL; \
while (True) { \
if (*p == c) last = p; \
- if (*p == 0) return last; \
+ if (*p == 0) return CONST_CAST(Int *,last); \
p++; \
} \
}