Skip to content

build: guard feature macros under -Wundef - #7

Merged
Damien Sorresso (SIGFUN) merged 1 commit into
microsoft:publicfrom
isuzano:public
May 4, 2026
Merged

build: guard feature macros under -Wundef#7
Damien Sorresso (SIGFUN) merged 1 commit into
microsoft:publicfrom
isuzano:public

Conversation

@isuzano

Copy link
Copy Markdown
Contributor

Summary

Fix -Wundef failures caused by optional compiler/platform macros being used without guards.

Changes

  • Add fallback for __has_ptrcheck
  • Use defined(...) guards for compiler/platform macros
  • Fix __ZX_FIXED_ENUMS fallback without macro redefinition
  • Adjust __APPLE__ and __clang__ checks

Validation

  • make clean: OK
  • make test: progresses past previous -Wundef failures
  • Remaining failure is unrelated: -Wstack-protector in unit_buff_write_object_flex.c

Notes

This patch does not emulate bounds-safety features and does not change runtime behavior.
It only ensures safe handling of feature-test macros under -Wundef.

Add fallback definitions and defined() guards for optional compiler
and platform feature-test macros.

This avoids -Wundef failures without changing runtime behavior.
@isuzano

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@mingodad

Copy link
Copy Markdown

With this changes my build with gcc9 goes further but dies with:

make
cc -std=gnu11 -Werror -Wall -Wextra -Wcast-qual -Wconversion -Wformat=2 -Wformat-security -Wnull-dereference -Wstack-protector -Wvla -Warray-bounds -Wimplicit-fallthrough -Wint-conversion -Wdouble-promotion -Wundef -Wstrict-prototypes -Wbad-function-cast -Wfloat-equal -Wpointer-arith -Wformat-truncation=2 -Wformat-signedness -Wuninitialized -Wlogical-op -Wduplicated-cond -Wduplicated-branches -fstack-protector-strong -fno-delete-null-pointer-checks -ftrapv -Isrc -Iposix -g -DTARGET_0XTEST=1 -DPOINTER_TAG_BITS_HI=16 -DPOINTER_TAG_BITS_LO=3  -c -o build/public/obj/lib/src/0xc/std/cursor.o src/0xc/std/cursor.c
In file included from src/0xc/std/cursor.c:12:
src/0xc/std/cursor.c: In function ‘cmemopen’:
src/0xc/std/string.h:129:2: error: implicit declaration of function ‘strlcpy’; did you mean ‘strncpy’? [-Werror=implicit-function-declaration]
  129 |  strlcpy((DST), (SRC), sizeof(DST)); \
      |  ^~~~~~~
src/0xc/std/cursor.c:45:2: note: in expansion of macro ‘strscpy’
   45 |  strscpy(cur->cur_mode, mode);
      |  ^~~~~~~
cc1: all warnings being treated as errors
Makefile.public:148: recipe for target 'build/public/obj/lib/src/0xc/std/cursor.o' failed
make: *** [build/public/obj/lib/src/0xc/std/cursor.o] Error 1

Maybe it's missing some linux glibc specific definitions.

@SIGFUN

Damien Sorresso (SIGFUN) commented May 4, 2026

Copy link
Copy Markdown
Contributor

With this changes my build with gcc9 goes further but dies with:

make
cc -std=gnu11 -Werror -Wall -Wextra -Wcast-qual -Wconversion -Wformat=2 -Wformat-security -Wnull-dereference -Wstack-protector -Wvla -Warray-bounds -Wimplicit-fallthrough -Wint-conversion -Wdouble-promotion -Wundef -Wstrict-prototypes -Wbad-function-cast -Wfloat-equal -Wpointer-arith -Wformat-truncation=2 -Wformat-signedness -Wuninitialized -Wlogical-op -Wduplicated-cond -Wduplicated-branches -fstack-protector-strong -fno-delete-null-pointer-checks -ftrapv -Isrc -Iposix -g -DTARGET_0XTEST=1 -DPOINTER_TAG_BITS_HI=16 -DPOINTER_TAG_BITS_LO=3  -c -o build/public/obj/lib/src/0xc/std/cursor.o src/0xc/std/cursor.c
In file included from src/0xc/std/cursor.c:12:
src/0xc/std/cursor.c: In function ‘cmemopen’:
src/0xc/std/string.h:129:2: error: implicit declaration of function ‘strlcpy’; did you mean ‘strncpy’? [-Werror=implicit-function-declaration]
  129 |  strlcpy((DST), (SRC), sizeof(DST)); \
      |  ^~~~~~~
src/0xc/std/cursor.c:45:2: note: in expansion of macro ‘strscpy’
   45 |  strscpy(cur->cur_mode, mode);
      |  ^~~~~~~
cc1: all warnings being treated as errors
Makefile.public:148: recipe for target 'build/public/obj/lib/src/0xc/std/cursor.o' failed
make: *** [build/public/obj/lib/src/0xc/std/cursor.o] Error 1

Maybe it's missing some linux glibc specific definitions.

Do you have prototypes for strlcpy(3) et al. in your default search paths? Might need to add an inclusion path depending on your system if the gcc9 toolchain headers don't have those prototypes.

@SIGFUN

Copy link
Copy Markdown
Contributor

Thanks!

@SIGFUN
Damien Sorresso (SIGFUN) merged commit eabe4a1 into microsoft:public May 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants