This patches fixes the case when a user-defined mapper is attached to the elements of an array, and to report error when a mapper is used for types other than struct, class, and union.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Without this patch, it cannot recognize array with mapper, for instance, #pragma omp target map(mapper(a),to: arr[0:2]) won't work without this patch.
Without this patch, it won't be able to find the mapper in this case, and Clang assumes no mapper. This patch fixes it, so the compiler can find the mapper in this case.
Definitely need positive tests with ast printing and codegen.
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14751 ↗ | (On Diff #221577) | Why do you want canonical type here? I think it is wrong. It drops all language sugar like typedefs etc. But typedefs are not supported in mappers, right? |
HI Alexey, the ast print test is already there. Because I didn't check the mapper for array type before, such code will always not report any error, and ast print test is correct. Codegen test belongs to the other patch I released. It fits that patch much better.
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14751 ↗ | (On Diff #221577) | I didn't see that the spec says typedef is not supported in mappers, so I suppose it should be supported. So I think getCanonicalType is necessary here? |
How is this possible? If we did not have support for the array type, we could not have correct handling of such types in successful tests.
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14751 ↗ | (On Diff #221577) | Do we check the canonicaL type by default, for non-array type? |
The ast print for array with mapper was correct because the mapper id is still with the array type. Without this patch, the problem is it will not look up the mapper declaration associated with the id, and as a result, the codegen is not correct. I found this problem when I tested the codegen.
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14751 ↗ | (On Diff #221577) | Yes, we use canonical type for non-array type, for instance, line 14935 in this file. |
Then another one question. Why we don't emit the diagnostics if the original type is not a class, struct or union? We just ignore this situation currently but we should not. The error message must be emitted. I think that's why the ast-print test works correctly though it should not.
We emit such diagnostic when mapper is declared, i.e., you cannot define a mapper for a non-class, non-struct, non-union type. It's in function ActOnOpenMPDeclareMapperType in SemaOpenMP.cpp. But I didn't emit such information where mapper is used. I will fix it in this patch. Thanks for getting this!
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14805 ↗ | (On Diff #221991) | Why need an additional check for scope and not "default" id? I don't see this additional requirement in the standard. |
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14805 ↗ | (On Diff #221991) | It's because every variable in map clauses will check this, including those are not struct, class, or union. Using this, e.g., mapping an integer won't report error that it doesn't have a mapper. |
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14805 ↗ | (On Diff #221991) | Maybe just move the check to the end of the function? |
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14805 ↗ | (On Diff #221991) | It will do some additional useless work if I move it to the end. I don't think it is necessary to move it back. But if you believe it's better, I can do it. |
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14805 ↗ | (On Diff #221991) | Could you add tests for this new functionality? |
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14805 ↗ | (On Diff #221991) | I already add the test in declare_mapper_message.c. I think nothing is needed for ast print test. |
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14805 ↗ | (On Diff #221991) | I mean, for this error message. I did not see the change in the tests when you added this new check. |
lib/Sema/SemaOpenMP.cpp | ||
---|---|---|
14805 ↗ | (On Diff #221991) | line 55, 68, 79 in declare_mapper_messages.c is added for this new check. |
Thanks Alexey! Please check the other 2 mapper patches at https://reviews.llvm.org/D67833 and https://reviews.llvm.org/D68100 when you have time. They should be the last mapper patches.