HIP
HIP copied to clipboard
[Feature]: Make the `options` parameter to `hiprtcCompileProgram` const char* const *`
Suggestion Description
Currently, the function has the following signature:
hiprtcResult hiprtcCompileProgram (
hiprtcProgram prog,
int numOptions,
const char ** options
)
However, this triggers -Wcast-qual warnings with a typical usage:
#include <hip/hiprtc.h>
#include <string.h>
int main()
{
char *opts[2];
opts[0] = strdup("-O3");
opts[1] = strdup("-fno");
hiprtcProgram prog = NULL;
// TODO: initialize prog
hiprtcCompileProgram(prog, 2, opts);
return 0;
}
$ hipcc --offload-arch=gfx90a -D__HIP_PLATFORM_AMD__ -Wcast-qual constchar.c
constchar.c:11:35: warning: passing 'char *[2]' to parameter of type 'const char **' discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
We cannot simply use (const char **)opts either: https://c-faq.com/ansi/constmismatch.html
$ hipcc --offload-arch=gfx90a -D__HIP_PLATFORM_AMD__ -Wcast-qual constchar.c
constchar.c:11:49: warning: cast from 'char **' to 'const char **' must have all intermediate pointers const qualified to be safe [-Wcast-qual]
hiprtcCompileProgram(prog, 2, (const char**)opts);
^
1 warning generated.
Since the function accepts a constant pointer to constant strings, it is reasonable to make its signature read
hiprtcResult hiprtcCompileProgram (
hiprtcProgram prog,
int numOptions,
const char * const* options
)
This will both explicitly communicate what the function does and also allow to write the code like above safely by using and explicit cast to (const char* const*)opts
Operating System
Ubuntu
GPU
MI50
ROCm Component
HIP RTC