Fix #59177, add check for dimensionality for shape argument against rank of FPTR argument in c_f_pointer
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Please check Fortran 2018 18.2.3.3: SHAPE shall be present if and only if FPTR is an array; its size shall be equal to the rank of FPTR.
I guess you want to add the check when shape has constant size. Please notice that it cannot be checked when the size of shape is compile-time unknown.
fix the commit to correctly compare size of array against rank, note that expr->Rank() ==1 is required to fix a potential issue when a non-scalar shape is passed into the function, the program crashes after context.message
flang/lib/Evaluate/intrinsics.cpp | ||
---|---|---|
2622–2623 | actually, also probably better to use *argExpr instead of *arguments[2] in the GetConstantShape call. |
replace redundant if statements by GetConstantShape, change argument is GetConstantShape call, rewrite error message
flang/lib/Evaluate/intrinsics.cpp | ||
---|---|---|
2621 | I'm afraid this will conflict with check-call error, as it also check if the argument is a scalar (albeit not checking the rank). |
flang/lib/Evaluate/intrinsics.cpp | ||
---|---|---|
2621 | error: Semantic errors in test.f90 ./test.f90:17:51: error: SHAPE= argument to C_F_POINTER() must be a rank-one array. call c_f_pointer(scalarC, multiDimIntF, shape=1) ^ ./test.f90:17:51: error: Whole scalar actual argument may not be associated with a dummy argument 'shape=' array call c_f_pointer(scalarC, multiDimIntF, shape=1) ^ which will reult in two reports being issued for the same error. |
LGTM now except one clang-format problem in flang/lib/Evaluate/intrinsics.cpp.
flang/lib/Evaluate/intrinsics.cpp | ||
---|---|---|
2621 | Thanks. This has already been checked elsewhere. |
Can you also add another check here?