[clang-format] Do not parse certain characters in pragma directives
Currently, we parse lines inside of a compiler `#pragma` the same way we parse any other line. This is fine for some cases, like separating expressions and adding proper spacing, but in others it causes some poor results from miscategorizing some tokens. For example, the OpenMP offloading uses certain clauses that contain special characters like `map(tofrom : A[0:N])`. This will be formatted poorly as it will be split between lines on the first colon. Additionally the subscript notation will lead to poor spacing. This can be seen in the OpenMP tests as the automatic clang formatting with inevitably ruin the formatting. For example, the following contrived example will be formatted poorly. ``` #pragma omp target teams distribute collapse(2) map(to: A[0 : M * K]) \ map(to: B[0:K * N]) map(tofrom:C[0:M*N]) firstprivate(Alpha) \ firstprivate(Beta) firstprivate(X) firstprivate(D) firstprivate(Y) \ firstprivate(E) firstprivate(Z) firstprivate(F) ``` This results in this when formatted, which is far from ideal. ``` #pragma omp target teams distribute collapse(2) map(to \ : A [0:M * K]) \ map(to \ : B [0:K * N]) map(tofrom \ : C [0:M * N]) firstprivate(Alpha) \ firstprivate(Beta) firstprivate(X) firstprivate(D) firstprivate(Y) \ firstprivate(E) firstprivate(Z) firstprivate(F) ``` This patch seeks to improve this by adding extra logic where the parsing goes awry. This is primarily caused by the colon being parsed as an inline-asm directive and the brackes an objective-C expressions. Also the line gets indented every single time the line is dropped. This doesn't implement true parsing handling for OpenMP statements. Reviewed By: HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D136100
Loading
Please sign in to comment