This is an archive of the discontinued LLVM Phabricator instance.

Remove const from variables with dynamic memory
ClosedPublic

Authored by Hahnfeld on Nov 7 2017, 12:44 PM.

Details

Summary

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 *'.

Diff Detail

Repository
rL LLVM

Event Timeline

Hahnfeld created this revision.Nov 7 2017, 12:44 PM
Hahnfeld edited the summary of this revision. (Show Details)
AndreyChurbanov accepted this revision.Nov 9 2017, 5:21 AM

LGTM

runtime/src/kmp_i18n.h
111 ↗(On Diff #121958)

This comment now looks ugly, as only one special message remains. I think it'd be better to combine the two comments into single one, something like "Special message to denote the end of variadic list of arguments".

This revision is now accepted and ready to land.Nov 9 2017, 5:21 AM
AndreyChurbanov requested changes to this revision.Nov 9 2017, 5:31 AM

Sorry, was too hasty.

This patch gives me compile error:

trunk/runtime/src/kmp_settings.cpp:1571:3: error: no matching function for call to

    '__kmp_stg_parse_str'
__kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
^~~~~~~~~~~~~~~~~~~

So probably the __kmp_cpuinfo_file type should be changed to "char*", or const should be casted out.

This revision now requires changes to proceed.Nov 9 2017, 5:31 AM
Hahnfeld updated this revision to Diff 122241.Nov 9 2017, 6:56 AM
Hahnfeld edited edge metadata.

Remove const from __kmp_cpuinfo_file.

Hahnfeld marked an inline comment as done.Nov 9 2017, 6:59 AM

Sorry, was too hasty.

This patch gives me compile error:

trunk/runtime/src/kmp_settings.cpp:1571:3: error: no matching function for call to

    '__kmp_stg_parse_str'
__kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
^~~~~~~~~~~~~~~~~~~

So probably the __kmp_cpuinfo_file type should be changed to "char*", or const should be casted out.

Damn, this code was covered by KMP_AFFINITY_SUPPORTED which is set neither on my MacBook nor on Power. I "hacked" this by temporarily enabling it on Power. Would you be able to retest on x86 Linux?

AndreyChurbanov accepted this revision.Nov 9 2017, 7:11 AM

LGTM

I've checked both const related patches (this one and D39756) on Linux x86 using clang and icc. They work for me now.

This revision is now accepted and ready to land.Nov 9 2017, 7:11 AM

LGTM

I've checked both const related patches (this one and D39756) on Linux x86 using clang and icc. They work for me now.

Thanks, much appreciated. Maybe I should look into enabling affinity on Power to reduce the amount of code that isn't built and tested there...

This revision was automatically updated to reflect the committed changes.