Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig 0.9.0 Regression: can't import <core_cm3.h> #10440

Open
foldl opened this issue Dec 29, 2021 · 1 comment
Open

Zig 0.9.0 Regression: can't import <core_cm3.h> #10440

foldl opened this issue Dec 29, 2021 · 1 comment
Labels
arch-arm 32-bit ARM bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@foldl
Copy link

foldl commented Dec 29, 2021

Zig Version

0.9.0

Steps to Reproduce

0.9.0 fails to import <core_cm3.h> while 0.8.0 is OK.

  1. aaa.h

    #pragma once
    
    typedef enum IRQn
    {
    /* -------------------  Cortex-M3 Processor Exceptions Numbers  ------------------- */
      NonMaskableInt_IRQn           = -14,      /*!<  2 Non Maskable Interrupt          */
      HardFault_IRQn                = -13,      /*!<  3 HardFault Interrupt             */
      MemoryManagement_IRQn         = -12,      /*!<  4 Memory Management Interrupt     */
      BusFault_IRQn                 = -11,      /*!<  5 Bus Fault Interrupt             */
      UsageFault_IRQn               = -10,      /*!<  6 Usage Fault Interrupt           */
      SVCall_IRQn                   =  -5,      /*!< 11 SV Call Interrupt               */
      DebugMonitor_IRQn             =  -4,      /*!< 12 Debug Monitor Interrupt         */
      PendSV_IRQn                   =  -2,      /*!< 14 Pend SV Interrupt               */
      SysTick_IRQn                  =  -1,      /*!< 15 System Tick Interrupt           */
    } IRQn_Type;
    
    /* --------  Configuration of the Cortex-M3 Processor and Core Peripherals  ------- */
    #define __CM3_REV                 0x0201    /*!< Core revision r2p1                              */
    #define __MPU_PRESENT             0         /*!< MPU present or not                              */
    #define __NVIC_PRIO_BITS          3         /*!< Number of Bits used for Priority Levels         */
    #define __Vendor_SysTickConfig    0         /*!< Set to 1 if different SysTick Config is used    */
    
    #include <core_cm3.h>                       /* Processor and core peripherals                    */
  2. zbug.zig

    const cm3 = @cImport({
        @cInclude("aaa.h");
    });
    
    export fn tool() c_int {
        return cm3.HardFault_IRQn;
    }
  3. build zbug.zig

    zig build-obj -target thumb-freestanding-none -mcpu cortex_m3 -I CMSIS_INC_PATH -I . zbug.zig

Expected Behavior

It should compile.

Actual Behavior

Using 0.9.0:

.\zbug.zig:1:13: error: C import failed
const cm3 = @cImport({
            ^
.\zbug.zig:1:13: note: libc headers not available; compilation does not link against libc
const cm3 = @cImport({
            ^
.../CMSIS/Include\core_cm3.h:138:6: note: "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
     ^
.\zbug.zig:6:12: note: referenced here
    return cm3.HardFault_IRQn;
           ^
@foldl foldl added the bug Observed behavior contradicts documented or intended behavior label Dec 29, 2021
@foldl
Copy link
Author

foldl commented Dec 30, 2021

It's reported because defined (__VFP_FP__) && !defined(__SOFTFP__) for Cortex M3. Code of core_cm3.h:

https://github.com/ARM-software/CMSIS/blob/f2cad4345783c948ed4a7f5cdb02cdc0856366f1/CMSIS/Include/core_cm3.h#L138

@Vexu Vexu added frontend Tokenization, parsing, AstGen, Sema, and Liveness. zig cc Zig as a drop-in C compiler feature labels Jan 9, 2022
@Vexu Vexu added this to the 0.10.0 milestone Jan 9, 2022
@andrewrk andrewrk added arch-arm 32-bit ARM regression It worked in a previous version of Zig, but stopped working. and removed zig cc Zig as a drop-in C compiler feature labels Aug 26, 2022
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Aug 26, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-arm 32-bit ARM bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
Development

No branches or pull requests

3 participants