[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73077 >From 94069d442fd703051bef0244e8c663c1390cadbb Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Wed, 22 Nov 2023 11:06:00 +0800 Subject: [PATCH] [clang][Sema] Add -Wswitch-default warning option Adds a warning, issued by the clang semantic analysis. The patch warns on switch which don't have the default branch. This is a counterpart of gcc's Wswitch-default. --- clang/include/clang/Basic/DiagnosticGroups.td | 2 +- .../include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaStmt.cpp | 3 +++ clang/test/Sema/switch-default.c| 17 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/switch-default.c diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index ff028bbbf7426..12b11527b3057 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -632,7 +632,7 @@ def ShadowAll : DiagGroup<"shadow-all", [Shadow, ShadowFieldInConstructor, def Shorten64To32 : DiagGroup<"shorten-64-to-32">; def : DiagGroup<"sign-promo">; def SignCompare : DiagGroup<"sign-compare">; -def : DiagGroup<"switch-default">; +def SwitchDefault : DiagGroup<"switch-default">; def : DiagGroup<"synth">; def SizeofArrayArgument : DiagGroup<"sizeof-array-argument">; def SizeofArrayDecay : DiagGroup<"sizeof-array-decay">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 990692c06d7d3..d61a34806fc5d 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10044,6 +10044,8 @@ def warn_missing_case : Warning<"%plural{" "3:enumeration values %1, %2, and %3 not handled in switch|" ":%0 enumeration values not handled in switch: %1, %2, %3...}0">, InGroup; +def warn_switch_default : Warning<"'switch' missing 'default' label">, + InGroup, DefaultIgnore; def warn_unannotated_fallthrough : Warning< "unannotated fall-through between switch labels">, diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 2b45aa5dff7be..63348d27a8c94 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1327,6 +1327,9 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, } } + if (!TheDefaultStmt) +Diag(SwitchLoc, diag::warn_switch_default); + if (!HasDependentValue) { // If we don't have a default statement, check whether the // condition is constant. diff --git a/clang/test/Sema/switch-default.c b/clang/test/Sema/switch-default.c new file mode 100644 index 0..3f2e216933033 --- /dev/null +++ b/clang/test/Sema/switch-default.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-default %s + +int f1(int a) { + switch (a) {// expected-warning {{switch missing default case}} +case 1: a++; break; +case 2: a += 2; break; + } + return a; +} + +int f2(int a) { + switch (a) {// no-warning +default: + ; + } + return a; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)
@@ -10044,6 +10044,8 @@ def warn_missing_case : Warning<"%plural{" "3:enumeration values %1, %2, and %3 not handled in switch|" ":%0 enumeration values not handled in switch: %1, %2, %3...}0">, InGroup; +def warn_switch_default : Warning<"switch missing default case">, dongjianqiang2 wrote: Thanks for the correction! https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73077 >From af54d1f1870ba43e18cb3677d171e916f8c887b2 Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Wed, 22 Nov 2023 11:06:00 +0800 Subject: [PATCH] [clang][Sema] Add -Wswitch-default warning option Adds a warning, issued by the clang semantic analysis. The patch warns on switch which don't have the default branch. This is a counterpart of gcc's Wswitch-default. --- clang/include/clang/Basic/DiagnosticGroups.td | 2 +- .../include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaStmt.cpp | 3 +++ clang/test/Sema/switch-default.c| 17 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/switch-default.c diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index ff028bbbf7426..12b11527b3057 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -632,7 +632,7 @@ def ShadowAll : DiagGroup<"shadow-all", [Shadow, ShadowFieldInConstructor, def Shorten64To32 : DiagGroup<"shorten-64-to-32">; def : DiagGroup<"sign-promo">; def SignCompare : DiagGroup<"sign-compare">; -def : DiagGroup<"switch-default">; +def SwitchDefault : DiagGroup<"switch-default">; def : DiagGroup<"synth">; def SizeofArrayArgument : DiagGroup<"sizeof-array-argument">; def SizeofArrayDecay : DiagGroup<"sizeof-array-decay">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 990692c06d7d3..d61a34806fc5d 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10044,6 +10044,8 @@ def warn_missing_case : Warning<"%plural{" "3:enumeration values %1, %2, and %3 not handled in switch|" ":%0 enumeration values not handled in switch: %1, %2, %3...}0">, InGroup; +def warn_switch_default : Warning<"'switch' missing 'default' label">, + InGroup, DefaultIgnore; def warn_unannotated_fallthrough : Warning< "unannotated fall-through between switch labels">, diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 2b45aa5dff7be..63348d27a8c94 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1327,6 +1327,9 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, } } + if (!TheDefaultStmt) +Diag(SwitchLoc, diag::warn_switch_default); + if (!HasDependentValue) { // If we don't have a default statement, check whether the // condition is constant. diff --git a/clang/test/Sema/switch-default.c b/clang/test/Sema/switch-default.c new file mode 100644 index 0..854b561b37c48 --- /dev/null +++ b/clang/test/Sema/switch-default.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-default %s + +int f1(int a) { + switch (a) {// expected-warning {{'switch' missing 'default' label}} +case 1: a++; break; +case 2: a += 2; break; + } + return a; +} + +int f2(int a) { + switch (a) {// no-warning +default: + ; + } + return a; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73077 >From a09d149f050918f6161e5880b4f7e352fc5e52c2 Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Wed, 22 Nov 2023 11:06:00 +0800 Subject: [PATCH] [clang][Sema] Add -Wswitch-default warning option Adds a warning, issued by the clang semantic analysis. The patch warns on switch which don't have the default branch. This is a counterpart of gcc's Wswitch-default. --- clang/docs/ReleaseNotes.rst | 2 ++ clang/include/clang/Basic/DiagnosticGroups.td | 2 +- .../include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaStmt.cpp | 3 +++ clang/test/Sema/switch-default.c| 17 + 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/switch-default.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 157afd9e86291..733971611d1c7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -342,6 +342,8 @@ Improvements to Clang's diagnostics of a base class is not called in the constructor of its derived class. - Clang no longer emits ``-Wmissing-variable-declarations`` for variables declared with the ``register`` storage class. +- Clang's ``-Wswitch-default`` flag now diagnoses whenever a ``switch`` statement + does not have a ``default`` label. - Clang's ``-Wtautological-negation-compare`` flag now diagnoses logical tautologies like ``x && !x`` and ``!x || x`` in expressions. This also makes ``-Winfinite-recursion`` diagnose more cases. diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index ff028bbbf7426..12b11527b3057 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -632,7 +632,7 @@ def ShadowAll : DiagGroup<"shadow-all", [Shadow, ShadowFieldInConstructor, def Shorten64To32 : DiagGroup<"shorten-64-to-32">; def : DiagGroup<"sign-promo">; def SignCompare : DiagGroup<"sign-compare">; -def : DiagGroup<"switch-default">; +def SwitchDefault : DiagGroup<"switch-default">; def : DiagGroup<"synth">; def SizeofArrayArgument : DiagGroup<"sizeof-array-argument">; def SizeofArrayDecay : DiagGroup<"sizeof-array-decay">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 990692c06d7d3..d61a34806fc5d 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10044,6 +10044,8 @@ def warn_missing_case : Warning<"%plural{" "3:enumeration values %1, %2, and %3 not handled in switch|" ":%0 enumeration values not handled in switch: %1, %2, %3...}0">, InGroup; +def warn_switch_default : Warning<"'switch' missing 'default' label">, + InGroup, DefaultIgnore; def warn_unannotated_fallthrough : Warning< "unannotated fall-through between switch labels">, diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 2b45aa5dff7be..63348d27a8c94 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1327,6 +1327,9 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, } } + if (!TheDefaultStmt) +Diag(SwitchLoc, diag::warn_switch_default); + if (!HasDependentValue) { // If we don't have a default statement, check whether the // condition is constant. diff --git a/clang/test/Sema/switch-default.c b/clang/test/Sema/switch-default.c new file mode 100644 index 0..854b561b37c48 --- /dev/null +++ b/clang/test/Sema/switch-default.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-default %s + +int f1(int a) { + switch (a) {// expected-warning {{'switch' missing 'default' label}} +case 1: a++; break; +case 2: a += 2; break; + } + return a; +} + +int f2(int a) { + switch (a) {// no-warning +default: + ; + } + return a; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73223 >From 438da675d853e0b1bc38670c18361d7d3615f860 Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Thu, 23 Nov 2023 16:58:11 +0800 Subject: [PATCH] [Driver][MachineOutliner] Support outlining option with LTO for aarch64_be This patch propagates the -moutline option when target is aarch64_be, fix warning: 'aarch64_be' does not support '-moutline'; flag ignored [-Woption-ignored] --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 4 +--- clang/test/Driver/aarch64-outliner.c | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 1f31c6395206e..4dc471ddc098f 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -2398,9 +2398,7 @@ void tools::addMachineOutlinerArgs(const Driver &D, // We only support -moutline in AArch64 and ARM targets right now. If // we're not compiling for these, emit a warning and ignore the flag. // Otherwise, add the proper mllvm flags. - if (!(Triple.isARM() || Triple.isThumb() || -Triple.getArch() == llvm::Triple::aarch64 || -Triple.getArch() == llvm::Triple::aarch64_32)) { + if (!(Triple.isARM() || Triple.isThumb() || Triple.isAArch64())) { D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName(); } else { addArg(Twine("-enable-machine-outliner")); diff --git a/clang/test/Driver/aarch64-outliner.c b/clang/test/Driver/aarch64-outliner.c index 42e43b433e282..06e5de11ec49e 100644 --- a/clang/test/Driver/aarch64-outliner.c +++ b/clang/test/Driver/aarch64-outliner.c @@ -1,7 +1,9 @@ // REQUIRES: aarch64-registered-target // RUN: %clang --target=aarch64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON +// RUN: %clang --target=aarch64_be -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON // ON: "-mllvm" "-enable-machine-outliner" // RUN: %clang --target=aarch64 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF +// RUN: %clang --target=aarch64_be -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF // OFF: "-mllvm" "-enable-machine-outliner=never" // RUN: %clang --target=x86_64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=WARN // WARN: warning: 'x86_64' does not support '-moutline'; flag ignored [-Woption-ignored] ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)
@@ -2400,7 +2400,8 @@ void tools::addMachineOutlinerArgs(const Driver &D, // Otherwise, add the proper mllvm flags. if (!(Triple.isARM() || Triple.isThumb() || Triple.getArch() == llvm::Triple::aarch64 || dongjianqiang2 wrote: Updated, thanks. https://github.com/llvm/llvm-project/pull/73223 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)
https://github.com/dongjianqiang2 created https://github.com/llvm/llvm-project/pull/72781 clang splits -export-dynamic into "-e" and "xport-dynamic", and gets ld warning: cannot find entry symbol xport-dynamic; defaulting to , which is unexpected from user. Adjust the driver to support -export-dynamic, which can match GCC behavior. >From 4eb84135489b28f3b06085693dc79928b7b7e3ff Mon Sep 17 00:00:00 2001 From: Dong JianQiang Date: Sun, 19 Nov 2023 11:23:31 +0800 Subject: [PATCH] [Driver] Add support for -export-dynamic which can match GCC behavior. clang splits -export-dynamic into "-e" and "xport-dynamic", and gets ld warning: cannot find entry symbol xport-dynamic; defaulting to , which is unexpected from user. Adjust the driver to support -export-dynamic, which can match GCC behavior. --- clang/include/clang/Driver/Options.td | 1 + clang/test/Driver/dynamic-linker.c| 6 ++ 2 files changed, 7 insertions(+) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index df12ba8fbcb296a..3bb764a1e46ab8a 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1453,6 +1453,7 @@ def extract_api_ignores_EQ: CommaJoined<["--"], "extract-api-ignores=">, HelpText<"Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.">, MarshallingInfoStringVector>; def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group; +def export_dynamic : Flag<["-"], "export-dynamic">, Flags<[LinkerInput]>, Group; def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">, diff --git a/clang/test/Driver/dynamic-linker.c b/clang/test/Driver/dynamic-linker.c index 978907e0adee697..d202f537b44fb98 100644 --- a/clang/test/Driver/dynamic-linker.c +++ b/clang/test/Driver/dynamic-linker.c @@ -23,6 +23,12 @@ // RUN: %clang -target powerpc64-unknown-linux-gnu -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s // RUN: %clang -target x86_64-unknown-linux-gnu -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s +// RUN: %clang -target armv7-unknown-linux-gnueabi -### -export-dynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s +// RUN: %clang -target i386-unknown-linux-gnu -### -export-dynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s +// RUN: %clang -target mips64-unknown-linux-gnu -### -export-dynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s +// RUN: %clang -target powerpc64-unknown-linux-gnu -### -export-dynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s +// RUN: %clang -target x86_64-unknown-linux-gnu -### -export-dynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s + // CHECK-SHARED: "-shared" // CHECK-RDYNAMIC: "-export-dynamic" // CHECK-STATIC: "-{{B?}}static" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)
https://github.com/dongjianqiang2 closed https://github.com/llvm/llvm-project/pull/72781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)
dongjianqiang2 wrote: > GCC's default spec file for Linux does not say how `-export-dynamic` > translates to ld `-export-dynamic`. > > I think ld `--export-dynamic` is exclusively caused by `-Wl,--export-dynamic` > or `-rdynamic`. Do you have any example of `gcc -export-dynamic` uses? > > > clang splits -export-dynamic into "-e" and "xport-dynamic" > > This behavior simulates GCC but the uses seem extremely rare or not used at > all. We probably should just reject `-exxx`: #72804 https://github.com/llvm/llvm-project/pull/72781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)
https://github.com/dongjianqiang2 reopened https://github.com/llvm/llvm-project/pull/72781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)
dongjianqiang2 wrote: @MaskRay the reason for adding this option is that gcc supports it. please refer to https://godbolt.org/z/54sE6zTa1 https://github.com/llvm/llvm-project/pull/72781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)
dongjianqiang2 wrote: > > @MaskRay the reason for adding this option is that gcc supports it. please > > refer to [godbolt.org/z/54sE6zTa1](https://godbolt.org/z/54sE6zTa1) > > This doesn't answer my question. GCC has a lot of options that Clang doesn't > support. An option supported by GCC does not mean that Clang needs to support > it. This option has perfect replacement, which makes it even questionable > (since to the best of my knowledge `-export-dynamic` driver option is not > used) See my previous comment: > > > GCC's default spec file for Linux does not say how -export-dynamic > > translates to ld -export-dynamic. > > I think ld --export-dynamic is exclusively caused by -Wl,--export-dynamic > > or -rdynamic. > > Do you have any example of gcc -export-dynamic uses? This is historically undocumented option. and yes, it can be repalced by -rdynamic. See [PR47390](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47390). The purpose of this pull request is to ensure consistency between the two compilers. If you think it's unnecessary to support it, I'm fine with it. : ) https://github.com/llvm/llvm-project/pull/72781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Default Generic_GCC aarch64_be to -fasynchronous-unwind-tables (PR #72971)
https://github.com/dongjianqiang2 created https://github.com/llvm/llvm-project/pull/72971 This patch defaults Generic_GCC aarch64_be to use -fasynchronous-unwind-tables and ensures consistent behavior with aarch64 little endian. >From f8adcd49a4627926ac8009c595c6b0103589e600 Mon Sep 17 00:00:00 2001 From: Dong JianQiang Date: Tue, 21 Nov 2023 16:15:52 +0800 Subject: [PATCH] [Driver] Default Generic_GCC aarch64_be to -fasynchronous-unwind-tables This patch defaults Generic_GCC aarch64_be to use -fasynchronous-unwind-tables. --- clang/lib/Driver/ToolChains/Gnu.cpp | 1 + clang/test/Driver/aarch64-features.c | 1 + 2 files changed, 2 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 2b1e8f02cf66388..782618236ff8982 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2937,6 +2937,7 @@ ToolChain::UnwindTableLevel Generic_GCC::getDefaultUnwindTableLevel(const ArgList &Args) const { switch (getArch()) { case llvm::Triple::aarch64: + case llvm::Triple::aarch64_be: case llvm::Triple::ppc: case llvm::Triple::ppcle: case llvm::Triple::ppc64: diff --git a/clang/test/Driver/aarch64-features.c b/clang/test/Driver/aarch64-features.c index a797cc0cf9084c2..d2075c91314a8b2 100644 --- a/clang/test/Driver/aarch64-features.c +++ b/clang/test/Driver/aarch64-features.c @@ -1,4 +1,5 @@ // RUN: %clang --target=aarch64-none-linux-gnu -### %s -fsyntax-only 2>&1 | FileCheck %s +// RUN: %clang --target=aarch64_be-none-linux-gnu -### %s -fsyntax-only 2>&1 | FileCheck %s // RUN: %clang --target=arm64-none-linux-gnu -### %s -fsyntax-only 2>&1 | FileCheck %s // CHECK: "-funwind-tables=2" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)
https://github.com/dongjianqiang2 created https://github.com/llvm/llvm-project/pull/73077 Adds a warning, issued by the clang semantic analysis. The patch warns on switch which don't have the default branch. This is a counterpart of gcc's Wswitch-default. >From 7962e1ffc6bb5ab8873f391f5030199ba62c1345 Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Wed, 22 Nov 2023 11:06:00 +0800 Subject: [PATCH] [clang][Sema] Add -Wswitch-default warning option Adds a warning, issued by the clang semantic analysis. The patch warns on switch which don't have the default branch. This is a counterpart of gcc's Wswitch-default. --- clang/include/clang/Basic/DiagnosticGroups.td | 2 +- .../include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaStmt.cpp | 3 +++ clang/test/Sema/switch-default.c| 17 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/switch-default.c diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index ff028bbbf74261e..12b11527b30571a 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -632,7 +632,7 @@ def ShadowAll : DiagGroup<"shadow-all", [Shadow, ShadowFieldInConstructor, def Shorten64To32 : DiagGroup<"shorten-64-to-32">; def : DiagGroup<"sign-promo">; def SignCompare : DiagGroup<"sign-compare">; -def : DiagGroup<"switch-default">; +def SwitchDefault : DiagGroup<"switch-default">; def : DiagGroup<"synth">; def SizeofArrayArgument : DiagGroup<"sizeof-array-argument">; def SizeofArrayDecay : DiagGroup<"sizeof-array-decay">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 990692c06d7d3a8..17c9627910bb6ce 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10044,6 +10044,8 @@ def warn_missing_case : Warning<"%plural{" "3:enumeration values %1, %2, and %3 not handled in switch|" ":%0 enumeration values not handled in switch: %1, %2, %3...}0">, InGroup; +def warn_switch_default : Warning<"switch missing default case">, + InGroup, DefaultIgnore; def warn_unannotated_fallthrough : Warning< "unannotated fall-through between switch labels">, diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 2b45aa5dff7be7c..63348d27a8c94a1 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1327,6 +1327,9 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, } } + if (!TheDefaultStmt) +Diag(SwitchLoc, diag::warn_switch_default); + if (!HasDependentValue) { // If we don't have a default statement, check whether the // condition is constant. diff --git a/clang/test/Sema/switch-default.c b/clang/test/Sema/switch-default.c new file mode 100644 index 000..3f2e21693303378 --- /dev/null +++ b/clang/test/Sema/switch-default.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-default %s + +int f1(int a) { + switch (a) {// expected-warning {{switch missing default case}} +case 1: a++; break; +case 2: a += 2; break; + } + return a; +} + +int f2(int a) { + switch (a) {// no-warning +default: + ; + } + return a; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)
dongjianqiang2 wrote: > There is one clang-tidy check (bugprone-switch-missing-default-case) also for > this feature. Thank you for your reply. It may be a more convenient and straightforward way if can be identified during compile time. On the other hand, it it more compatibile with GCC's hehavior. : ) https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)
dongjianqiang2 wrote: > > > > @MaskRay the reason for adding this option is that gcc supports it. > > > > please refer to > > > > [godbolt.org/z/54sE6zTa1](https://godbolt.org/z/54sE6zTa1) > > > > > > > > > This doesn't answer my question. GCC has a lot of options that Clang > > > doesn't support. An option supported by GCC does not mean that Clang > > > needs to support it. This option has perfect replacement, which makes it > > > even questionable (since to the best of my knowledge `-export-dynamic` > > > driver option is not used) See my previous comment: > > > > GCC's default spec file for Linux does not say how -export-dynamic > > > > translates to ld -export-dynamic. > > > > I think ld --export-dynamic is exclusively caused by > > > > -Wl,--export-dynamic or -rdynamic. > > > > Do you have any example of gcc -export-dynamic uses? > > > > > > This is historically undocumented option. and yes, it can be repalced by > > -rdynamic. See > > [PR47390](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47390). The purpose > > of this pull request is to ensure consistency between the two compilers. If > > you think it's unnecessary to support it, I'm fine with it. : ) > > Thank you for digging this up. So `-export-dynamic` is the only special > `-exxx` option GCC supports. Except this gawk issue (2011) which likely gets > fixed long ago, `gcc -export-dynamic` seems to have no use. This doesn't > justify driver adding an option (that we know is not a good thing) special > case. > > Note that `clang -e xxx` or `clang -exxx` did not work before 2020-07, so > even all `-exxx` `-e xxx` all probably rarely used. We should consider > [#72804 > (comment)](https://github.com/llvm/llvm-project/pull/72804#issuecomment-1820321163) Currently, we are switching to the llvm compiler in embedded system. In some scenarios, the -e option is used to specify the program entry address. gcc supportes both `-e xxx` and `-exxx`, so it may not be a good idea to support '-e xxx' only. So far, I've only encountered this particular -export-dynamic scenario, the program got native exception due to the wrong entry address. When looking back at the logs. I found this warning "cannot find entry symbol xport-dynamic; defaulting to ". https://github.com/llvm/llvm-project/pull/72781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)
https://github.com/dongjianqiang2 created https://github.com/llvm/llvm-project/pull/73223 This patch propagates the -moutline flag when target is aarch64_be, fix warning: 'aarch64_be' does not support '-moutline'; flag ignored [-Woption-ignored] >From 1492725fb3bb60f400264f718972ce249ec3eda8 Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Thu, 23 Nov 2023 16:58:11 +0800 Subject: [PATCH] [Driver][MachineOutliner] Support outlining option with LTO for aarch64_be This patch propagates the -moutline flag when target is aarch64_be, fix warning: 'aarch64_be' does not support '-moutline'; flag ignored [-Woption-ignored] --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 ++- clang/test/Driver/aarch64-outliner.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 5d2cd1959b06925..078f2ff80a21939 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -2436,7 +2436,8 @@ void tools::addMachineOutlinerArgs(const Driver &D, // Otherwise, add the proper mllvm flags. if (!(Triple.isARM() || Triple.isThumb() || Triple.getArch() == llvm::Triple::aarch64 || -Triple.getArch() == llvm::Triple::aarch64_32)) { +Triple.getArch() == llvm::Triple::aarch64_32 || +Triple.getArch() == llvm::Triple::aarch64_be)) { D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName(); } else { addArg(Twine("-enable-machine-outliner")); diff --git a/clang/test/Driver/aarch64-outliner.c b/clang/test/Driver/aarch64-outliner.c index 42e43b433e282d3..06e5de11ec49ecd 100644 --- a/clang/test/Driver/aarch64-outliner.c +++ b/clang/test/Driver/aarch64-outliner.c @@ -1,7 +1,9 @@ // REQUIRES: aarch64-registered-target // RUN: %clang --target=aarch64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON +// RUN: %clang --target=aarch64_be -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON // ON: "-mllvm" "-enable-machine-outliner" // RUN: %clang --target=aarch64 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF +// RUN: %clang --target=aarch64_be -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF // OFF: "-mllvm" "-enable-machine-outliner=never" // RUN: %clang --target=x86_64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=WARN // WARN: warning: 'x86_64' does not support '-moutline'; flag ignored [-Woption-ignored] ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)
dongjianqiang2 wrote: > ``` > enum class test > { > err1, > err2, > ok > }; > > int check_err (test v) > { > switch (v) > { > case test::err1: > return 1; > case test::err2: > return 2; > case test::ok: > break; > } > return 0; > } > ``` > > report: main.cxx:40:3: error: 'switch' missing 'default' label > [-Werror,-Wswitch-default] > > how to solve for enum class? try to build libfmt project with > fmt/include/fmt/format.h:3878:3: error: 'switch' missing 'default' label > [-Werror,-Wswitch-default] and other errors Hi, -Wswitch-default is a warning option on switch which don't have the default branch, the option is disabled by default, You can check whether -Wswitch-default is added in the build script. https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)
@@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-default %s + +int f1(int a) { + switch (a) {// expected-warning {{'switch' missing 'default' label}} +case 1: a++; break; +case 2: a += 2; break; + } + return a; +} dongjianqiang2 wrote: See PR([#75900](https://github.com/llvm/llvm-project/pull/75900) ) https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Wswitch-default] Warning for enum even completely covered the cases (PR #75900)
https://github.com/dongjianqiang2 approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/75900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Wswitch-default] Warning for enum even completely covered the cases (PR #75900)
https://github.com/dongjianqiang2 closed https://github.com/llvm/llvm-project/pull/75900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix Wswitch-default bad warning in template (PR #76007)
dongjianqiang2 wrote: thanks for correcting this. https://github.com/llvm/llvm-project/pull/76007 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)
dongjianqiang2 wrote: > export-dynamic In that case, we have got to change `-exxx` to `-e xxx`, and `-export-dynamic` to `-rdynamic`. LGTM, and it follows GCC's official documented spec : ) https://github.com/llvm/llvm-project/pull/72781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Allow -e entry but reject -eentry (PR #72804)
https://github.com/dongjianqiang2 approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/72804 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73223 >From 5742f71b9077a038cfefe4c74290d7e9d2f42d3f Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Thu, 23 Nov 2023 16:58:11 +0800 Subject: [PATCH] [Driver][MachineOutliner] Support outlining option with LTO for aarch64_be This patch propagates the -moutline option when target is aarch64_be, fix warning: 'aarch64_be' does not support '-moutline'; flag ignored [-Woption-ignored] --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 ++- clang/test/Driver/aarch64-outliner.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 5d2cd1959b06925..078f2ff80a21939 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -2436,7 +2436,8 @@ void tools::addMachineOutlinerArgs(const Driver &D, // Otherwise, add the proper mllvm flags. if (!(Triple.isARM() || Triple.isThumb() || Triple.getArch() == llvm::Triple::aarch64 || -Triple.getArch() == llvm::Triple::aarch64_32)) { +Triple.getArch() == llvm::Triple::aarch64_32 || +Triple.getArch() == llvm::Triple::aarch64_be)) { D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName(); } else { addArg(Twine("-enable-machine-outliner")); diff --git a/clang/test/Driver/aarch64-outliner.c b/clang/test/Driver/aarch64-outliner.c index 42e43b433e282d3..06e5de11ec49ecd 100644 --- a/clang/test/Driver/aarch64-outliner.c +++ b/clang/test/Driver/aarch64-outliner.c @@ -1,7 +1,9 @@ // REQUIRES: aarch64-registered-target // RUN: %clang --target=aarch64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON +// RUN: %clang --target=aarch64_be -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON // ON: "-mllvm" "-enable-machine-outliner" // RUN: %clang --target=aarch64 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF +// RUN: %clang --target=aarch64_be -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF // OFF: "-mllvm" "-enable-machine-outliner=never" // RUN: %clang --target=x86_64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=WARN // WARN: warning: 'x86_64' does not support '-moutline'; flag ignored [-Woption-ignored] ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Allow -e entry but reject -eentry (PR #72804)
https://github.com/dongjianqiang2 closed https://github.com/llvm/llvm-project/pull/72804 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73223 >From 2a90faa84bd4a47a291f0631f26b87e7ee60ce63 Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Thu, 23 Nov 2023 16:58:11 +0800 Subject: [PATCH] [Driver][MachineOutliner] Support outlining option with LTO for aarch64_be This patch propagates the -moutline option when target is aarch64_be, fix warning: 'aarch64_be' does not support '-moutline'; flag ignored [-Woption-ignored] --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 ++- clang/test/Driver/aarch64-outliner.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 5d2cd1959b06925..078f2ff80a21939 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -2436,7 +2436,8 @@ void tools::addMachineOutlinerArgs(const Driver &D, // Otherwise, add the proper mllvm flags. if (!(Triple.isARM() || Triple.isThumb() || Triple.getArch() == llvm::Triple::aarch64 || -Triple.getArch() == llvm::Triple::aarch64_32)) { +Triple.getArch() == llvm::Triple::aarch64_32 || +Triple.getArch() == llvm::Triple::aarch64_be)) { D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName(); } else { addArg(Twine("-enable-machine-outliner")); diff --git a/clang/test/Driver/aarch64-outliner.c b/clang/test/Driver/aarch64-outliner.c index 42e43b433e282d3..06e5de11ec49ecd 100644 --- a/clang/test/Driver/aarch64-outliner.c +++ b/clang/test/Driver/aarch64-outliner.c @@ -1,7 +1,9 @@ // REQUIRES: aarch64-registered-target // RUN: %clang --target=aarch64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON +// RUN: %clang --target=aarch64_be -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON // ON: "-mllvm" "-enable-machine-outliner" // RUN: %clang --target=aarch64 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF +// RUN: %clang --target=aarch64_be -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF // OFF: "-mllvm" "-enable-machine-outliner=never" // RUN: %clang --target=x86_64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=WARN // WARN: warning: 'x86_64' does not support '-moutline'; flag ignored [-Woption-ignored] ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73223 >From b58489a05f97dcb6cf31ce9527ff0e7a16a9f56e Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Thu, 23 Nov 2023 16:58:11 +0800 Subject: [PATCH] [Driver][MachineOutliner] Support outlining option with LTO for aarch64_be This patch propagates the -moutline option when target is aarch64_be, fix warning: 'aarch64_be' does not support '-moutline'; flag ignored [-Woption-ignored] --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 ++- clang/test/Driver/aarch64-outliner.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 1f31c6395206ee8..fb92a6dfbc0e26d 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -2400,7 +2400,8 @@ void tools::addMachineOutlinerArgs(const Driver &D, // Otherwise, add the proper mllvm flags. if (!(Triple.isARM() || Triple.isThumb() || Triple.getArch() == llvm::Triple::aarch64 || -Triple.getArch() == llvm::Triple::aarch64_32)) { +Triple.getArch() == llvm::Triple::aarch64_32 || +Triple.getArch() == llvm::Triple::aarch64_be)) { D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName(); } else { addArg(Twine("-enable-machine-outliner")); diff --git a/clang/test/Driver/aarch64-outliner.c b/clang/test/Driver/aarch64-outliner.c index 42e43b433e282d3..06e5de11ec49ecd 100644 --- a/clang/test/Driver/aarch64-outliner.c +++ b/clang/test/Driver/aarch64-outliner.c @@ -1,7 +1,9 @@ // REQUIRES: aarch64-registered-target // RUN: %clang --target=aarch64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON +// RUN: %clang --target=aarch64_be -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=ON // ON: "-mllvm" "-enable-machine-outliner" // RUN: %clang --target=aarch64 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF +// RUN: %clang --target=aarch64_be -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF // OFF: "-mllvm" "-enable-machine-outliner=never" // RUN: %clang --target=x86_64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=WARN // WARN: warning: 'x86_64' does not support '-moutline'; flag ignored [-Woption-ignored] ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)
https://github.com/dongjianqiang2 closed https://github.com/llvm/llvm-project/pull/72781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix Wswitch-default bad warning in template (PR #76007)
https://github.com/dongjianqiang2 approved this pull request. LGTM, thanks https://github.com/llvm/llvm-project/pull/76007 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Add support for -mlong-calls code generation (PR #142982)
dongjianqiang2 wrote: > My understanding is that this will make all calls to global functions into > long calls. > > In AArch64 static linkes are required to insert range extension thunks for > out of range BLs. In the best case this is just another direct branch, at > worst case for `--pic-veneer` this is just `adrp, add, br`. I would expect > that on-demand linker inserted thunks would outperform making all calls long > for the majority of programs. I'm interested in any data that shows that long > calls works better, and whether that could feed back into the lld thunk > generation code. For example are the thunks too far away from the caller > which causes page faults etc. > > I note that with `-ffunction-sections` and certain linker options calls to > static functions can go out of range too. These would get handled by linker > thunks though. This option is explicitly designed to enable reliable patching workflows when compiling object files. It is to guarantee call range safety in patches. When modifying/recompiling individual object files (e.g., during security patches),final memory layouts are unknown at compile time, patched functions might end up >128MB away from callers. -mlong-calls forces all cross-object calls to use 64-bit absolute addressing. https://github.com/llvm/llvm-project/pull/142982 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Add support for -mlong-calls code generation (PR #142982)
dongjianqiang2 wrote: > > > My understanding is that this will make all calls to global functions > > > into long calls. > > > In AArch64 static linkes are required to insert range extension thunks > > > for out of range BLs. In the best case this is just another direct > > > branch, at worst case for `--pic-veneer` this is just `adrp, add, br`. I > > > would expect that on-demand linker inserted thunks would outperform > > > making all calls long for the majority of programs. I'm interested in any > > > data that shows that long calls works better, and whether that could feed > > > back into the lld thunk generation code. For example are the thunks too > > > far away from the caller which causes page faults etc. > > > I note that with `-ffunction-sections` and certain linker options calls > > > to static functions can go out of range too. These would get handled by > > > linker thunks though. > > > > > > This option is explicitly designed to enable reliable patching workflows > > when compiling object files. It is to guarantee call range safety in > > patches. When modifying/recompiling individual object files (e.g., > > during security patches),final memory layouts are unknown at compile > > time, patched functions might end up >128MB away from callers. > > -mlong-calls forces all cross-object calls to use 64-bit absolute > > addressing. > > If I've understood object patching, this would mean inserting a new function > implementation, and binary patching all the call-sites to point to the new > implementation. > > As an aside to this patch. > > I'd be tempted to see if I could indirect all the calls via the PLT. Then > you'd be able add the new function and alter the dynamic symbol table entry > to point to the new implementation and the dynamic linker would do the rest. > That might need some fiddling in the linker or compiler driver to force it to > create a PLT entry, --shared would do it, but for an executable we'd need a > PT_INTERPRET section. > > There was a Discourse thread on ROM Patching for embedded systems > https://discourse.llvm.org/t/rfc-a-user-guided-rom-patching-mechanism-for-embedded-applications/78467 > which had a similar idea. Thanks @smithp35 for your solution! I would like to kindly ask for your expertise in reviewing the following code, which implements backend support for `-mlong-calls` on AArch64 targets. It might not need to be merged, just considering it as an optional approach. Thank you once again for your time and consideration. https://github.com/llvm/llvm-project/pull/142982 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Add support for -mlong-calls code generation (PR #142982)
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/142982 >From cf005a3e475893da88dbee53701edf147997cfff Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Thu, 5 Jun 2025 22:46:26 +0800 Subject: [PATCH] [AArch64] Add support for -mlong-calls code generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements backend support for -mlong-calls on AArch64 targets. When enabled, calls to external functions are lowered to an indirect call via an address computed using `adrp` and `add` rather than a direct `bl` instruction, which is limited to a ±128MB PC-relative offset. This is particularly useful when code and/or data exceeds the 26-bit immediate range of `bl`, such as in large binaries or link-time-optimized builds. Key changes: - In SelectionDAG lowering (`LowerCall`), detect `-mlong-calls` and emit: - `adrp + add` address calculation - `blr` indirect call instruction This patch ensures that long-calls are emitted correctly for both GlobalAddress and ExternalSymbol call targets. Tested: - New codegen tests under `llvm/test/CodeGen/AArch64/aarch64-long-calls.ll` - Verified `adrp + add + blr` output in `.s` for global and external functions --- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 6 +++ llvm/lib/Target/AArch64/AArch64Features.td| 4 ++ .../Target/AArch64/AArch64ISelLowering.cpp| 13 +-- .../AArch64/GISel/AArch64CallLowering.cpp | 11 ++ .../GISel/AArch64InstructionSelector.cpp | 8 .../AArch64/GISel/AArch64LegalizerInfo.cpp| 38 +-- .../AArch64/GISel/AArch64LegalizerInfo.h | 4 +- .../CodeGen/AArch64/aarch64-long-calls.ll | 27 + 8 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 llvm/test/CodeGen/AArch64/aarch64-long-calls.ll diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index eaae9f876e3ad..2463bcdae2f4f 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -466,6 +466,12 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, if (Args.getLastArg(options::OPT_mno_bti_at_return_twice)) Features.push_back("+no-bti-at-return-twice"); + + if (Arg *A = Args.getLastArg(options::OPT_mlong_calls, + options::OPT_mno_long_calls)) { +if (A->getOption().matches(options::OPT_mlong_calls)) + Features.push_back("+long-calls"); + } } void aarch64::setPAuthABIInTriple(const Driver &D, const ArgList &Args, diff --git a/llvm/lib/Target/AArch64/AArch64Features.td b/llvm/lib/Target/AArch64/AArch64Features.td index 469c76752c78c..5af6ed5f1ffa2 100644 --- a/llvm/lib/Target/AArch64/AArch64Features.td +++ b/llvm/lib/Target/AArch64/AArch64Features.td @@ -825,6 +825,10 @@ def FeatureDisableFastIncVL : SubtargetFeature<"disable-fast-inc-vl", "HasDisableFastIncVL", "true", "Do not prefer INC/DEC, ALL, { 1, 2, 4 } over ADDVL">; +def FeatureLongCalls : SubtargetFeature<"long-calls", "GenLongCalls", "true", +"Generate calls via indirect call " +"instructions">; + //===--===// // Architectures. // diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index 9f51caef6d228..d6015ccf94afc 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -9286,8 +9286,12 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI, Callee = DAG.getTargetGlobalAddress(CalledGlobal, DL, PtrVT, 0, OpFlags); Callee = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, Callee); } else { - const GlobalValue *GV = G->getGlobal(); - Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags); + if (Subtarget->genLongCalls()) +Callee = getAddr(G, DAG, OpFlags); + else { +const GlobalValue *GV = G->getGlobal(); +Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags); + } } } else if (auto *S = dyn_cast(Callee)) { bool UseGot = (getTargetMachine().getCodeModel() == CodeModel::Large && @@ -9298,7 +9302,10 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI, Callee = DAG.getTargetExternalSymbol(Sym, PtrVT, AArch64II::MO_GOT); Callee = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, Callee); } else { - Callee = DAG.getTargetExternalSymbol(Sym, PtrVT, 0); + if (Subtarget->genLongCalls()) +Callee = getAddr(S, DAG, 0); + else +Callee = DAG.getTargetExternalSymbol(Sym, PtrVT, 0); } } diff --git a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp b/llvm/lib/Target/AArch64/
[clang] [llvm] [AArch64] Add support for -mlong-calls code generation (PR #142982)
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/142982 >From e828099b2daa6c4f092b7428318fc9b12a85514d Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Thu, 5 Jun 2025 22:46:26 +0800 Subject: [PATCH] [AArch64] Add support for -mlong-calls code generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements backend support for -mlong-calls on AArch64 targets. When enabled, calls to external functions are lowered to an indirect call via an address computed using `adrp` and `add` rather than a direct `bl` instruction, which is limited to a ±128MB PC-relative offset. This is particularly useful when code and/or data exceeds the 26-bit immediate range of `bl`, such as in large binaries or link-time-optimized builds. Key changes: - In SelectionDAG lowering (`LowerCall`), detect `-mlong-calls` and emit: - `adrp + add` address calculation - `blr` indirect call instruction This patch ensures that long-calls are emitted correctly for both GlobalAddress and ExternalSymbol call targets. Tested: - New codegen tests under `llvm/test/CodeGen/AArch64/aarch64-long-calls.ll` - Verified `adrp + add + blr` output in `.s` for global and external functions --- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 6 +++ llvm/lib/Target/AArch64/AArch64Features.td| 4 ++ .../Target/AArch64/AArch64ISelLowering.cpp| 13 +-- .../AArch64/GISel/AArch64CallLowering.cpp | 11 ++ .../GISel/AArch64InstructionSelector.cpp | 9 + .../AArch64/GISel/AArch64LegalizerInfo.cpp| 37 +-- .../AArch64/GISel/AArch64LegalizerInfo.h | 4 +- .../CodeGen/AArch64/aarch64-long-calls.ll | 27 ++ 8 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 llvm/test/CodeGen/AArch64/aarch64-long-calls.ll diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index eaae9f876e3ad..2463bcdae2f4f 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -466,6 +466,12 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, if (Args.getLastArg(options::OPT_mno_bti_at_return_twice)) Features.push_back("+no-bti-at-return-twice"); + + if (Arg *A = Args.getLastArg(options::OPT_mlong_calls, + options::OPT_mno_long_calls)) { +if (A->getOption().matches(options::OPT_mlong_calls)) + Features.push_back("+long-calls"); + } } void aarch64::setPAuthABIInTriple(const Driver &D, const ArgList &Args, diff --git a/llvm/lib/Target/AArch64/AArch64Features.td b/llvm/lib/Target/AArch64/AArch64Features.td index 469c76752c78c..5af6ed5f1ffa2 100644 --- a/llvm/lib/Target/AArch64/AArch64Features.td +++ b/llvm/lib/Target/AArch64/AArch64Features.td @@ -825,6 +825,10 @@ def FeatureDisableFastIncVL : SubtargetFeature<"disable-fast-inc-vl", "HasDisableFastIncVL", "true", "Do not prefer INC/DEC, ALL, { 1, 2, 4 } over ADDVL">; +def FeatureLongCalls : SubtargetFeature<"long-calls", "GenLongCalls", "true", +"Generate calls via indirect call " +"instructions">; + //===--===// // Architectures. // diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index 9f51caef6d228..d6015ccf94afc 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -9286,8 +9286,12 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI, Callee = DAG.getTargetGlobalAddress(CalledGlobal, DL, PtrVT, 0, OpFlags); Callee = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, Callee); } else { - const GlobalValue *GV = G->getGlobal(); - Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags); + if (Subtarget->genLongCalls()) +Callee = getAddr(G, DAG, OpFlags); + else { +const GlobalValue *GV = G->getGlobal(); +Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags); + } } } else if (auto *S = dyn_cast(Callee)) { bool UseGot = (getTargetMachine().getCodeModel() == CodeModel::Large && @@ -9298,7 +9302,10 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI, Callee = DAG.getTargetExternalSymbol(Sym, PtrVT, AArch64II::MO_GOT); Callee = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, Callee); } else { - Callee = DAG.getTargetExternalSymbol(Sym, PtrVT, 0); + if (Subtarget->genLongCalls()) +Callee = getAddr(S, DAG, 0); + else +Callee = DAG.getTargetExternalSymbol(Sym, PtrVT, 0); } } diff --git a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp b/llvm/lib/Target/AArch6
[clang] [llvm] [AArch64] Add support for -mlong-calls code generation (PR #142982)
https://github.com/dongjianqiang2 created https://github.com/llvm/llvm-project/pull/142982 This patch implements backend support for -mlong-calls on AArch64 targets. When enabled, calls to external functions are lowered to an indirect call via an address computed using `adrp` and `add` rather than a direct `bl` instruction, which is limited to a ±128MB PC-relative offset. This is particularly useful when code and/or data exceeds the 26-bit immediate range of `bl`, such as in large binaries or link-time-optimized builds. Key changes: - In SelectionDAG lowering (`LowerCall`), detect `-mlong-calls` and emit: - `adrp + add` address calculation - `blr` indirect call instruction This patch ensures that long-calls are emitted correctly for both GlobalAddress and ExternalSymbol call targets. Tested: - New codegen tests under `llvm/test/CodeGen/AArch64/aarch64-long-calls.ll` - Verified `adrp + add + blr` output in `.s` for global and external functions >From fcf661d89713e589af497b63366ca37db8aad9f9 Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Thu, 5 Jun 2025 22:46:26 +0800 Subject: [PATCH] [AArch64] Add support for -mlong-calls code generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements backend support for -mlong-calls on AArch64 targets. When enabled, calls to external functions are lowered to an indirect call via an address computed using `adrp` and `add` rather than a direct `bl` instruction, which is limited to a ±128MB PC-relative offset. This is particularly useful when code and/or data exceeds the 26-bit immediate range of `bl`, such as in large binaries or link-time-optimized builds. Key changes: - In SelectionDAG lowering (`LowerCall`), detect `-mlong-calls` and emit: - `adrp + add` address calculation - `blr` indirect call instruction This patch ensures that long-calls are emitted correctly for both GlobalAddress and ExternalSymbol call targets. Tested: - New codegen tests under `llvm/test/CodeGen/AArch64/aarch64-long-calls.ll` - Verified `adrp + add + blr` output in `.s` for global and external functions --- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 6 + llvm/lib/Target/AArch64/AArch64Features.td| 4 +++ .../Target/AArch64/AArch64ISelLowering.cpp| 13 +++--- .../CodeGen/AArch64/aarch64-long-calls.ll | 26 +++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 llvm/test/CodeGen/AArch64/aarch64-long-calls.ll diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index eaae9f876e3ad..2463bcdae2f4f 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -466,6 +466,12 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, if (Args.getLastArg(options::OPT_mno_bti_at_return_twice)) Features.push_back("+no-bti-at-return-twice"); + + if (Arg *A = Args.getLastArg(options::OPT_mlong_calls, + options::OPT_mno_long_calls)) { +if (A->getOption().matches(options::OPT_mlong_calls)) + Features.push_back("+long-calls"); + } } void aarch64::setPAuthABIInTriple(const Driver &D, const ArgList &Args, diff --git a/llvm/lib/Target/AArch64/AArch64Features.td b/llvm/lib/Target/AArch64/AArch64Features.td index 469c76752c78c..5af6ed5f1ffa2 100644 --- a/llvm/lib/Target/AArch64/AArch64Features.td +++ b/llvm/lib/Target/AArch64/AArch64Features.td @@ -825,6 +825,10 @@ def FeatureDisableFastIncVL : SubtargetFeature<"disable-fast-inc-vl", "HasDisableFastIncVL", "true", "Do not prefer INC/DEC, ALL, { 1, 2, 4 } over ADDVL">; +def FeatureLongCalls : SubtargetFeature<"long-calls", "GenLongCalls", "true", +"Generate calls via indirect call " +"instructions">; + //===--===// // Architectures. // diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index 9f51caef6d228..d6015ccf94afc 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -9286,8 +9286,12 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI, Callee = DAG.getTargetGlobalAddress(CalledGlobal, DL, PtrVT, 0, OpFlags); Callee = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, Callee); } else { - const GlobalValue *GV = G->getGlobal(); - Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags); + if (Subtarget->genLongCalls()) +Callee = getAddr(G, DAG, OpFlags); + else { +const GlobalValue *GV = G->getGlobal(); +Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags); + } } } else if (auto *S =
[clang] [llvm] [AArch64] Add support for -mlong-calls code generation (PR #142982)
dongjianqiang2 wrote: > -mlong-calls is an old-fashioned compiler option. I think it was added before > linkers knew range extension thunks (aka stubs, veneers, etc). > > Can you use -fno-plt instead? It works with both SelectionDAG and GlobalISel. > You will get GOT-generating code sequence that can be optimized to adrp+add > by the linker. You can use --emit-relocs to get relocations in the > executable. We could implement `__attribute__((noplt))`, if you want the > patching to be per-function. > > The proposed -mlong-calls is -fno-pic hack that works with limited scenarios > with a large performance downside. I don't think we should support it. Yes, we are indeed still using the -mlong-calls option in our older embedded systems. This is necessary due to the lack of support for GOT-based relocation types in these environments. As a result, we have incorporated this option to ensure compatibility and functionality. Moving forward, it's important of adding support in SelectionDAG and GlobalISel for these scenarios. https://github.com/llvm/llvm-project/pull/142982 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits