This is an archive of the discontinued LLVM Phabricator instance.

[flang] Support target-specialized C int types
AbandonedPublic

Authored by peixin on Oct 11 2022, 6:46 AM.

Details

Summary

Currently, C_INTMAX_T is 64-bit integer in stdint.h on 64-bit linux
machine. Make it c_int128_t until it is supported.

On non-win32 and non-mach machine, C_INT_FAST16_T and C_INT_FAST32_T are
defined as long int. The detailed info can be obtained as follows:

! test.c
#include <stdint.h>
$ clang test.c -E
...
typedef signed char int_fast8_t;

typedef long int int_fast16_t;
typedef long int int_fast32_t;
typedef long int int_fast64_t;
...

Fixes #58282.

Diff Detail

Event Timeline

peixin created this revision.Oct 11 2022, 6:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 11 2022, 6:46 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
peixin requested review of this revision.Oct 11 2022, 6:46 AM
peixin added inline comments.Oct 11 2022, 6:50 AM
flang/module/iso_c_binding.f90
49

I find this rule by looking at intel definition /opt/intel/oneapi/compiler/2022.0.2/linux/compiler/include/iso_c_binding.f90:

! On linux the following C types (int8_t .. intmax_t) are defined in stdint.h
! Support for C types on Windows.
!DEC$ IF DEFINED(_WIN32)
    INTEGER (KIND=4), PARAMETER :: C_INT8_T = 1
    INTEGER (KIND=4), PARAMETER :: C_INT16_T = 2
    INTEGER (KIND=4), PARAMETER :: C_INT32_T = 4
    INTEGER (KIND=4), PARAMETER :: C_INT64_T = 8
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST8_T = 1
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST16_T = 2
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST32_T = 4
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST64_T = 8
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST8_T = 1
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST16_T = 2
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST32_T = 4
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST64_T = 8
    INTEGER (KIND=4), PARAMETER :: C_INTMAX_T = 8
!DEC$ ELSEIF DEFINED(__MACH__)
    INTEGER (KIND=4), PARAMETER :: C_INT8_T = 1
    INTEGER (KIND=4), PARAMETER :: C_INT16_T = 2
    INTEGER (KIND=4), PARAMETER :: C_INT32_T = 4
    INTEGER (KIND=4), PARAMETER :: C_INT64_T = 8
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST8_T = 1
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST16_T = 2
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST32_T = 4
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST64_T = 8
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST8_T = 1
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST16_T = 2
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST32_T = 4
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST64_T = 8
    INTEGER (KIND=4), PARAMETER :: C_INTMAX_T = 8
!DEC$ ELSE
    INTEGER (KIND=4), PARAMETER :: C_INT8_T = 1
    INTEGER (KIND=4), PARAMETER :: C_INT16_T = 2
    INTEGER (KIND=4), PARAMETER :: C_INT32_T = 4
    INTEGER (KIND=4), PARAMETER :: C_INT64_T = 8
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST8_T = 1
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST16_T = 2
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST32_T = 4
    INTEGER (KIND=4), PARAMETER :: C_INT_LEAST64_T = 8
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST8_T = 1
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST16_T = POINTER_LEN
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST32_T = POINTER_LEN
    INTEGER (KIND=4), PARAMETER :: C_INT_FAST64_T = 8
    INTEGER (KIND=4), PARAMETER :: C_INTMAX_T = 8
!DEC$ ENDIF

I also double checked one minwg32 and mach machine.

peixin edited the summary of this revision. (Show Details)Oct 11 2022, 6:08 PM

@peixin It seems these code snippets from Intel are part of a copyrighted file, owned by Intel. Do you know if LLVM has a policy about including such code, even in a code review like this?

@peixin It seems these code snippets from Intel are part of a copyrighted file, owned by Intel. Do you know if LLVM has a policy about including such code, even in a code review like this?

Sorry. How should I do for now? It seems that I don't have the permission to remove it or Phabricator does not support it?

peixin added a comment.EditedOct 13 2022, 6:53 PM

@sscalpone Should I abandon this PR or ask help from the administrator to remove it?

peixin abandoned this revision.Oct 18 2022, 6:45 PM