Skip to content

OKL incorrect macro expansion  #750

@IuriiKobein

Description

@IuriiKobein

Hello,
My team currently testing a new OKL transpiler based on clang frontend against different libraries that using OCCA.

We have found the bug in legacy OKL preprocessor.
Input :

#define MYSTR my_fn_

inline void my_fn_1() {}
inline void my_fn_2() {}


@directive("#define MYMACRO(idx) MYSTR ## idx")

@kernel void hello_kern() {
    for (int i = 0; i < 10; ++i; @outer) {
        for (int j = 0; j < 10; ++j; @inner) {


            MYMACRO(1)();
            MYMACRO(2)();

        }
    }
}

OKL legacy outputs:

inline void my_fn_1() {}

inline void my_fn_2() {}

extern "C" void hello_kern() {
#pragma omp parallel for
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      my_fn_1();
      my_fn_2();
    }
  }
}

New OKL transpiler output:

inline void my_fn_1() {}

inline void my_fn_2() {}

extern "C" void hello_kern() {
#pragma omp parallel for
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      MYSTR1();
      MYSTR2();
    }
  }

Actually to the latest one is correct according to C preprocessor spec.
To archive desire behavior additional level of macro directive is required
#define CONCAT(id1, id2) id1##id2
#define MYMACRO(idx) CONCAT(MYSTR, idx)

Metadata

Metadata

Assignees

No one assigned

    Labels

    OKLbugUse this label when reporting bugs!parser

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions