[PATCH] D123113: [Flang] Add `INTENT` for non-dummy arguments extension nvfortran compiler supports using INTENT attributes for non-dummy arguments. For example, for local variables.
unterumarmung created this revision. Herald added a reviewer: sscalpone. Herald added projects: Flang, All. unterumarmung requested review of this revision. Herald added subscribers: cfe-commits, sstefan1, jdoerfert, MaskRay. Herald added a reviewer: jdoerfert. Herald added a project: clang. This change adds a -fnon-arg-intent flag that enables such behavior in flang. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D123113 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Flang.cpp flang/include/flang/Common/Fortran-features.h flang/lib/Frontend/CompilerInvocation.cpp flang/lib/Semantics/check-declarations.cpp flang/test/Driver/driver-help-hidden.f90 flang/test/Driver/driver-help.f90 flang/test/Driver/frontend-forwarding.f90 flang/test/Semantics/non-arg-intent.f90 Index: flang/test/Semantics/non-arg-intent.f90 === --- /dev/null +++ flang/test/Semantics/non-arg-intent.f90 @@ -0,0 +1,5 @@ +!RUN: %flang_fc1 %s -fnon-arg-intent +function foo() result(res) +integer, intent(out) :: res +procedure(), intent(in) :: p1 +end function foo \ No newline at end of file Index: flang/test/Driver/frontend-forwarding.f90 === --- flang/test/Driver/frontend-forwarding.f90 +++ flang/test/Driver/frontend-forwarding.f90 @@ -7,6 +7,7 @@ ! RUN: -fdefault-integer-8 \ ! RUN: -fdefault-real-8 \ ! RUN: -flarge-sizes \ +! RUN: -fnon-arg-intent \ ! RUN: -mllvm -print-before-all\ ! RUN: -P \ ! RUN: | FileCheck %s @@ -17,4 +18,5 @@ ! CHECK: "-fdefault-integer-8" ! CHECK: "-fdefault-real-8" ! CHECK: "-flarge-sizes" +! CHECK: "-fnon-arg-intent" ! CHECK: "-mllvm" "-print-before-all" Index: flang/test/Driver/driver-help.f90 === --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -42,6 +42,7 @@ ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! HELP-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments ! HELP-NEXT: -fopenacc Enable OpenACC ! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. @@ -115,6 +116,7 @@ ! HELP-FC1-NEXT:Do not use the analyzed objects when unparsing ! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! HELP-FC1-NEXT: -fno-reformat Dump the cooked character stream in -E mode +! HELP-FC1-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments ! HELP-FC1-NEXT: -fopenacc Enable OpenACC ! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. Index: flang/test/Driver/driver-help-hidden.f90 === --- flang/test/Driver/driver-help-hidden.f90 +++ flang/test/Driver/driver-help-hidden.f90 @@ -42,6 +42,7 @@ ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations ! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! CHECK-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments ! CHECK-NEXT: -fopenacc Enable OpenACC ! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. Index: flang/lib/Semantics/check-declarations.cpp === --- flang/lib/Semantics/check-declarations.cpp +++ flang/lib/Semantics/check-declarations.cpp @@ -533,8 +533,10 @@ } else if (symbol.attrs().test(Attr::INTENT_IN) || symbol.attrs().test(Attr::INTENT_OUT) || symbol.attrs().test(Attr::INTENT_INOUT)) { -messages_.Say("INTENT attributes may apply only to a dummy " - "argument"_err_en_US); // C843 +if (!context_.languageFeatures().IsEnabled( +Fortran::common::LanguageFeature::NonDummyArgumentIntent)) + messages_.Say("INTENT attributes may apply only to a dummy " +"argument"_err_en_US); // C843 } else if (IsOptional(symbol)) { messages_.Say("OPTIONAL attribute may apply only to a dummy " "argument"_err_en_US); // C849 @@ -766,8 +768,10 @@ } else if (symbol.attrs().test(Attr::INTENT_IN) || symbol.att
[PATCH] D123113: [Flang] Add `INTENT` for non-dummy arguments extension
unterumarmung updated this revision to Diff 420436. unterumarmung retitled this revision from "[Flang] Add `INTENT` for non-dummy arguments extension nvfortran compiler supports using INTENT attributes for non-dummy arguments. For example, for local variables." to "[Flang] Add `INTENT` for non-dummy arguments extension". unterumarmung edited the summary of this revision. unterumarmung added a comment. Fixed revision description Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123113/new/ https://reviews.llvm.org/D123113 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Flang.cpp flang/include/flang/Common/Fortran-features.h flang/lib/Frontend/CompilerInvocation.cpp flang/lib/Semantics/check-declarations.cpp flang/test/Driver/driver-help-hidden.f90 flang/test/Driver/driver-help.f90 flang/test/Driver/frontend-forwarding.f90 flang/test/Semantics/non-arg-intent.f90 Index: flang/test/Semantics/non-arg-intent.f90 === --- /dev/null +++ flang/test/Semantics/non-arg-intent.f90 @@ -0,0 +1,5 @@ +!RUN: %flang_fc1 %s -fnon-arg-intent +function foo() result(res) +integer, intent(out) :: res +procedure(), intent(in) :: p1 +end function foo \ No newline at end of file Index: flang/test/Driver/frontend-forwarding.f90 === --- flang/test/Driver/frontend-forwarding.f90 +++ flang/test/Driver/frontend-forwarding.f90 @@ -7,6 +7,7 @@ ! RUN: -fdefault-integer-8 \ ! RUN: -fdefault-real-8 \ ! RUN: -flarge-sizes \ +! RUN: -fnon-arg-intent \ ! RUN: -mllvm -print-before-all\ ! RUN: -P \ ! RUN: | FileCheck %s @@ -17,4 +18,5 @@ ! CHECK: "-fdefault-integer-8" ! CHECK: "-fdefault-real-8" ! CHECK: "-flarge-sizes" +! CHECK: "-fnon-arg-intent" ! CHECK: "-mllvm" "-print-before-all" Index: flang/test/Driver/driver-help.f90 === --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -42,6 +42,7 @@ ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! HELP-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments ! HELP-NEXT: -fopenacc Enable OpenACC ! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. @@ -115,6 +116,7 @@ ! HELP-FC1-NEXT:Do not use the analyzed objects when unparsing ! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! HELP-FC1-NEXT: -fno-reformat Dump the cooked character stream in -E mode +! HELP-FC1-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments ! HELP-FC1-NEXT: -fopenacc Enable OpenACC ! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. Index: flang/test/Driver/driver-help-hidden.f90 === --- flang/test/Driver/driver-help-hidden.f90 +++ flang/test/Driver/driver-help-hidden.f90 @@ -42,6 +42,7 @@ ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations ! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! CHECK-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments ! CHECK-NEXT: -fopenacc Enable OpenACC ! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. Index: flang/lib/Semantics/check-declarations.cpp === --- flang/lib/Semantics/check-declarations.cpp +++ flang/lib/Semantics/check-declarations.cpp @@ -533,8 +533,10 @@ } else if (symbol.attrs().test(Attr::INTENT_IN) || symbol.attrs().test(Attr::INTENT_OUT) || symbol.attrs().test(Attr::INTENT_INOUT)) { -messages_.Say("INTENT attributes may apply only to a dummy " - "argument"_err_en_US); // C843 +if (!context_.languageFeatures().IsEnabled( +Fortran::common::LanguageFeature::NonDummyArgumentIntent)) + messages_.Say("INTENT attributes may apply only to a dummy " +"argument"_err_en_US); // C843 } else if (IsOptional(symbol)) { messages_.Say("OPTIONAL attribute may apply only to a dummy "
[PATCH] D123113: [Flang] Add `INTENT` for non-dummy arguments extension
unterumarmung updated this revision to Diff 420437. unterumarmung added a comment. Fixed commit message Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123113/new/ https://reviews.llvm.org/D123113 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Flang.cpp flang/include/flang/Common/Fortran-features.h flang/lib/Frontend/CompilerInvocation.cpp flang/lib/Semantics/check-declarations.cpp flang/test/Driver/driver-help-hidden.f90 flang/test/Driver/driver-help.f90 flang/test/Driver/frontend-forwarding.f90 flang/test/Semantics/non-arg-intent.f90 Index: flang/test/Semantics/non-arg-intent.f90 === --- /dev/null +++ flang/test/Semantics/non-arg-intent.f90 @@ -0,0 +1,5 @@ +!RUN: %flang_fc1 %s -fnon-arg-intent +function foo() result(res) +integer, intent(out) :: res +procedure(), intent(in) :: p1 +end function foo \ No newline at end of file Index: flang/test/Driver/frontend-forwarding.f90 === --- flang/test/Driver/frontend-forwarding.f90 +++ flang/test/Driver/frontend-forwarding.f90 @@ -7,6 +7,7 @@ ! RUN: -fdefault-integer-8 \ ! RUN: -fdefault-real-8 \ ! RUN: -flarge-sizes \ +! RUN: -fnon-arg-intent \ ! RUN: -mllvm -print-before-all\ ! RUN: -P \ ! RUN: | FileCheck %s @@ -17,4 +18,5 @@ ! CHECK: "-fdefault-integer-8" ! CHECK: "-fdefault-real-8" ! CHECK: "-flarge-sizes" +! CHECK: "-fnon-arg-intent" ! CHECK: "-mllvm" "-print-before-all" Index: flang/test/Driver/driver-help.f90 === --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -42,6 +42,7 @@ ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! HELP-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments ! HELP-NEXT: -fopenacc Enable OpenACC ! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. @@ -115,6 +116,7 @@ ! HELP-FC1-NEXT:Do not use the analyzed objects when unparsing ! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! HELP-FC1-NEXT: -fno-reformat Dump the cooked character stream in -E mode +! HELP-FC1-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments ! HELP-FC1-NEXT: -fopenacc Enable OpenACC ! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. Index: flang/test/Driver/driver-help-hidden.f90 === --- flang/test/Driver/driver-help-hidden.f90 +++ flang/test/Driver/driver-help-hidden.f90 @@ -42,6 +42,7 @@ ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations ! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! CHECK-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments ! CHECK-NEXT: -fopenacc Enable OpenACC ! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. Index: flang/lib/Semantics/check-declarations.cpp === --- flang/lib/Semantics/check-declarations.cpp +++ flang/lib/Semantics/check-declarations.cpp @@ -533,8 +533,10 @@ } else if (symbol.attrs().test(Attr::INTENT_IN) || symbol.attrs().test(Attr::INTENT_OUT) || symbol.attrs().test(Attr::INTENT_INOUT)) { -messages_.Say("INTENT attributes may apply only to a dummy " - "argument"_err_en_US); // C843 +if (!context_.languageFeatures().IsEnabled( +Fortran::common::LanguageFeature::NonDummyArgumentIntent)) + messages_.Say("INTENT attributes may apply only to a dummy " +"argument"_err_en_US); // C843 } else if (IsOptional(symbol)) { messages_.Say("OPTIONAL attribute may apply only to a dummy " "argument"_err_en_US); // C849 @@ -766,8 +768,10 @@ } else if (symbol.attrs().test(Attr::INTENT_IN) || symbol.attrs().test(Attr::INTENT_OUT) || symbol.attrs().test(Attr::INTENT_INOUT)) { -messages_.Say("INTENT attributes may apply only to a dummy " - "argument"_err_en_US); // C843 +
[PATCH] D123113: [Flang] Add `INTENT` for non-dummy arguments extension
unterumarmung added a comment. @ekieri, hello! Thank you for the comment, it is really helpful! It turns out that I've researched the issue poorly. Actually, `nvfortran` compiler forbids to use `INTENT` attribute on local variables, even though a "mod" file can be generated. It generates a severe error like the one below and there's no way to ignore the severe errors, if I understand correctly. NVFORTRAN-S-0134-Illegal attribute - intent specified for nondummy argument bar2 (test.f90: 3) But the reason why I filed the patch was that `nvfortran` allows to use any kind of `INTENT` attribute for a local variable that marked as `RESULT` one for a function: function foo() result(bar) integer, intent(out) :: bar end function foo `nvfortran` does not generate any message for this code, not even a warning. So, it looks like a bug in the compiler, not a feature or extension and this should not be supported in flang, I think. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123113/new/ https://reviews.llvm.org/D123113 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D124669: [flang][driver] Add support for -save-temps
unterumarmung added inline comments. Comment at: clang/include/clang/Driver/Options.td:4131 def : Flag<["-"], "no-integrated-as">, Alias, - Flags<[CC1Option, NoXarchOption]>; + Flags<[CC1Option,FlangOption,NoXarchOption]>; Why not to add `FC1Option` here and elsewhere like it's done for `CC1Option`? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124669/new/ https://reviews.llvm.org/D124669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D124669: [flang][driver] Add support for -save-temps
unterumarmung added inline comments. Comment at: clang/include/clang/Driver/Options.td:4131 def : Flag<["-"], "no-integrated-as">, Alias, - Flags<[CC1Option, NoXarchOption]>; + Flags<[CC1Option,FlangOption,NoXarchOption]>; rovka wrote: > awarzynski wrote: > > unterumarmung wrote: > > > Why not to add `FC1Option` here and elsewhere like it's done for > > > `CC1Option`? > > I'm not 100% sure what `-fno-integrated-as` controls in Clang's frontend > > driver, `clang -cc1`. I'm guessing that it might related to using/not-using > > LLVM's MCAsmParser. Perhaps for inline assembly? > > > > In Flang, I'm only focusing on `-save-temps` for which I need to make sure > > that we don't try to call `flang-new -fc1as` or something similar (it does > > not exist). Instead, `-save-temps` will have to rely on an external > > assembler. > > > > So, we basically don't require -`fno-integrated-as` in `flang-new -fc1` > > just yet (that's what `FC1Option` is for - marking an option as available > > in the frontend driver). > I'm not 100% sure either (haven't looked at the code), but my understanding > of `-fno-integrated-as` is that it forces clang to call the system assembler > as opposed to using the LLVM libraries to generate machine code directly. > Since flang never uses the system assembler, I would say the integrated > assembler is always on in flang. So I'm not convinced it makes sense to add > this flag to the driver, unless we're actually adding a > `-fc1as`. @awarzynski @rovka, thank you for the detailed explanation! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124669/new/ https://reviews.llvm.org/D124669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D144135: [clang-tidy] Add performance-enum-size check
unterumarmung added inline comments. Comment at: clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp:127-128 + + diag(MatchedDecl->getLocation(), "enum %0 derive from %1 of size %2 bytes, " + "derive from '%3' to reduce it size to %4") + << MatchedDecl << MatchedDecl->getIntegerType() << Size << NewType.first I find the enum's type derivation message to be a bit unintuitive. It would slightly improve the user experience if the error message provided clearer information, like stating "enum %0 has a base type of %1..." or "the base type of enum %0 appears excessive for its value set...". However, please remember that these are merely personal thoughts, and as a non-contributor, my suggestions are not obligatory. Comment at: clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst:62 +Requires C++11 or above. +Does not provide auto-fixes. + Why not? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D144135/new/ https://reviews.llvm.org/D144135 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits