NCAS-CMS / NCAS-CMS/cf-python

UMRead C library: `make` warnings with Clang compiler

Open
#325 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
150
Forks
23
Avg merge
1d 11h
Merged PRs (30d)
2

Description

The CI job using MacOS and its default compiler Clang is currently raising some warnings on building the UMRead C library, all amounting to unwgdos.c:371:45: warning: shifting a negative signed value is undefined [-Wshift-negative-value], with full make output of (or see also https://github.com/NCAS-CMS/cf-python/runs/5130889501?check_suite_focus=true for the job log, etc.):

$ cd /Users/runner/work/cf-python/cf-python/main/cf/umread_lib/c-lib
$ make
clang -Wall -fPIC -DOSX -c umfile.c
clang -Wall -fPIC -DOSX -c error.c
clang -Wall -fPIC -DOSX -c filetype.c
clang -Wall -fPIC -DOSX -c malloc.c
clang -Wall -fPIC -DOSX -c linklist.c
clang -Wall -fPIC -DOSX -c new_structs.c
clang -Wall -fPIC -DOSX -c swap.c
/Applications/Xcode_13.2.1.app/Contents/Developer/usr/bin/make -C type-dep
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o umfile_test_typedep_sgl.o umfile_test_typedep.c
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o interpret_header_sgl.o interpret_header.c
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o read_sgl.o read.c
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o process_vars_sgl.o process_vars.c
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o debug_dump_sgl.o debug_dump.c
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o date_and_time_sgl.o date_and_time.c
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o compare_sgl.o compare.c
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o levels_sgl.o levels.c
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o axes_sgl.o axes.c
clang -Wall -fPIC -DOSX -I.. -c -DSINGLE -o unwgdos_sgl.o unwgdos.c
unwgdos.c:371:45: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
      *inum = (*icomp << (31-istart)) & (~0 << 31);
                                         ~~ ^
unwgdos.c:3[9](https://github.com/NCAS-CMS/cf-python/runs/5130889501?check_suite_focus=true#step:10:9)6:[27](https://github.com/NCAS-CMS/cf-python/runs/5130889501?check_suite_focus=true#step:10:27): warning: shifting a negative signed value is undefined [-Wshift-negative-value]
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o umfile_test_typedep_dbl.o umfile_test_typedep.c
  i = (ui >> ibit) & ~(~0 << 1);
                       ~~ ^
2 warnings generated.
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o interpret_header_dbl.o interpret_header.c
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o read_dbl.o read.c
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o process_vars_dbl.o process_vars.c
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o debug_dump_dbl.o debug_dump.c
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o date_and_time_dbl.o date_and_time.c
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o compare_dbl.o compare.c
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o levels_dbl.o levels.c
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o axes_dbl.o axes.c
clang -Wall -fPIC -DOSX -I.. -c -DDOUBLE -o unwgdos_dbl.o unwgdos.c
unwgdos.c:371:45: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
      *inum = (*icomp << ([31](https://github.com/NCAS-CMS/cf-python/runs/5130889501?check_suite_focus=true#step:10:31)-istart)) & (~0 << 31);
                                         ~~ ^
rm -f umfile_typedep.a
unwgdos.c:[39](https://github.com/NCAS-CMS/cf-python/runs/5130889501?check_suite_focus=true#step:10:39)6:27: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
ar r umfile_typedep.a  umfile_test_typedep_sgl.o  interpret_header_sgl.o  read_sgl.o  process_vars_sgl.o  debug_dump_sgl.o  date_and_time_sgl.o  compare_sgl.o  levels_sgl.o  axes_sgl.o  unwgdos_sgl.o  umfile_test_typedep_dbl.o  interpret_header_dbl.o  read_dbl.o  process_vars_dbl.o  debug_dump_dbl.o  date_and_time_dbl.o  compare_dbl.o  levels_dbl.o  axes_dbl.o  unwgdos_dbl.o
  i = (ui >> ibit) & ~(~0 << 1);
                       ~~ ^
2 warnings generated.
ar: creating archive umfile_typedep.a
clang -dynamiclib -o umfile.so umfile.o error.o filetype.o malloc.o linklist.o new_structs.o swap.o -force_load type-dep/umfile_typedep.a

@alaniwi please could you look at this and let us know if it's an issue or not (I don't know enough C to be sure myself, and David is away until 28th)? Thanks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cf/umread_lib/c-lib/unwgdos.c at the reported lines 371 and 396, then run make with the Clang configuration shown in the issue. Check the compiler documentation or project context to determine whether the shifts are valid; done means the macOS build no longer emits these warnings without changing library behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.