Menu ▾ ▴

#19 NVHPC compiler gives error with pointer arithmetic

v1.0 (example)
open
nobody
None
5
2 days ago
4 days ago
Carl Ponder
No

I'm seeing this error with the 4.14.1 source

nvc -m64 -tp=native -fpic -noswitcherror -Masmkeyword -D__thread='' -mp -lpthread -std=c99  -g -Wall -Werror -Wextra -Wno-unused-parameter -I. -I/usr/local/build/include -DCONFIG_PFMLIB_DEBUG -DCONFIG_PFMLIB_OS_LINUX -DCONFIG_PFMLIB_NOTRACEPOINT  -g -Wall -Werror -Wextra -Wno-unused-parameter -I. -I/usr/local/build/lib/../include -DCONFIG_PFMLIB_DEBUG -DCONFIG_PFMLIB_OS_LINUX -DCONFIG_PFMLIB_NOTRACEPOINT -DHAS_OPENAT -D_REENTRANT -I. -fvisibility=hidden -DCONFIG_PFMLIB_ARCH_ARM64 -I. -c pfmlib_common.c
"pfmlib_common.c", line 920: error: arithmetic on pointer to void or function type [nonobject_pointer_arithmetic]

    return (pfmlib_pmu_t *)(p - offs);
                              ^

Remark: individual warnings can be suppressed with "--diag_suppress <warning-name>"

1 error detected in the compilation of "pfmlib_common.c".
make[1]: *** [/usr/local/build/lib/../rules.mk:30: pfmlib_common.o] Error 2
make[1]: Leaving directory '/usr/local/build/lib'
make: *** [Makefile:73: install] Error 2

This didn't happen with the 4.13.0 source.

Discussion

  • Carl Ponder

    Carl Ponder - 4 days ago

    I'm using the NVHPC 26.9 compilers here. Googling around, it suggests that this statement is accepted by GCC but may not be compliant with the C standard. Note that the -std=c99 flag failed to suppress the error.

    If there's a dimple code substitution I can use, I'd be willing to try it.

     
  • Carl Ponder

    Carl Ponder - 3 days ago

    4.14.0 has the same problem as 4.14.1.

     
  • Carl Ponder

    Carl Ponder - 3 days ago

    This is the body in 4.14.1:

        915 static inline pfmlib_pmu_t *
        916 pfmlib_node_to_pmu(pfmlib_node_t *n)
        917 {
        918         void *p = (void *)n;
        919         void *offs = (void *)offsetof(pfmlib_pmu_t, node);
        920         return (pfmlib_pmu_t *)(p - offs);
        921 }
    

    So, yeah, it's performing arithmetic between two void * pointers.

     
  • Carl Ponder

    Carl Ponder - 2 days ago

    I can stop this particular error using the command

    sed -i~ '918,919s/void \*/unsigned long long \*/g' lib/pfmlib_common.c
    

    which converts the above to

        915 static inline pfmlib_pmu_t *
        916 pfmlib_node_to_pmu(pfmlib_node_t *n)
        917 {
        918         unsigned long long *p = (unsigned long long *)n;
        919         unsigned long long *offs = (unsigned long long *)offsetof(pfmlib_pmu_t, node);
        920         return (pfmlib_pmu_t *)(p - offs);
        921 }
    
     

    Last edit: Carl Ponder 2 days ago
  • Carl Ponder

    Carl Ponder - 2 days ago

    Ok -- the -Werror flag causes the failure here. I assume it's being used precisely to flag this kind of issue: potentially non-portable C.
    That said, I don't know what the correct source-change would be to fix this, I don't use pointer-arithmetic. For now, I'm just going to suppress the error-flagging:

    make DBG="-g -Wall -Wextra" ...
    
     

Log in to post a comment.