Skip to content

build: guard feature macros under -Wundef#7

Merged
SIGFUN merged 1 commit into
microsoft:publicfrom
isuzano:public
May 4, 2026
Merged

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

Conversation

@isuzano
Copy link
Copy Markdown
Contributor

@isuzano isuzano commented May 2, 2026

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

isuzano commented May 2, 2026

@microsoft-github-policy-service agree

@FoxMoss FoxMoss mentioned this pull request May 2, 2026
@mingodad
Copy link
Copy Markdown

mingodad commented May 2, 2026

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
Copy link
Copy Markdown
Contributor

SIGFUN commented May 4, 2026

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

SIGFUN commented May 4, 2026

Thanks!

@SIGFUN 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