Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2514,6 +2514,16 @@ void OmpAttributeVisitor::ResolveOmpObject(
name->ToString());
}
}
if (ompFlag == Symbol::Flag::OmpDeclareTarget) {
if (symbol->IsFuncResult()) {
if (Symbol * func{currScope().symbol()}) {
assert(
func->IsSubprogram() && "Expecting function scope");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: There is a CHECK macro that is commonly used in frontend code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

func->set(ompFlag);
name->symbol = func;
}
}
}
if (GetContext().directive ==
llvm::omp::Directive::OMPD_target_data) {
checkExclusivelists(symbol, Symbol::Flag::OmpUseDevicePtr,
Expand Down
8 changes: 8 additions & 0 deletions flang/lib/Semantics/unparse-with-symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class SymbolDumpVisitor {
currStmt_ = std::nullopt;
}

bool Pre(const parser::OpenMPDeclareTargetConstruct &x) {
currStmt_ = x.source;
return true;
}
void Post(const parser::OpenMPDeclareTargetConstruct &) {
currStmt_ = std::nullopt;
}

private:
std::optional<SourceName> currStmt_; // current statement we are processing
std::multimap<const char *, const Symbol *> symbols_; // location to symbol
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Lower/OpenMP/declare-target-func-and-subr.f90
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ FUNCTION FUNC_DEFAULT_EXTENDEDLIST() RESULT(I)
I = 1
END FUNCTION FUNC_DEFAULT_EXTENDEDLIST

! ALL-LABEL: func.func @_QPfunc_name_as_result()
! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
FUNCTION FUNC_NAME_AS_RESULT()
!$omp declare target(FUNC_NAME_AS_RESULT)
FUNC_NAME_AS_RESULT = 1.0
END FUNCTION FUNC_NAME_AS_RESULT

!! -----

! Check specification valid forms of declare target with subroutines
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
!RUN: %flang_fc1 -fdebug-unparse-with-symbols -fopenmp %s 2>&1 | FileCheck %s

! This used to crash.

module test
contains
function ex(a, b, c)
!$omp declare target(ex)
integer :: a, b, c
ex = a + b + c
end function ex
end module test

!CHECK: !DEF: /test Module
!CHECK: module test
!CHECK: contains
!CHECK: !DEF: /test/ex PUBLIC (Function, OmpDeclareTarget) Subprogram REAL(4)
!CHECK: !DEF: /test/ex/a ObjectEntity INTEGER(4)
!CHECK: !DEF: /test/ex/b ObjectEntity INTEGER(4)
!CHECK: !DEF: /test/ex/c ObjectEntity INTEGER(4)
!CHECK: function ex(a, b, c)
!CHECK: !$omp declare target (ex)
!CHECK: !REF: /test/ex/a
!CHECK: !REF: /test/ex/b
!CHECK: !REF: /test/ex/c
!CHECK: integer a, b, c
!CHECK: !DEF: /test/ex/ex (Implicit, OmpDeclareTarget) ObjectEntity REAL(4)
!CHECK: !REF: /test/ex/a
!CHECK: !REF: /test/ex/b
!CHECK: !REF: /test/ex/c
!CHECK: ex = a+b+c
!CHECK: end function ex
!CHECK: end module test

Loading