[clang] [Clang] Make `-Wreturn-type` default to an error in all language modes (PR #123470)
Sirraide wrote: Looks like I might have to fix some compiler-rt tests first; that might well end up being another separate pr. https://github.com/llvm/llvm-project/pull/123470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Make `-Wreturn-type` default to an error in all language modes (PR #123470)
https://github.com/Sirraide updated https://github.com/llvm/llvm-project/pull/123470 >From 441385e14210f23a4fe5368d44620073a4347a31 Mon Sep 17 00:00:00 2001 From: Sirraide Date: Sat, 18 Jan 2025 19:35:01 +0100 Subject: [PATCH 1/2] [Clang] Make -Wreturn-type default to an error in all language modes --- clang/docs/ReleaseNotes.rst | 4 clang/include/clang/Basic/DiagnosticSemaKinds.td | 12 ++-- clang/test/Index/warning-flags.c | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index aa1c02d04f7caa..a086c443984408 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -81,6 +81,10 @@ code bases. ``-fno-strict-overflow`` to opt-in to a language dialect where signed integer and pointer overflow are well-defined. +- ``-Wreturn-type`` now defaults to an error in all language modes; like other + warnings, it can be reverted to just being a warning by specifying + ``-Wno-error=return-type``. + C/C++ Language Potentially Breaking Changes --- diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index db54312ad965e8..b70d152781a2a8 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -709,10 +709,10 @@ def err_thread_unsupported : Error< // FIXME: Combine fallout warnings to just one warning. def warn_maybe_falloff_nonvoid_function : Warning< "non-void function does not return a value in all control paths">, - InGroup; + InGroup, DefaultError; def warn_falloff_nonvoid_function : Warning< "non-void function does not return a value">, - InGroup; + InGroup, DefaultError; def warn_const_attr_with_pure_attr : Warning< "'const' attribute imposes more restrictions; 'pure' attribute ignored">, InGroup; @@ -726,10 +726,10 @@ def err_falloff_nonvoid_block : Error< "non-void block does not return a value">; def warn_maybe_falloff_nonvoid_coroutine : Warning< "non-void coroutine does not return a value in all control paths">, - InGroup; + InGroup, DefaultError; def warn_falloff_nonvoid_coroutine : Warning< "non-void coroutine does not return a value">, - InGroup; + InGroup, DefaultError; def warn_suggest_noreturn_function : Warning< "%select{function|method}0 %1 could be declared with attribute 'noreturn'">, InGroup, DefaultIgnore; @@ -8365,10 +8365,10 @@ let CategoryName = "Lambda Issue" in { "lambda declared 'noreturn' should not return">; def warn_maybe_falloff_nonvoid_lambda : Warning< "non-void lambda does not return a value in all control paths">, -InGroup; +InGroup, DefaultError; def warn_falloff_nonvoid_lambda : Warning< "non-void lambda does not return a value">, -InGroup; +InGroup, DefaultError; def err_access_lambda_capture : Error< // The ERRORs represent other special members that aren't constructors, in // hopes that someone will bother noticing and reporting if they appear diff --git a/clang/test/Index/warning-flags.c b/clang/test/Index/warning-flags.c index 1694c6abab5624..3229f000c4ae0c 100644 --- a/clang/test/Index/warning-flags.c +++ b/clang/test/Index/warning-flags.c @@ -9,7 +9,7 @@ int *bar(float *f) { return f; } // RUN: c-index-test -test-load-source-reparse 5 all -w %s 2>&1 | FileCheck -check-prefix=NOWARNINGS %s // RUN: c-index-test -test-load-source all -w -O4 %s 2>&1 | FileCheck -check-prefix=NOWARNINGS %s -// CHECK-BOTH-WARNINGS: warning: non-void function does not return a value +// CHECK-BOTH-WARNINGS: error: non-void function does not return a value // CHECK-BOTH-WARNINGS: warning: incompatible pointer types returning 'float *' from a function with result type 'int *' // CHECK-SECOND-WARNING-NOT:non-void function does not return a value >From 5200de410b12463a7c8ba7fdbb75e9156f2cb116 Mon Sep 17 00:00:00 2001 From: Sirraide Date: Sat, 18 Jan 2025 21:43:37 +0100 Subject: [PATCH 2/2] Fix two tests --- clang/test/CodeGen/armv7k-abi.c| 10 +- clang/test/CodeGenOpenCL/atomics-cas-remarks-gfx90a.cl | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/test/CodeGen/armv7k-abi.c b/clang/test/CodeGen/armv7k-abi.c index fd18dafa7d03f5..872e6423a4a992 100644 --- a/clang/test/CodeGen/armv7k-abi.c +++ b/clang/test/CodeGen/armv7k-abi.c @@ -16,7 +16,7 @@ typedef struct { void simple_hfa(HFA h) {} // CHECK: define{{.*}} %struct.HFA @return_simple_hfa -HFA return_simple_hfa() {} +HFA return_simple_hfa() { return (HFA){0}; } typedef struct { double arr[4]; @@ -43,7 +43,7 @@ typedef struct { void big_struct_indirect(BigStruct b) {} // CHECK: define{{.*}} void @return_big_struct_indirect(ptr dead_on_unwind noalias writable sret -BigStruct return_big_struct_indirect() {} +BigStruct return_big_struct_indirect()
[clang] [Clang] Make `-Wreturn-type` default to an error in all language modes (PR #123470)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (Sirraide) Changes This makes `-Wreturn-type` default to an error in all language modes as there is basically never a reason as to why one would *want* to fall off the end of a non-void function. Most of the tedious work of migrating the tests was done in #123464 (except for one test that for some reason didn’t want to cooperate earlier, which is why that one is handled in this pr). --- Full diff: https://github.com/llvm/llvm-project/pull/123470.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+4) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+6-6) - (modified) clang/test/Index/warning-flags.c (+1-1) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index aa1c02d04f7caa..a086c443984408 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -81,6 +81,10 @@ code bases. ``-fno-strict-overflow`` to opt-in to a language dialect where signed integer and pointer overflow are well-defined. +- ``-Wreturn-type`` now defaults to an error in all language modes; like other + warnings, it can be reverted to just being a warning by specifying + ``-Wno-error=return-type``. + C/C++ Language Potentially Breaking Changes --- diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index db54312ad965e8..b70d152781a2a8 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -709,10 +709,10 @@ def err_thread_unsupported : Error< // FIXME: Combine fallout warnings to just one warning. def warn_maybe_falloff_nonvoid_function : Warning< "non-void function does not return a value in all control paths">, - InGroup; + InGroup, DefaultError; def warn_falloff_nonvoid_function : Warning< "non-void function does not return a value">, - InGroup; + InGroup, DefaultError; def warn_const_attr_with_pure_attr : Warning< "'const' attribute imposes more restrictions; 'pure' attribute ignored">, InGroup; @@ -726,10 +726,10 @@ def err_falloff_nonvoid_block : Error< "non-void block does not return a value">; def warn_maybe_falloff_nonvoid_coroutine : Warning< "non-void coroutine does not return a value in all control paths">, - InGroup; + InGroup, DefaultError; def warn_falloff_nonvoid_coroutine : Warning< "non-void coroutine does not return a value">, - InGroup; + InGroup, DefaultError; def warn_suggest_noreturn_function : Warning< "%select{function|method}0 %1 could be declared with attribute 'noreturn'">, InGroup, DefaultIgnore; @@ -8365,10 +8365,10 @@ let CategoryName = "Lambda Issue" in { "lambda declared 'noreturn' should not return">; def warn_maybe_falloff_nonvoid_lambda : Warning< "non-void lambda does not return a value in all control paths">, -InGroup; +InGroup, DefaultError; def warn_falloff_nonvoid_lambda : Warning< "non-void lambda does not return a value">, -InGroup; +InGroup, DefaultError; def err_access_lambda_capture : Error< // The ERRORs represent other special members that aren't constructors, in // hopes that someone will bother noticing and reporting if they appear diff --git a/clang/test/Index/warning-flags.c b/clang/test/Index/warning-flags.c index 1694c6abab5624..3229f000c4ae0c 100644 --- a/clang/test/Index/warning-flags.c +++ b/clang/test/Index/warning-flags.c @@ -9,7 +9,7 @@ int *bar(float *f) { return f; } // RUN: c-index-test -test-load-source-reparse 5 all -w %s 2>&1 | FileCheck -check-prefix=NOWARNINGS %s // RUN: c-index-test -test-load-source all -w -O4 %s 2>&1 | FileCheck -check-prefix=NOWARNINGS %s -// CHECK-BOTH-WARNINGS: warning: non-void function does not return a value +// CHECK-BOTH-WARNINGS: error: non-void function does not return a value // CHECK-BOTH-WARNINGS: warning: incompatible pointer types returning 'float *' from a function with result type 'int *' // CHECK-SECOND-WARNING-NOT:non-void function does not return a value `` https://github.com/llvm/llvm-project/pull/123470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Make `-Wreturn-type` default to an error in all language modes (PR #123470)
https://github.com/Sirraide created https://github.com/llvm/llvm-project/pull/123470 This makes `-Wreturn-type` default to an error in all language modes as there is basically never a reason as to why one would *want* to fall off the end of a non-void function. Most of the tedious work of migrating the tests was done in #123464 (except for one test that for some reason didn’t want to cooperate earlier, which is why that one is handled in this pr). >From 441385e14210f23a4fe5368d44620073a4347a31 Mon Sep 17 00:00:00 2001 From: Sirraide Date: Sat, 18 Jan 2025 19:35:01 +0100 Subject: [PATCH] [Clang] Make -Wreturn-type default to an error in all language modes --- clang/docs/ReleaseNotes.rst | 4 clang/include/clang/Basic/DiagnosticSemaKinds.td | 12 ++-- clang/test/Index/warning-flags.c | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index aa1c02d04f7caa..a086c443984408 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -81,6 +81,10 @@ code bases. ``-fno-strict-overflow`` to opt-in to a language dialect where signed integer and pointer overflow are well-defined. +- ``-Wreturn-type`` now defaults to an error in all language modes; like other + warnings, it can be reverted to just being a warning by specifying + ``-Wno-error=return-type``. + C/C++ Language Potentially Breaking Changes --- diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index db54312ad965e8..b70d152781a2a8 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -709,10 +709,10 @@ def err_thread_unsupported : Error< // FIXME: Combine fallout warnings to just one warning. def warn_maybe_falloff_nonvoid_function : Warning< "non-void function does not return a value in all control paths">, - InGroup; + InGroup, DefaultError; def warn_falloff_nonvoid_function : Warning< "non-void function does not return a value">, - InGroup; + InGroup, DefaultError; def warn_const_attr_with_pure_attr : Warning< "'const' attribute imposes more restrictions; 'pure' attribute ignored">, InGroup; @@ -726,10 +726,10 @@ def err_falloff_nonvoid_block : Error< "non-void block does not return a value">; def warn_maybe_falloff_nonvoid_coroutine : Warning< "non-void coroutine does not return a value in all control paths">, - InGroup; + InGroup, DefaultError; def warn_falloff_nonvoid_coroutine : Warning< "non-void coroutine does not return a value">, - InGroup; + InGroup, DefaultError; def warn_suggest_noreturn_function : Warning< "%select{function|method}0 %1 could be declared with attribute 'noreturn'">, InGroup, DefaultIgnore; @@ -8365,10 +8365,10 @@ let CategoryName = "Lambda Issue" in { "lambda declared 'noreturn' should not return">; def warn_maybe_falloff_nonvoid_lambda : Warning< "non-void lambda does not return a value in all control paths">, -InGroup; +InGroup, DefaultError; def warn_falloff_nonvoid_lambda : Warning< "non-void lambda does not return a value">, -InGroup; +InGroup, DefaultError; def err_access_lambda_capture : Error< // The ERRORs represent other special members that aren't constructors, in // hopes that someone will bother noticing and reporting if they appear diff --git a/clang/test/Index/warning-flags.c b/clang/test/Index/warning-flags.c index 1694c6abab5624..3229f000c4ae0c 100644 --- a/clang/test/Index/warning-flags.c +++ b/clang/test/Index/warning-flags.c @@ -9,7 +9,7 @@ int *bar(float *f) { return f; } // RUN: c-index-test -test-load-source-reparse 5 all -w %s 2>&1 | FileCheck -check-prefix=NOWARNINGS %s // RUN: c-index-test -test-load-source all -w -O4 %s 2>&1 | FileCheck -check-prefix=NOWARNINGS %s -// CHECK-BOTH-WARNINGS: warning: non-void function does not return a value +// CHECK-BOTH-WARNINGS: error: non-void function does not return a value // CHECK-BOTH-WARNINGS: warning: incompatible pointer types returning 'float *' from a function with result type 'int *' // CHECK-SECOND-WARNING-NOT:non-void function does not return a value ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits