llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.93k stars 11.53k forks source link

JSON Dumper is omitting OMP clause information #102498

Open goldenskans opened 1 month ago

goldenskans commented 1 month ago

When using the "-ast-dump=json" flag, the generated AST information in the JSON file is missing information about OpenMP clauses. Directives seem to show up fine, but not any associated clauses. In comparison, the text output using just "-ast-dump" does contain both the directives and their clauses.

Put the following snippet of code in a file called "noOMPClauseInJSON.cpp"

#include <omp.h>

#define SIZE 5

void test(int *a, int *b, int *c, int size)
{
    int i;
    #pragma omp parallel
    {
        #pragma omp for nowait
        for (i = 0; i < size; i++)
            b[i] = a[i] * a[i];

        #pragma omp for nowait
        for (i = 0; i < size; i++)
            c[i] = a[i]/2;
    }
}

Clang command:

% clang -fsyntax-only -fno-color-diagnostics -Xclang -ast-dump=json -x c++ -fopenmp "~/noOMPClauseInJSON.cpp" -v > "~/noOMPClauseInJSON.json"

Do a search for the "OMPForDirective" in the JSON file and note there is no "OMPNowaitClause" after it. There is however and empty child section "{ }" that is presumably where the information for the clause should appear. Compare that to text output by repeating the same clang command but remove "=json" and change the file extension for the output to ".txt". Search again for "OMPForDirective" and note that the "OMPNowaitClause" appears immediately after its associated "OMPForDirective".

This makes it difficult to build accurate tooling using the AST output since the JSON is easier to consume than the text output.

This was caught using clang 18.0.0 but also reproducible using the tip (clang 20.0.0)

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-frontend

Author: Eric (goldenskans)

When using the "-ast-dump=json" flag, the generated AST information in the JSON file is missing information about OpenMP clauses. Directives seem to show up fine, but not any associated clauses. In comparison, the text output using just "-ast-dump" does contain both the directives and their clauses. Put the following snippet of code in a file called "noOMPClauseInJSON.cpp" ```c++ #include <omp.h> #define SIZE 5 void test(int *a, int *b, int *c, int size) { int i; #pragma omp parallel { #pragma omp for nowait for (i = 0; i < size; i++) b[i] = a[i] * a[i]; #pragma omp for nowait for (i = 0; i < size; i++) c[i] = a[i]/2; } } ``` Clang command: ```shell % clang -fsyntax-only -fno-color-diagnostics -Xclang -ast-dump=json -x c++ -fopenmp "~/noOMPClauseInJSON.cpp" -v > "~/noOMPClauseInJSON.json" ``` Do a search for the "OMPForDirective" in the JSON file and note there is no "OMPNowaitClause" after it. There is however and empty child section "{ }" that is presumably where the information for the clause should appear. Compare that to text output by repeating the same clang command but remove "=json" and change the file extension for the output to ".txt". Search again for "OMPForDirective" and note that the "OMPNowaitClause" appears immediately after its associated "OMPForDirective". This makes it difficult to build accurate tooling using the AST output since the JSON is easier to consume than the text output. This was caught using clang 18.0.0 but also reproducible using the tip (clang 20.0.0)