Skip to content

Translate-c regression - error, when using multiple #pragma once when also including a libc header #25410

@kavika13

Description

@kavika13

Zig Version

0.16.0-dev.463+f624191f9

Steps to Reproduce and Observed Behavior

This is a stripped down repro of an issue I was seeing while trying to use build.zig to translate headers from this library: https://github.com/richgel999/miniz

I'm using Windows 10, if that makes a difference.

Create a header file (test.h) with these contents:

#pragma once
#include <time.h>
#pragma once

Run this command on the header:

zig translate-c -lc test.h

On Zig 0.16.0-dev.463, it returns an error.

If I remove any of those lines in test.h, then the error does not occur.

The error (I replaced spaces with newlines, in case that made it more legible):

error: the following build command failed with exit code 1:
C:\Users\kavika\AppData\Local\zig\o\189f1ed682f34b880cfec35678bf38cf\translate-c.exe
-x
c
-isystem
C:\Users\kavika\.zvm\master\lib\compiler/aro/include
-fno-PIE
-fPIC
-g
-gcodeview
-fno-lto
-MD
-MV
-MF
C:\Users\kavika\AppData\Local\zig\tmp\c7e498ef919a9372-test.h.d
-fhosted
-nostdinc
-D__MSVCRT_VERSION__=0xE00
-D_WIN32_WINNT=0x0a00
-isystem
C:\Users\kavika\.zvm\master\lib\include
-isystem
C:\Users\kavika\.zvm\master\lib\libc\include\x86_64-windows-gnu
-isystem
C:\Users\kavika\.zvm\master\lib\libc\include\generic-mingw
-isystem
C:\Users\kavika\.zvm\master\lib\libc\include\x86_64-windows-any
-isystem
C:\Users\kavika\.zvm\master\lib\libc\include\any-windows-any
-O0
-target
x86_64-windows.win10_cu...win10_cu-gnu
-mcpu=znver3-16bit_mode-32bit_mode-3dnow-3dnowa+64bit+adx+aes+allow_light_256_bit-amx_avx512-amx_bf16-amx_complex-amx_fp16-amx_fp8-amx_int8-amx_movrs-amx_tf32-amx_tile-amx_transpose+avx-avx10_1-avx10_2+avx2-avx512bf16-avx512bitalg-avx512bw-avx512cd-avx512dq-avx512er-avx512f-avx512fp16-avx512ifma-avx512pf-avx512vbmi-avx512vbmi2-avx512vl-avx512vnni-avx512vp2intersect-avx512vpopcntdq-avxifma-avxneconvert-avxvnni-avxvnniint16-avxvnniint8+bmi+bmi2-branch_hint+branchfusion-bsf_bsr_0_clobbers_result-ccmp-cf-cldemote+clflushopt+clwb+clzero+cmov-cmpccxadd+crc32+cx16+cx8-egpr-enqcmd-ermsb-evex512+f16c-false_deps_getmant-false_deps_lzcnt_tzcnt-false_deps_mulc-false_deps_mullq-false_deps_perm-false_deps_popcnt-false_deps_range-fast_11bytenop+fast_15bytenop-fast_7bytenop+fast_bextr-fast_dpwssd-fast_gather-fast_hops+fast_imm16+fast_lzcnt+fast_movbe+fast_scalar_fsqrt+fast_scalar_shift_masks-fast_shld_rotate-fast_variable_crosslane_shuffle+fast_variable_perlane_shuffle+fast_vector_fsqrt-fast_vector_shift_masks-faster_shift_than_shuffle+fma-fma4+fsgsbase+fsrm+fxsr-gfni-harden_sls_ijmp-harden_sls_ret-hreset-idivl_to_divb+idivq_to_divl-inline_asm_use_gpr32-invpcid-kl-lea_sp-lea_uses_ag-lvi_cfi-lvi_load_hardening-lwp+lzcnt+macrofusion+mmx+movbe-movdir64b-movdiri-movrs-mwaitx-ndd-nf-no_bypass_delay-no_bypass_delay_blend-no_bypass_delay_mov-no_bypass_delay_shuffle+nopl-pad_short_functions+pclmul-pconfig-pku+popcnt-ppx-prefer_128_bit-prefer_256_bit-prefer_mask_registers-prefer_movmsk_over_vtest-prefer_no_gather-prefer_no_scatter-prefetchi-prefetchwt1+prfchw-ptwrite-push2pop2-raoint+rdpid-rdpru+rdrnd+rdseed-retpoline-retpoline_external_thunk-retpoline_indirect_branches-retpoline_indirect_calls-rtm+sahf+sbb_dep_breaking-serialize-seses-sgx+sha-sha512+shstk-slow_3ops_lea-slow_incdec-slow_lea-slow_pmaddwd-slow_pmulld-slow_shld-slow_two_mem_ops-slow_unaligned_mem_16-slow_unaligned_mem_32-sm3-sm4+smap+smep-soft_float+sse+sse2+sse3+sse4_1+sse4_2+sse4a-sse_unaligned_mem+ssse3-tagged_globals-tbm-tsxldtrk-tuning_fast_imm_vector_shift-uintr-use_glm_div_sqrt_costs-use_slm_arith_costs-usermsr+vaes+vpclmulqdq+vzeroupper-waitpkg-wbnoinvd-widekl+x87-xop+xsave+xsavec+xsaveopt+xsaves-zu
test.h

Expected Behavior

On Zig 0.15.1, the header gets translated and it spits out zig code, without having to remove any lines. The full header in the miniz lib I mentioned above also seems to translate successfully in zig 0.15.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions