[flang] Follow up #192674 Add INLINEALWAYS Directive (#194313)

Following some post merge review comments, this updates the work done in
#192674 based on feedback. It fixes some formatting that was not
conforming, fixes Typo's and updates the new warning's for Semantics
checks.
This commit is contained in:
Jack Styles 2026-04-29 08:54:21 +01:00 committed by GitHub
parent 0e513fc667
commit 561a0c5e30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 13 deletions

View file

@ -3569,7 +3569,7 @@ private:
if (currentFunctionUnit && !currentFunctionUnit->isMainProgram()) {
const std::string symName =
currentFunctionUnit->getSubprogramSymbol().name().ToString();
if (dir.v->ToString() == symName) {
if (dir.v.value().ToString() == symName) {
func->setAttr("llvm.always_inline", builder->getUnitAttr());
}
}

View file

@ -1908,11 +1908,11 @@ public:
Word("!DIR$ NOINLINE");
},
[&](const CompilerDirective::IVDep &) { Word("!DIR$ IVDEP"); },
[&](const CompilerDirective::InlineAlways &InlineAlways) {
[&](const CompilerDirective::InlineAlways &inlineAlways) {
Word("!DIR$ INLINEALWAYS");
if (InlineAlways.v.has_value()) {
if (inlineAlways.v.has_value()) {
Word(" ");
Word(InlineAlways.v->ToString());
Word(inlineAlways.v->ToString());
}
},
[&](const CompilerDirective::Simd &) { Word("!DIR$ SIMD"); },

View file

@ -10492,11 +10492,11 @@ void ResolveNamesVisitor::Post(const parser::CompilerDirective &x) {
Symbol *sym{currScope().symbol()};
if (!sym || !sym->has<SubprogramDetails>()) {
Say(x.source,
"!DIR$ INLINEALWAYS directive with name must appear in a subroutine or function"_err_en_US);
}
if (inlineAlways->v->ToString() != sym->name().ToString()) {
"!DIR$ INLINEALWAYS directive with name must appear in a subprogram"_err_en_US);
} else if (inlineAlways->v->ToString() != sym->name().ToString()) {
context().Warn(common::UsageWarning::IgnoredDirective, x.source,
"INLINEALWAYS name does not match the subroutine or function name"_warn_en_US);
"INLINEALWAYS name '%s' does not match the subprogram name '%s'"_warn_en_US,
inlineAlways->v->ToString(), sym->name().ToString());
}
} else if (context().ShouldWarn(common::UsageWarning::IgnoredDirective)) {
Say(x.source, "Unrecognized compiler directive was ignored"_warn_en_US)

View file

@ -23,7 +23,7 @@ end function
function test_func2()
!DIR$ INLINEALWAYS wrong_func
end function
! CHCEK: func.func @_QPtest_func2() -> f32 {
! CHECK: func.func @_QPtest_func2() -> f32 {
integer function test_func3() result(res)
res = 10
@ -40,5 +40,5 @@ subroutine test()
result = 0
!DIR$ INLINEALWAYS
result = test_func3()
! CHCEK: %[[.*]] = fir.call @_QPtest_func3() fastmath<contract> {inline_attr = #fir.inline_attrs<always_inline>} : () -> i32
! CHECK: fir.call @_QPtest_func3() fastmath<contract> {inline_attr = #fir.inline_attrs<always_inline>} : () -> i32
end subroutine

View file

@ -2,16 +2,16 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
module m
! ERROR: !DIR$ INLINEALWAYS directive with name must appear in a subroutine or function
! ERROR: !DIR$ INLINEALWAYS directive with name must appear in a subprogram
!DIR$ INLINEALWAYS m
end module
subroutine test_subroutine()
! WARNING: INLINEALWAYS name does not match the subroutine or function name [-Wignored-directive]
! WARNING: INLINEALWAYS name 'wrong_subroutine' does not match the subprogram name 'test_subroutine' [-Wignored-directive]
!DIR$ INLINEALWAYS wrong_subroutine
end subroutine
function test_func()
! WARNING: INLINEALWAYS name does not match the subroutine or function name [-Wignored-directive]
! WARNING: INLINEALWAYS name 'wrong_func' does not match the subprogram name 'test_func' [-Wignored-directive]
!DIR$ INLINEALWAYS wrong_func
end function