Skip to content

Commit 55ee00e

Browse files
authored
[flang][CUDA] Allow constant to match device actual in specific procedure (llvm#178658)
When scanning the specific procedures of a generic interface for a match for a set of actual arguments, accept a constant actual argument as a match for a dummy argument with the DEVICE attribute.
1 parent 20103ee commit 55ee00e

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

flang/lib/Semantics/check-call.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,9 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
11071107
actualDataAttr = common::CUDADataAttr::Device;
11081108
}
11091109
// For device procedures, treat actual arguments with VALUE attribute as
1110-
// device data
1111-
if (!actualDataAttr && actualLastSymbol && IsValue(*actualLastSymbol) &&
1110+
// device data; also constant actual arguments.
1111+
if (!actualDataAttr &&
1112+
(!actualLastSymbol || IsValue(*actualLastSymbol)) &&
11121113
(*procedure.cudaSubprogramAttrs ==
11131114
common::CUDASubprogramAttrs::Device)) {
11141115
actualDataAttr = common::CUDADataAttr::Device;

flang/lib/Semantics/expression.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,7 +3011,6 @@ auto ExpressionAnalyzer::ResolveGeneric(const Symbol &symbol,
30113011
}
30123012
crtMatchingDistance = ComputeCudaMatchingDistance(
30133013
context_.languageFeatures(), *procedure, localActuals);
3014-
} else {
30153014
}
30163015
}
30173016
}
@@ -3113,14 +3112,12 @@ void ExpressionAnalyzer::EmitGenericResolutionError(const Symbol &symbol,
31133112
? "No specific subroutine of generic '%s' matches the actual arguments"_err_en_US
31143113
: "No specific function of generic '%s' matches the actual arguments"_err_en_US,
31153114
symbol.name())}) {
3116-
parser::ContextualMessages &messages{GetContextualMessages()};
3117-
semantics::Scope &scope{context_.FindScope(messages.at())};
31183115
for (const Symbol &specific : tried) {
31193116
if (auto procChars{characteristics::Procedure::Characterize(
31203117
specific, GetFoldingContext())}) {
31213118
if (procChars->HasExplicitInterface()) {
31223119
auto reasons{semantics::CheckExplicitInterface(*procChars, arguments,
3123-
context_, &scope, /*intrinsic=*/nullptr,
3120+
context_, /*scope=*/nullptr, /*intrinsic=*/nullptr,
31243121
/*allocActualArgumentConversions=*/false,
31253122
/*extentErrors=*/false,
31263123
/*ignoreImplicitVsExplicit=*/false)};

flang/test/Semantics/bug2131.cuf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
!RUN: %python %S/test_errors.py %s %flang_fc1 -x cuda
2+
module m
3+
interface randomNumber
4+
module procedure rngScalar, rngArray
5+
end interface
6+
integer :: host_n = 3
7+
contains
8+
attributes(device) function rngScalar() result(res)
9+
real :: res
10+
res = 123.
11+
end
12+
attributes(device) function rngArray(n) result(res)
13+
integer, intent(in) :: n
14+
real :: res(n)
15+
res = 123.
16+
end
17+
attributes(device) function randomPointInUnitSphere() result(res)
18+
real :: res(3)
19+
integer :: n
20+
res = randomNumber(3) ! ok, constant
21+
n = 3
22+
res = randomNumber(n) ! ok, local
23+
!ERROR: No specific function of generic 'randomnumber' matches the actual arguments
24+
res = randomNumber(host_n)
25+
end
26+
end

0 commit comments

Comments
 (0)