Skip to content

[clang][OpenMP] The include file <omp.h> doesn't compile in C89 mode (it uses the "inline" keyword) #130452

Open
@quake33

Description

@quake33

Hello,

Clang 14.0.6 fails to compile the following program (main.c):

#include <omp.h>

int main(void) {
  return 0;
}

The command producing the error is:

clang -std=c89 -fopenmp main.c

The error message is:

In file included from main.c:1:
/usr/lib/llvm-14/lib/clang/14.0.6/include/omp.h:493:12: error: unknown type name 'inline'
    static inline int omp_is_initial_device(void) { return 1; }
           ^
1 error generated.

I obtained Clang from the official Debian (stable) package.

I think this issue is still relevant today because the keyword inline is still written in the include file <omp.h>.

The problem is that inline is not a known keyword in C89. Therefore I propose to change this:

#   if defined(_OPENMP) && _OPENMP >= 201811
    #pragma omp begin declare variant match(device={kind(host)})
    static inline int omp_is_initial_device(void) { return 1; }
    #pragma omp end declare variant
    #pragma omp begin declare variant match(device={kind(nohost)})
    static inline int omp_is_initial_device(void) { return 0; }
    #pragma omp end declare variant
#   endif

into this:

#   if defined(_OPENMP) && _OPENMP >= 201811
#       if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #pragma omp begin declare variant match(device={kind(host)})
    static inline int omp_is_initial_device(void) { return 1; }
    #pragma omp end declare variant
    #pragma omp begin declare variant match(device={kind(nohost)})
    static inline int omp_is_initial_device(void) { return 0; }
    #pragma omp end declare variant
#       else
    #pragma omp begin declare variant match(device={kind(host)})
    static int omp_is_initial_device(void) { return 1; }
    #pragma omp end declare variant
    #pragma omp begin declare variant match(device={kind(nohost)})
    static int omp_is_initial_device(void) { return 0; }
    #pragma omp end declare variant
#       endif
#   endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions