Skip to content
  • Cheng Shao's avatar
    a9d27c90
    rts: use __builtin_offsetof to implement STG_FIELD_OFFSET · a9d27c90
    Cheng Shao authored
    This patch fixes the STG_FIELD_OFFSET macro definition by using
    __builtin_offsetof, which is what gcc/clang uses to implement offsetof
    in standard C. The previous definition that uses NULL pointer involves
    subtle undefined behavior in C and thus reported by
    UndefinedBehaviorSanitizer as well:
    
    ```
    rts/Capability.h:243:58: runtime error: member access within null pointer of type 'Capability' (aka 'struct Capability_')
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/Capability.h:243:58
    ```
    
    (cherry picked from commit 05c4fafb)
    a9d27c90
    rts: use __builtin_offsetof to implement STG_FIELD_OFFSET
    Cheng Shao authored
    This patch fixes the STG_FIELD_OFFSET macro definition by using
    __builtin_offsetof, which is what gcc/clang uses to implement offsetof
    in standard C. The previous definition that uses NULL pointer involves
    subtle undefined behavior in C and thus reported by
    UndefinedBehaviorSanitizer as well:
    
    ```
    rts/Capability.h:243:58: runtime error: member access within null pointer of type 'Capability' (aka 'struct Capability_')
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/Capability.h:243:58
    ```
    
    (cherry picked from commit 05c4fafb)
Loading