Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 4d4ec95

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:cf670d5e56d1 into amd-gfx:917468d90022
Local branch amd-gfx 917468d Merged main:122064a6303e into amd-gfx:ba5461f13b4c Remote branch main cf670d5 [flang][openacc] Accept scalar integer expression in the if clause (llvm#69381)
2 parents 917468d + cf670d5 commit 4d4ec95

File tree

64 files changed

+1315
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1315
-604
lines changed

flang/docs/OpenACC.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ local:
2121
* `!$acc end loop` does not trigger a parsing error and is just ignored.
2222
* The restriction on `!$acc data` required clauses is emitted as a portability
2323
warning instead of an error as other compiler accepts it.
24+
* The `if` clause accepts scalar integer expression in addition to scalar
25+
logical expression.

flang/lib/Semantics/check-acc-structure.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ CHECK_SIMPLE_CLAUSE(DeviceNum, ACCC_device_num)
376376
CHECK_SIMPLE_CLAUSE(Finalize, ACCC_finalize)
377377
CHECK_SIMPLE_CLAUSE(Firstprivate, ACCC_firstprivate)
378378
CHECK_SIMPLE_CLAUSE(Host, ACCC_host)
379-
CHECK_SIMPLE_CLAUSE(If, ACCC_if)
380379
CHECK_SIMPLE_CLAUSE(IfPresent, ACCC_if_present)
381380
CHECK_SIMPLE_CLAUSE(Independent, ACCC_independent)
382381
CHECK_SIMPLE_CLAUSE(NoCreate, ACCC_no_create)
@@ -660,6 +659,20 @@ void AccStructureChecker::Enter(const parser::AccClause::Link &x) {
660659
CheckMultipleOccurrenceInDeclare(x.v, llvm::acc::Clause::ACCC_link);
661660
}
662661

662+
void AccStructureChecker::Enter(const parser::AccClause::If &x) {
663+
CheckAllowed(llvm::acc::Clause::ACCC_if);
664+
if (const auto *expr{GetExpr(x.v)}) {
665+
if (auto type{expr->GetType()}) {
666+
if (type->category() == TypeCategory::Integer ||
667+
type->category() == TypeCategory::Logical) {
668+
return; // LOGICAL and INTEGER type supported for the if clause.
669+
}
670+
}
671+
}
672+
context_.Say(
673+
GetContext().clauseSource, "Must have LOGICAL or INTEGER type"_err_en_US);
674+
}
675+
663676
void AccStructureChecker::Enter(const parser::Module &) {
664677
declareSymbols.clear();
665678
}

flang/test/Fir/invalid.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ func.func @bad_array_modify(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %
690690
func.func @slice_must_be_integral() {
691691
%0 = arith.constant 42 : i32
692692
%1 = fir.field_index field, !fir.type<t(param:i32){field:i32}> (%0 : i32)
693-
// expected-error@+1 {{'fir.slice' op operand #0 must be any integer, but got '!fir.field'}}
693+
// expected-error@+1 {{'fir.slice' op operand #0 must be variadic of any integer, but got '!fir.field'}}
694694
%2 = fir.slice %1, %1, %1 : (!fir.field, !fir.field, !fir.field) -> !fir.slice<1>
695695
return
696696
}

flang/test/HLFIR/invalid.fir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,15 @@ func.func @bad_concat(%arg0: !fir.ref<!fir.char<1,10>>, %arg1: !fir.ref<!fir.cha
267267
// -----
268268
func.func @bad_concat_2(%arg0: !fir.ref<!fir.array<100x!fir.char<1,10>>>, %arg1: !fir.ref<!fir.array<100x!fir.char<1,20>>>) {
269269
%c30 = arith.constant 30 : index
270-
// expected-error@+1 {{'hlfir.concat' op operand #0 must be any character scalar type, but got '!fir.ref<!fir.array<100x!fir.char<1,10>>>'}}
270+
// expected-error@+1 {{'hlfir.concat' op operand #0 must be variadic of any character scalar type, but got '!fir.ref<!fir.array<100x!fir.char<1,10>>>'}}
271271
%0 = hlfir.concat %arg0, %arg1 len %c30 : (!fir.ref<!fir.array<100x!fir.char<1,10>>>, !fir.ref<!fir.array<100x!fir.char<1,20>>>, index) -> (!hlfir.expr<100x!fir.char<1,30>>)
272272
return
273273
}
274274

275275
// -----
276276
func.func @bad_concat_3(%arg0: !fir.ref<!fir.char<1,10>>, %arg1: !fir.ref<i32>) {
277277
%c30 = arith.constant 30 : index
278-
// expected-error@+1 {{'hlfir.concat' op operand #1 must be any character scalar type, but got '!fir.ref<i32>'}}
278+
// expected-error@+1 {{'hlfir.concat' op operand #1 must be variadic of any character scalar type, but got '!fir.ref<i32>'}}
279279
%0 = hlfir.concat %arg0, %arg1 len %c30 : (!fir.ref<!fir.char<1,10>>, !fir.ref<i32>, index) -> (!hlfir.expr<!fir.char<1,30>>)
280280
return
281281
}

flang/test/Lower/OpenACC/acc-init.f90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
subroutine acc_init
77
logical :: ifCondition = .TRUE.
8+
integer :: ifInt = 1
89

910
!$acc init
1011
!CHECK: acc.init{{ *}}{{$}}
@@ -28,4 +29,9 @@ subroutine acc_init
2829
!CHECK: [[DEVTYPE2:%.*]] = arith.constant 2 : i32
2930
!CHECK: acc.init device_type([[DEVTYPE1]], [[DEVTYPE2]] : i32, i32) device_num([[DEVNUM]] : i32){{$}}
3031

32+
!$acc init if(ifInt)
33+
!CHECK: %[[IFINT:.*]] = fir.load %{{.*}} : !fir.ref<i32>
34+
!CHECK: %[[CONV:.*]] = fir.convert %[[IFINT]] : (i32) -> i1
35+
!CHECK: acc.init if(%[[CONV]])
36+
3137
end subroutine acc_init

flang/test/Semantics/OpenACC/acc-init-validity.f90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ program openacc_init_validity
1010
integer :: i, j
1111
integer, parameter :: N = 256
1212
logical :: ifCondition = .TRUE.
13+
integer :: ifInt
14+
real :: ifReal
1315
real(8), dimension(N) :: a
1416

1517
!$acc init
1618
!$acc init if(.TRUE.)
1719
!$acc init if(ifCondition)
20+
!$acc init if(ifInt)
1821
!$acc init device_num(1)
1922
!$acc init device_num(i)
2023
!$acc init device_type(i)
@@ -93,4 +96,7 @@ program openacc_init_validity
9396
!ERROR: At most one DEVICE_TYPE clause can appear on the INIT directive
9497
!$acc init device_type(2) device_type(i, j)
9598

99+
!ERROR: Must have LOGICAL or INTEGER type
100+
!$acc init if(ifReal)
101+
96102
end program openacc_init_validity

lld/ELF/Driver.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,24 +2248,6 @@ static void replaceCommonSymbols() {
22482248
}
22492249
}
22502250

2251-
// If all references to a DSO happen to be weak, the DSO is not added to
2252-
// DT_NEEDED. If that happens, replace ShardSymbol with Undefined to avoid
2253-
// dangling references to an unneeded DSO. Use a weak binding to avoid
2254-
// --no-allow-shlib-undefined diagnostics. Similarly, demote lazy symbols.
2255-
static void demoteSharedAndLazySymbols() {
2256-
llvm::TimeTraceScope timeScope("Demote shared and lazy symbols");
2257-
for (Symbol *sym : symtab.getSymbols()) {
2258-
auto *s = dyn_cast<SharedSymbol>(sym);
2259-
if (!(s && !cast<SharedFile>(s->file)->isNeeded) && !sym->isLazy())
2260-
continue;
2261-
2262-
uint8_t binding = sym->isLazy() ? sym->binding : uint8_t(STB_WEAK);
2263-
Undefined(nullptr, sym->getName(), binding, sym->stOther, sym->type)
2264-
.overwrite(*sym);
2265-
sym->versionId = VER_NDX_GLOBAL;
2266-
}
2267-
}
2268-
22692251
// The section referred to by `s` is considered address-significant. Set the
22702252
// keepUnique flag on the section if appropriate.
22712253
static void markAddrsig(Symbol *s) {
@@ -3023,7 +3005,6 @@ void LinkerDriver::link(opt::InputArgList &args) {
30233005

30243006
// Garbage collection and removal of shared symbols from unused shared objects.
30253007
invokeELFT(markLive,);
3026-
demoteSharedAndLazySymbols();
30273008

30283009
// Make copies of any input sections that need to be copied into each
30293010
// partition.

lld/ELF/LinkerScript.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ void LinkerScript::processSectionCommands() {
613613
discard(*s);
614614
discardSynthetic(*osec);
615615
osec->commands.clear();
616+
seenDiscard = true;
616617
return false;
617618
}
618619

lld/ELF/LinkerScript.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ class LinkerScript final {
356356

357357
bool hasSectionsCommand = false;
358358
bool seenDataAlign = false;
359+
bool seenDiscard = false;
359360
bool seenRelroEnd = false;
360361
bool errorOnMissingSection = false;
361362
std::string backwardDotErr;

lld/ELF/MapFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static void writeCref(raw_fd_ostream &os) {
229229
if (isa<SharedSymbol>(sym))
230230
map[sym].insert(file);
231231
if (auto *d = dyn_cast<Defined>(sym))
232-
if (!d->isLocal() && (!d->section || d->section->isLive()))
232+
if (!d->isLocal())
233233
map[d].insert(file);
234234
}
235235
}

0 commit comments

Comments
 (0)