Allocated memory is typically not 'const' if it needs to be freed.
This patch removes around 50 wrong const attributes, modifies the
corresponding functions and finally gets rid of some const_casts.
These have especially been strange for __kmp_str_fname_free() that
added a 'const' to call __kmp_str_free() which removed it again.
Two minor cleanups that I performed in this process:
* __kmp_tool_libraries now lives in kmp_settings.cpp as it is
used nowhere else.
* __kmp_msg_empty was removed as it was never used and Clang
now complained that it was assigned a string literal that
is 'const char *'.
Differential Revision: https://reviews.llvm.org/D39755
llvm-svn: 317797
extern void __kmp_affinity_bind_thread(int which);
extern kmp_affin_mask_t *__kmp_affin_fullMask;
-extern char const *__kmp_cpuinfo_file;
+extern char *__kmp_cpuinfo_file;
#endif /* KMP_AFFINITY_SUPPORTED */
extern int __kmp_hws_requested;
extern int __kmp_hws_abs_flag; // absolute or per-item number requested
-#if OMP_50_ENABLED && LIBOMP_OMPT_SUPPORT
-extern char const *__kmp_tool_libraries;
-#endif // OMP_50_ENABLED && LIBOMP_OMPT_SUPPORT
-
/* ------------------------------------------------------------------------ */
#define KMP_PAD(type, sz) \
KMP_MB();
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_deo: T#%%d before wait: "
"ordered_iter:%%%s lower:%%%s\n",
KMP_MB(); /* is this necessary? */
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_deo: T#%%d after wait: "
"ordered_iter:%%%s lower:%%%s\n",
#endif
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_init: T#%%d called: schedule:%%d "
"chunk:%%%s lb:%%%s ub:%%%s st:%%%s\n",
#endif
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmp_dispatch_init: T#%%d new: schedule:%%d chunk:%%%s\n",
schedule = __kmp_auto;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_init: kmp_sch_auto: T#%%d new: "
"schedule:%%d chunk:%%%s\n",
#endif
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_init: T#%%d new: schedule:%%d"
" chunk:%%%s\n",
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmp_dispatch_init: T#%%d returning: schedule:%%d ordered:%%%s "
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_finish: T#%%d before wait: "
"ordered_iteration:%%%s lower:%%%s\n",
KMP_MB(); /* is this necessary? */
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_finish: T#%%d after wait: "
"ordered_iteration:%%%s lower:%%%s\n",
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmp_dispatch_finish_chunk: T#%%d before wait: "
//!!!!! TODO check if the inc should be unsigned, or signed???
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmp_dispatch_finish_chunk: T#%%d after wait: "
KMP_DEBUG_ASSERT(p_lb && p_ub && p_st); // AC: these cannot be NULL
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d called p_lb:%%%s "
"p_ub:%%%s p_st:%%%s p_last: %%p\n",
pr->u.p.ordered_upper = limit;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d "
"ordered_lower:%%%s ordered_upper:%%%s\n",
} // if
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmp_dispatch_next: T#%%d serialized case: p_lb:%%%s "
pr->u.p.ordered_upper = limit;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d "
"ordered_lower:%%%s ordered_upper:%%%s\n",
if (pr->ordered) {
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d "
"ordered_lower:%%%s ordered_upper:%%%s\n",
pr->u.p.ordered_upper = limit;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d "
"ordered_lower:%%%s ordered_upper:%%%s\n",
pr->u.p.ordered_upper = limit;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d "
"ordered_lower:%%%s ordered_upper:%%%s\n",
pr->u.p.ordered_upper = limit;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d "
"ordered_lower:%%%s ordered_upper:%%%s\n",
pr->u.p.ordered_upper = limit;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d "
"ordered_lower:%%%s ordered_upper:%%%s\n",
pr->u.p.ordered_upper = limit;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d "
"ordered_lower:%%%s ordered_upper:%%%s\n",
pr->u.p.ordered_upper = limit;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_dispatch_next: T#%%d "
"ordered_lower:%%%s ordered_upper:%%%s\n",
num_done = test_then_inc<ST>((volatile ST *)&sh->u.s.num_done);
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmp_dispatch_next: T#%%d increment num_done:%%%s\n",
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmp_dispatch_next: T#%%d normal case: "
KE_TRACE(10, ("__kmpc_dist_get_bounds called (%d)\n", gtid));
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmpc_dist_get_bounds: T#%%d liter=%%d "
"iter=(%%%s, %%%s, %%%s) signed?<%s>\n",
*/
struct __kmp_env_var {
- char const *name;
- char const *value;
+ char *name;
+ char *value;
};
typedef struct __kmp_env_var kmp_env_var_t;
struct __kmp_env_blk {
- char const *bulk;
- kmp_env_var_t const *vars;
+ char *bulk;
+ kmp_env_var_t *vars;
int count;
};
typedef struct __kmp_env_blk kmp_env_blk_t;
}
// NOTE: Function returns allocated memory, caller must free it!
-static char const *__kmp_pragma(int ct, ident_t const *ident) {
+static char *__kmp_pragma(int ct, ident_t const *ident) {
char const *cons = NULL; // Construct name.
char *file = NULL; // File name.
char *func = NULL; // Function (routine) name.
enum cons_type ct, // Construct type.
ident_t const *ident // Construct ident.
) {
- char const *construct = __kmp_pragma(ct, ident);
+ char *construct = __kmp_pragma(ct, ident);
__kmp_fatal(__kmp_msg_format(id, construct), __kmp_msg_null);
- KMP_INTERNAL_FREE(CCAST(char *, construct));
+ KMP_INTERNAL_FREE(construct);
}
void __kmp_error_construct2(kmp_i18n_id_t id, // Message identifier.
ident_t const *ident, // First construct ident.
struct cons_data const *cons // Second construct.
) {
- char const *construct1 = __kmp_pragma(ct, ident);
- char const *construct2 = __kmp_pragma(cons->type, cons->ident);
+ char *construct1 = __kmp_pragma(ct, ident);
+ char *construct2 = __kmp_pragma(cons->type, cons->ident);
__kmp_fatal(__kmp_msg_format(id, construct1, construct2), __kmp_msg_null);
- KMP_INTERNAL_FREE(CCAST(char *, construct1));
- KMP_INTERNAL_FREE(CCAST(char *, construct2));
+ KMP_INTERNAL_FREE(construct1);
+ KMP_INTERNAL_FREE(construct2);
}
struct cons_header *__kmp_allocate_cons_stack(int gtid) {
kmp_affin_mask_t *__kmp_affinity_masks = NULL;
unsigned __kmp_affinity_num_masks = 0;
-char const *__kmp_cpuinfo_file = NULL;
+char *__kmp_cpuinfo_file = NULL;
#endif /* KMP_AFFINITY_SUPPORTED */
kmp_uint64 __kmp_taskloop_min_tasks = 0;
#endif
-#if OMP_50_ENABLED && OMPT_SUPPORT
-char const *__kmp_tool_libraries = NULL;
-#endif
-
/* This check ensures that the compiler is passing the correct data type for the
flags formal parameter of the function kmpc_omp_task_alloc(). If the type is
not a 4-byte type, then give an error message about a non-positive length
#define get_section(id) ((id) >> 16)
#define get_number(id) ((id)&0xFFFF)
-kmp_msg_t __kmp_msg_empty = {kmp_mt_dummy, 0, "", 0};
kmp_msg_t __kmp_msg_null = {kmp_mt_dummy, 0, NULL, 0};
static char const *no_message_available = "(No message available)";
if (message.type == kmp_mt_dummy && message.str == NULL) {
break;
}
- if (message.type == kmp_mt_dummy && message.str == __kmp_msg_empty.str) {
- continue;
- }
switch (message.type) {
case kmp_mt_hint: {
format = kmp_i18n_fmt_Hint;
struct kmp_msg {
kmp_msg_type_t type;
int num;
- char const *str;
+ char *str;
int len;
}; // struct kmp_message
typedef struct kmp_msg kmp_msg_t;
-// Two special messages.
-extern kmp_msg_t __kmp_msg_empty; // Can be used in place where message is
-// required syntactically.
-extern kmp_msg_t
- __kmp_msg_null; // Denotes the end of variadic list of arguments.
+// Special message to denote the end of variadic list of arguments.
+extern kmp_msg_t __kmp_msg_null;
// Helper functions. Creates messages either from message catalog or from
// system. Note: these functions allocate memory. You should pass created
// Transform compiler-generated region location into the format
// that the tools more or less standardized on:
// "<func>$omp$parallel@[file:]<line>[:<col>]"
- const char *buff = NULL;
+ char *buff = NULL;
kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1);
buff = __kmp_str_format("%s$omp$parallel:%d@%s:%d:%d", str_loc.func,
team_size, str_loc.file, str_loc.line,
&__kmp_barrier_domain_count); // revert the count
return; // loc->reserved_2 is still 0
}
- const char *buff = NULL;
+ char *buff = NULL;
buff = __kmp_str_format("%s$omp$barrier@%s:%d", str_loc.func,
str_loc.file, str_loc.col);
__itt_suppress_push(__itt_suppress_memory_errors);
unsigned int frm = (loc->reserved_2 & 0x0000FFFF) - 1;
if ((frm < KMP_MAX_FRAME_DOMAINS) &&
(__kmp_itt_region_team_size[frm] != team_size)) {
- const char *buff = NULL;
+ char *buff = NULL;
kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1);
buff = __kmp_str_format("%s$omp$parallel:%d@%s:%d:%d", str_loc.func,
team_size, str_loc.file, str_loc.line,
// Transform compiler-generated region location into the format
// that the tools more or less standardized on:
// "<func>$omp$parallel:team_size@[file:]<line>[:<col>]"
- const char *buff = NULL;
+ char *buff = NULL;
kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1);
buff = __kmp_str_format("%s$omp$parallel:%d@%s:%d:%d", str_loc.func,
team_size, str_loc.file, str_loc.line,
unsigned int frm = (loc->reserved_2 & 0x0000FFFF) - 1;
if ((frm < KMP_MAX_FRAME_DOMAINS) &&
(__kmp_itt_region_team_size[frm] != team_size)) {
- const char *buff = NULL;
+ char *buff = NULL;
kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1);
buff = __kmp_str_format("%s$omp$parallel:%d@%s:%d:%d", str_loc.func,
team_size, str_loc.file, str_loc.line,
// "<func>$omp$frame@[file:]<line>[:<col>]"
kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1);
if (imbalance) {
- const char *buff_imb = NULL;
+ char *buff_imb = NULL;
buff_imb = __kmp_str_format("%s$omp$barrier-imbalance:%d@%s:%d",
str_loc.func, team_size, str_loc.file,
str_loc.col);
end);
__kmp_str_free(&buff_imb);
} else {
- const char *buff = NULL;
+ char *buff = NULL;
buff = __kmp_str_format("%s$omp$barrier@%s:%d", str_loc.func,
str_loc.file, str_loc.col);
__itt_suppress_push(__itt_suppress_memory_errors);
KE_TRACE(10, ("__kmpc_for_static_init called (%d)\n", global_tid));
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmpc_for_static_init: T#%%d sched=%%d liter=%%d iter=(%%%s,"
// ON A ZERO-TRIP LOOP (lower=1, upper=0,stride=1) - JPH June 23, 2009.
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmpc_for_static_init:(ZERO TRIP) liter=%%d "
"lower=%%%s upper=%%%s stride = %%%s "
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmpc_for_static_init: (serial) liter=%%d "
"lower=%%%s upper=%%%s stride = %%%s\n",
(incr > 0) ? (*pupper - *plower + 1) : (-(*plower - *pupper + 1));
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmpc_for_static_init: (serial) liter=%%d "
"lower=%%%s upper=%%%s stride = %%%s\n",
#endif
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmpc_for_static_init: liter=%%d lower=%%%s "
"upper=%%%s stride = %%%s signed?<%s>\n",
KE_TRACE(10, ("__kmpc_dist_for_static_init called (%d)\n", gtid));
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmpc_dist_for_static_init: T#%%d schedLoop=%%d liter=%%d "
end:;
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format(
"__kmpc_dist_for_static_init: last=%%d lo=%%%s up=%%%s upDist=%%%s "
KE_TRACE(10, ("__kmp_team_static_init called (%d)\n", gtid));
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff = __kmp_str_format("__kmp_team_static_init enter: T#%%d liter=%%d "
"iter=(%%%s, %%%s, %%%s) chunk %%%s; signed?<%s>\n",
}
#ifdef KMP_DEBUG
{
- const char *buff;
+ char *buff;
// create format specifiers before the debug output
buff =
__kmp_str_format("__kmp_team_static_init exit: T#%%d team%%u liter=%%d "
} // __kmp_stg_parse_size
static void __kmp_stg_parse_str(char const *name, char const *value,
- char const **out) {
+ char **out) {
__kmp_str_free(out);
*out = __kmp_str_format("%s", value);
} // __kmp_stg_parse_str
#undef set_respect
#undef set_granularity
- __kmp_str_free(CCAST(const char **, &buffer));
+ __kmp_str_free(&buffer);
if (proclist) {
if (!type) {
#if OMP_50_ENABLED && OMPT_SUPPORT
+static char *__kmp_tool_libraries = NULL;
+
static void __kmp_stg_parse_omp_tool_libraries(char const *name,
char const *value, void *data) {
__kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
} // kmp_str_fname_init
void __kmp_str_fname_free(kmp_str_fname_t *fname) {
- __kmp_str_free(CCAST(char const **, &fname->path));
- __kmp_str_free(CCAST(char const **, &fname->dir));
- __kmp_str_free(CCAST(char const **, &fname->base));
+ __kmp_str_free(&fname->path);
+ __kmp_str_free(&fname->dir);
+ __kmp_str_free(&fname->base);
} // kmp_str_fname_free
int __kmp_str_fname_match(kmp_str_fname_t const *fname, char const *pattern) {
void __kmp_str_loc_free(kmp_str_loc_t *loc) {
__kmp_str_fname_free(&loc->fname);
- __kmp_str_free(CCAST(const char **, &(loc->_bulk)));
+ __kmp_str_free(&(loc->_bulk));
loc->file = NULL;
loc->func = NULL;
} // kmp_str_loc_free
return buffer;
} // func __kmp_str_format
-void __kmp_str_free(char const **str) {
+void __kmp_str_free(char **str) {
KMP_DEBUG_ASSERT(str != NULL);
- KMP_INTERNAL_FREE(CCAST(char *, *str));
+ KMP_INTERNAL_FREE(*str);
*str = NULL;
} // func __kmp_str_free
int __kmp_str_eqf(char const *lhs, char const *rhs);
char *__kmp_str_format(char const *format, ...);
-void __kmp_str_free(char const **str);
+void __kmp_str_free(char **str);
int __kmp_str_match(char const *target, int len, char const *data);
int __kmp_str_match_false(char const *data);
int __kmp_str_match_true(char const *data);
// Try tool-libraries-var ICV
const char *tool_libs = getenv("OMP_TOOL_LIBRARIES");
if (tool_libs) {
- const char *libs = __kmp_str_format("%s", tool_libs);
+ char *libs = __kmp_str_format("%s", tool_libs);
char *buf;
- char *fname = __kmp_str_token(CCAST(char *, libs), sep, &buf);
+ char *fname = __kmp_str_token(libs, sep, &buf);
while (fname) {
#if KMP_OS_UNIX
void *h = dlopen(fname, RTLD_LAZY);