Skip to content

[Clang] [NFC] Fix unintended -Wreturn-type warnings everywhere in the test suite #123464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2025

Conversation

Sirraide
Copy link
Member

@Sirraide Sirraide commented Jan 18, 2025

In preparation of making -Wreturn-type default to an error (as there is virtually no situation where you’d want to fall off the end of a function that is supposed to return a value), this patch fixing tests that have relied on this being a warning, of which there seem to be 3 kinds:

  1. Tests which for no apparent reason have a function that triggers the warning.

    I suspect that a lot of these were on accident (or from before the warning was introduced), since a lot of people will open issues w/ their problematic code in the main function (which is the one case where you don’t need to return from a non-void function, after all...), which someone will then copy, possibly into a namespace, possibly renaming it, the end result of that being that you end up w/ something that definitely is not main anymore, but which still is declared as returning int, and which still has no return statement (another reason why I think this might apply to a lot of these is because usually the actual return type of such problematic functions is quite literally int).

    A lot of these are really old tests that don’t use -verify, which is why no-one noticed or had to care about the extra warning that was already being emitted by them until now.

  2. Tests which test either -Wreturn-type, [[noreturn]], or what codegen and sanitisers do whenever you do fall off the end of a function.

  3. Tests where I struggle to figure out what is even being tested (usually because they’re Objective-C tests, and I don’t know Objective-C), whether falling off the end of a function matters in the first place, and tests where actually spelling out an expression to return would be rather cumbersome (e.g. matrix types currently don’t support list initialisation, so I can’t write e.g. return {}).

For tests that fall into categories 2 and 3, I just added -Wno-error=return-type to the RUN lines and called it a day. This was especially necessary for the former since -Wreturn-type is an analysis-based warning, meaning that it is currently impossible to test for more than one occurrence of it in the same compilation if it defaults to an error since the analysis pass is skipped for subsequent functions as soon as an error is emitted.

I’ve also added -Werror=return-type to a few tests that I had already updated as this patch was previously already making the warning an error by default, but we’ve decided to split that into two patches instead.

@Sirraide Sirraide added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jan 18, 2025
@Sirraide Sirraide requested a review from Endilll as a code owner January 18, 2025 15:34
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:SystemZ backend:X86 clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:modules C++20 modules and Clang Header Modules labels Jan 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 18, 2025

@llvm/pr-subscribers-backend-x86
@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: None (Sirraide)

Changes

This makes -Wreturn-type default to an error as there is virtually no situation where you’d want to fall off the end of a function that is supposed to return a value. The actual change is just adding DefaultError to 6 diagnostics, the rest is fixing tests that have relied on this being a warning, of which there seem to be 3 kinds:

  1. Tests which for no apparent reason have a function that triggers the warning.

    I suspect that a lot of these were on accident (or from before the warning was introduced), since a lot of people will open issues w/ their problematic code in the main function (which is the one case where you don’t need to return from a non-void function, after all...), which someone will then copy, possibly into a namespace, possibly renaming it, the end result of that being that you end up w/ something that definitely is not main anymore, but which still is declared as returning int, and which still has no return statement (another reason why I think this might apply to a lot of these is because usually the actual return type of such problematic functions is quite literally int).

    A lot of these are really old tests that don’t use -verify, which is why no-one noticed or had to care about the extra warning that was already being emitted by them until now.

  2. Tests which test either -Wreturn-type, [[noreturn]], or what codegen and sanitisers do whenever you do fall off the end of a function.

  3. Tests where I struggle to figure out what is even being tested (usually because they’re Objective-C tests, and I don’t know Objective-C), whether falling off the end of a function matters in the first place, and tests where actually spelling out an expression to return would be rather cumbersome (e.g. matrix types currently don’t support list initialisation, so I can’t write e.g. return {}).

For tests that fall into categories 2 and 3, I just added -Wno-error=return-type to the RUN lines and called it a day. This was especially necessary for the former since -Wreturn-type is an analysis-based warning, meaning that it is currently impossible to test for more than one occurrence of it in the same compilation if it defaults to an error since the analysis pass is skipped for subsequent functions as soon as an error is emitted.


Patch is 116.79 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/123464.diff

150 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+6-3)
  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+6-6)
  • (modified) clang/test/ARCMT/autoreleases.m (+1-1)
  • (modified) clang/test/ARCMT/autoreleases.m.result (+1-1)
  • (modified) clang/test/ARCMT/retains.m (+2-2)
  • (modified) clang/test/ARCMT/retains.m.result (+2-2)
  • (modified) clang/test/AST/ast-dump-cxx2b-deducing-this.cpp (+1-1)
  • (modified) clang/test/AST/ast-dump-special-member-functions.cpp (+8-8)
  • (modified) clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist (+1-1)
  • (modified) clang/test/Analysis/const-method-call.cpp (+1-1)
  • (modified) clang/test/Analysis/inline-unique-reports.c (+1-1)
  • (modified) clang/test/Analysis/malloc.c (+2-2)
  • (modified) clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m (+17-17)
  • (modified) clang/test/Analysis/novoidtypecrash.c (+1-1)
  • (modified) clang/test/Analysis/plist-output.m (+1-1)
  • (modified) clang/test/Analysis/plist-stats-output.c (+1-1)
  • (modified) clang/test/Analysis/scopes-cfg-output.cpp (+1-1)
  • (modified) clang/test/Analysis/structured_bindings.cpp (+2-2)
  • (modified) clang/test/CXX/drs/cwg605.cpp (+1-1)
  • (modified) clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp (+5-5)
  • (modified) clang/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp (+4-4)
  • (modified) clang/test/CodeGen/2003-06-26-CFECrash.c (+1-1)
  • (modified) clang/test/CodeGen/2003-08-18-SigSetJmp.c (+1-1)
  • (modified) clang/test/CodeGen/2003-08-23-LocalUnionTest.c (+1-1)
  • (modified) clang/test/CodeGen/2003-10-29-AsmRename.c (+1-1)
  • (modified) clang/test/CodeGen/2003-11-20-ComplexDivision.c (+1-1)
  • (modified) clang/test/CodeGen/2004-06-18-VariableLengthArrayOfStructures.c (+1-1)
  • (modified) clang/test/CodeGen/2004-11-27-StaticFunctionRedeclare.c (+1-1)
  • (modified) clang/test/CodeGen/2005-01-02-VAArgError-ICE.c (+1-1)
  • (modified) clang/test/CodeGen/2005-06-15-ExpandGotoInternalProblem.c (+1-1)
  • (modified) clang/test/CodeGen/2007-01-06-KNR-Proto.c (+1)
  • (modified) clang/test/CodeGen/2008-05-06-CFECrash.c (+1-1)
  • (modified) clang/test/CodeGen/2008-07-30-redef-of-bitcasted-decl.c (+1-1)
  • (modified) clang/test/CodeGen/2008-10-13-FrontendCrash.c (+1-1)
  • (modified) clang/test/CodeGen/2009-01-21-InvalidIterator.c (+1)
  • (modified) clang/test/CodeGen/2009-05-04-EnumInreg.c (+1-1)
  • (modified) clang/test/CodeGen/2009-07-15-pad-wchar_t-array.c (+1)
  • (modified) clang/test/CodeGen/SystemZ/vec-abi-gnuattr-05.c (+1-1)
  • (modified) clang/test/CodeGen/X86/avx512fp16-abi.c (+8)
  • (modified) clang/test/CodeGen/X86/x86_64-atomic-128.c (+1)
  • (modified) clang/test/CodeGen/align-local.c (+1-1)
  • (modified) clang/test/CodeGen/arm-cmse-nonsecure.c (+2-2)
  • (modified) clang/test/CodeGen/arm-cmse-secure.c (+2-2)
  • (modified) clang/test/CodeGen/attr-noinline.cpp (+1-1)
  • (modified) clang/test/CodeGen/attr-noreturn.c (+2-2)
  • (modified) clang/test/CodeGen/block-copy.c (+1-1)
  • (modified) clang/test/CodeGen/builtin-memfns.c (+2-2)
  • (modified) clang/test/CodeGen/catch-undef-behavior.c (+3-3)
  • (modified) clang/test/CodeGen/cfi-unrelated-cast.cpp (+1-1)
  • (modified) clang/test/CodeGen/const-label-addr.c (+1-1)
  • (modified) clang/test/CodeGen/debug-info-crash.c (+1-1)
  • (modified) clang/test/CodeGen/debug-info.c (+2-2)
  • (modified) clang/test/CodeGen/empty-union-init.c (+1)
  • (modified) clang/test/CodeGen/exceptions-seh.c (+1)
  • (modified) clang/test/CodeGen/exprs.c (+6-6)
  • (modified) clang/test/CodeGen/ext-int-cc.c (+7-7)
  • (modified) clang/test/CodeGen/implicit-arg.c (+2-2)
  • (modified) clang/test/CodeGen/msan-param-retval.c (+6-6)
  • (modified) clang/test/CodeGen/msan-param-retval.cpp (+6-6)
  • (modified) clang/test/CodeGen/object-size.c (+1-1)
  • (modified) clang/test/CodeGen/sparcv8-abi.c (+3)
  • (modified) clang/test/CodeGen/sret.c (+1-1)
  • (modified) clang/test/CodeGen/static-order.c (+1)
  • (modified) clang/test/CodeGen/staticinit.c (+2-2)
  • (modified) clang/test/CodeGen/struct.c (+2-2)
  • (modified) clang/test/CodeGen/ubsan-debuglog-return.c (+1-1)
  • (modified) clang/test/CodeGen/union.c (+7-7)
  • (modified) clang/test/CodeGen/ve-abi.c (+1)
  • (modified) clang/test/CodeGenCXX/2007-01-06-PtrMethodInit.cpp (+5)
  • (modified) clang/test/CodeGenCXX/2007-09-10-RecursiveTypeResolution.cpp (+1)
  • (modified) clang/test/CodeGenCXX/2007-10-01-StructResize.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/2009-08-11-VectorRetTy.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/2010-07-23-DeclLoc.cpp (+4-4)
  • (modified) clang/test/CodeGenCXX/address-space-cast-coerce.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/array-value-initialize.cpp (+5-5)
  • (modified) clang/test/CodeGenCXX/attr.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/c-linkage.cpp (+2-1)
  • (modified) clang/test/CodeGenCXX/catch-undef-behavior.cpp (+5-5)
  • (modified) clang/test/CodeGenCXX/conditional-gnu-ext.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/cxx1y-variable-template-linkage.cpp (+3)
  • (modified) clang/test/CodeGenCXX/debug-info-cxx0x.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/debug-info-scoped-class.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/debug-lambda-this.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/expr.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp (+4-3)
  • (modified) clang/test/CodeGenCXX/mangle-exprs.cpp (+6-6)
  • (modified) clang/test/CodeGenCXX/mangle-variadic-templates.cpp (+3-3)
  • (modified) clang/test/CodeGenCXX/mangle.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/matrix-type-operators.cpp (+5-1)
  • (modified) clang/test/CodeGenCXX/matrix-type.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/microsoft-abi-static-initializers.cpp (+1)
  • (modified) clang/test/CodeGenCXX/new-alias.cpp (+2-1)
  • (modified) clang/test/CodeGenCXX/nrvo.cpp (+3-3)
  • (modified) clang/test/CodeGenCXX/reference-field.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/return.cpp (+4-4)
  • (modified) clang/test/CodeGenCXX/template-instantiation.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/trap-fnattr.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/ubsan-check-debuglocs.cpp (+1-1)
  • (modified) clang/test/CodeGenObjC/2007-10-18-ProDescriptor.m (+1)
  • (modified) clang/test/CodeGenObjC/2008-11-25-Blocks.m (+1-1)
  • (modified) clang/test/CodeGenObjC/debug-info-crash.m (+6-5)
  • (modified) clang/test/CodeGenObjC/encode-test.m (+6-6)
  • (modified) clang/test/CodeGenObjC/message-arrays.m (+1-1)
  • (modified) clang/test/CodeGenObjC/metadata-symbols-32.m (+2-2)
  • (modified) clang/test/CodeGenObjC/metadata-symbols-64.m (+3-3)
  • (modified) clang/test/CodeGenObjC/objc2-weak-compare.m (+3-3)
  • (modified) clang/test/CodeGenObjC/objc2-write-barrier-2.m (+6-5)
  • (modified) clang/test/CodeGenObjC/protocols-lazy.m (+1-1)
  • (modified) clang/test/CodeGenObjC/strong-in-c-struct.m (+4-4)
  • (modified) clang/test/CodeGenObjCXX/debug-info-line.mm (+2-2)
  • (modified) clang/test/CodeGenObjCXX/instantiate-return.mm (+1)
  • (modified) clang/test/CodeGenObjCXX/pr14474-gline-tables-only.mm (+4-4)
  • (modified) clang/test/CodeGenObjCXX/property-dot-reference.mm (+4-4)
  • (modified) clang/test/CodeGenObjCXX/return.mm (+2-2)
  • (modified) clang/test/CoverageMapping/switch.cpp (+1-1)
  • (modified) clang/test/Driver/cc-log-diagnostics.c (+3-3)
  • (modified) clang/test/FixIt/fixit-availability-maccatalyst.m (+1-1)
  • (modified) clang/test/FixIt/fixit-c++11.cpp (+1-1)
  • (modified) clang/test/Frontend/absolute-paths.c (+2-2)
  • (modified) clang/test/Frontend/ast-codegen.c (+2-2)
  • (modified) clang/test/Frontend/ast-main.cpp (+3-3)
  • (modified) clang/test/Index/warning-flags.c (+1-1)
  • (modified) clang/test/Misc/serialized-diags-stable.c (+1-1)
  • (modified) clang/test/Modules/pr61067.cppm (+1)
  • (modified) clang/test/Modules/redecl-merge.m (+1-1)
  • (modified) clang/test/PCH/irgen-rdar13114142.mm (+2)
  • (modified) clang/test/PCH/late-parsed-instantiations.cpp (+6-6)
  • (modified) clang/test/PCH/pr4489.c (+2-2)
  • (modified) clang/test/PCH/va_arg.c (+2)
  • (modified) clang/test/PCH/va_arg.h (+2)
  • (modified) clang/test/Parser/promote_types_in_proto.c (+1-1)
  • (modified) clang/test/Rewriter/rewrite-extern-c.mm (+1-1)
  • (modified) clang/test/Sema/freemain.c (+1-1)
  • (modified) clang/test/Sema/return-type-mismatch.c (+6-6)
  • (modified) clang/test/SemaCXX/attr-noreturn.cpp (+2-2)
  • (modified) clang/test/SemaCXX/constant-expression-cxx14.cpp (+1-1)
  • (modified) clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp (+1-1)
  • (added) clang/test/SemaCXX/err-missing-noreturn-1.cpp (+9)
  • (added) clang/test/SemaCXX/err-missing-noreturn-2.cpp (+15)
  • (modified) clang/test/SemaCXX/return-noreturn.cpp (+2-2)
  • (modified) clang/test/SemaCXX/warn-missing-noreturn.cpp (+1-14)
  • (modified) clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-add-assign.cpp (+7-7)
  • (modified) clang/test/SemaObjC/return-noreturn.m (+1-1)
  • (modified) clang/test/SemaObjC/try-catch.m (+1-1)
  • (modified) clang/test/SemaTemplate/late-parsing-eager-instantiation.cpp (+1-1)
  • (modified) clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (+1-1)
  • (modified) clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (+3-1)
  • (modified) clang/unittests/Tooling/ASTSelectionTest.cpp (+1-1)
  • (modified) clang/unittests/Tooling/LexicallyOrderedRecursiveASTVisitorTest.cpp (+1-1)
  • (modified) clang/unittests/Tooling/Syntax/BuildTreeTest.cpp (+3-3)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9eeb872aa57d79..b017f51658a449 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -81,6 +81,9 @@ code bases.
   ``-fno-strict-overflow`` to opt-in to a language dialect where signed integer
   and pointer overflow are well-defined.
 
+- The `-Wreturn-type` warning now defaults to an error. This behaviour can currently
+  be turned off by specifying `-Wno-error=return-type`.
+
 C/C++ Language Potentially Breaking Changes
 -------------------------------------------
 
@@ -310,7 +313,7 @@ C++23 Feature Support
 
 - Extend lifetime of temporaries in mem-default-init for P2718R0. Clang now fully
   supports `P2718R0 Lifetime extension in range-based for loops <https://wg21.link/P2718R0>`_.
-  
+
 - ``__cpp_explicit_this_parameter`` is now defined. (#GH82780)
 
 C++20 Feature Support
@@ -715,7 +718,7 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses dangling references for C++20's parenthesized aggregate initialization (#101957).
 
-- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings when an unrelated class 
+- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings when an unrelated class
   defined a defaulted comparison operator (#GH116270).
 
   .. code-block:: c++
@@ -934,7 +937,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure caused by invalid default argument substitutions in non-defining
   friend declarations. (#GH113324)
 - Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659)
-- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072) 
+- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072)
 - Fixed a null pointer dereference issue when heuristically computing ``sizeof...(pack)`` expressions. (#GH81436)
 - Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205)
 - Fixed an incorrect lambda scope of generic lambdas that caused Clang to crash when computing potential lambda
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..c84177a9bc75cc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -707,10 +707,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<ReturnType>;
+  InGroup<ReturnType>, DefaultError;
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
-  InGroup<ReturnType>;
+  InGroup<ReturnType>, DefaultError;
 def warn_const_attr_with_pure_attr : Warning<
   "'const' attribute imposes more restrictions; 'pure' attribute ignored">,
   InGroup<IgnoredAttributes>;
@@ -724,10 +724,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<ReturnType>;
+  InGroup<ReturnType>, DefaultError;
 def warn_falloff_nonvoid_coroutine : Warning<
   "non-void coroutine does not return a value">,
-  InGroup<ReturnType>;
+  InGroup<ReturnType>, DefaultError;
 def warn_suggest_noreturn_function : Warning<
   "%select{function|method}0 %1 could be declared with attribute 'noreturn'">,
   InGroup<MissingNoreturn>, DefaultIgnore;
@@ -8358,10 +8358,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<ReturnType>;
+    InGroup<ReturnType>, DefaultError;
   def warn_falloff_nonvoid_lambda : Warning<
     "non-void lambda does not return a value">,
-    InGroup<ReturnType>;
+    InGroup<ReturnType>, 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/ARCMT/autoreleases.m b/clang/test/ARCMT/autoreleases.m
index 4c268c09a715c6..7c046dc227a068 100644
--- a/clang/test/ARCMT/autoreleases.m
+++ b/clang/test/ARCMT/autoreleases.m
@@ -69,7 +69,7 @@ id test2(A* val) {
   return val;
 }
 
-id test3(void) {
+void test3(void) {
   id a = [[A alloc] init];
   [a autorelease];
 }
diff --git a/clang/test/ARCMT/autoreleases.m.result b/clang/test/ARCMT/autoreleases.m.result
index b3aad804a45be6..29d00ea60deed8 100644
--- a/clang/test/ARCMT/autoreleases.m.result
+++ b/clang/test/ARCMT/autoreleases.m.result
@@ -64,6 +64,6 @@ id test2(A* val) {
   return val;
 }
 
-id test3(void) {
+void test3(void) {
   id a = [[A alloc] init];
 }
diff --git a/clang/test/ARCMT/retains.m b/clang/test/ARCMT/retains.m
index 43a94fc16cecf2..df1badf214b692 100644
--- a/clang/test/ARCMT/retains.m
+++ b/clang/test/ARCMT/retains.m
@@ -21,7 +21,7 @@ @implementation Foo
 
 @synthesize bar;
 
--(id)something {}
+-(id)something { return (id)0; }
 
 -(id)test:(id)obj {
   id x = self.bar;
@@ -44,7 +44,7 @@ -(id)test:(id)obj {
   [x release];
   return [self retain];
 }
-  
+
 - (id)test1 {
   id x=0;
   ([x retain]);
diff --git a/clang/test/ARCMT/retains.m.result b/clang/test/ARCMT/retains.m.result
index 4e720d6bb4c112..211c4b50f53519 100644
--- a/clang/test/ARCMT/retains.m.result
+++ b/clang/test/ARCMT/retains.m.result
@@ -21,7 +21,7 @@ id IhaveSideEffect(void);
 
 @synthesize bar;
 
--(id)something {}
+-(id)something { return (id)0; }
 
 -(id)test:(id)obj {
   id x = self.bar;
@@ -39,7 +39,7 @@ id IhaveSideEffect(void);
   // do stuff with x;
   return self;
 }
-  
+
 - (id)test1 {
   id x=0;
   return (((x)));
diff --git a/clang/test/AST/ast-dump-cxx2b-deducing-this.cpp b/clang/test/AST/ast-dump-cxx2b-deducing-this.cpp
index 1b385e0fc33319..854d12b4cdba6e 100644
--- a/clang/test/AST/ast-dump-cxx2b-deducing-this.cpp
+++ b/clang/test/AST/ast-dump-cxx2b-deducing-this.cpp
@@ -5,7 +5,7 @@ struct S {
   int f(this S&);
 };
 
-int main() {
+void main() {
   S s;
   int x = s.f();
   // CHECK: CallExpr 0x{{[^ ]*}} <col:11, col:15> 'int
diff --git a/clang/test/AST/ast-dump-special-member-functions.cpp b/clang/test/AST/ast-dump-special-member-functions.cpp
index b98c90f6760434..0fe2cee615c826 100644
--- a/clang/test/AST/ast-dump-special-member-functions.cpp
+++ b/clang/test/AST/ast-dump-special-member-functions.cpp
@@ -253,25 +253,25 @@ struct TrivialCopyAssignment {
 struct NontrivialCopyAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct NontrivialCopyAssignment definition
   // CHECK: CopyAssignment {{.*}}non_trivial{{.*}}
-  NontrivialCopyAssignment& operator=(const NontrivialCopyAssignment&) {}
+  NontrivialCopyAssignment& operator=(const NontrivialCopyAssignment&) { return *this; }
 };
 
 struct CopyAssignmentHasConstParam {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct CopyAssignmentHasConstParam definition
   // CHECK: CopyAssignment {{.*}}has_const_param{{.*}}
-  CopyAssignmentHasConstParam& operator=(const CopyAssignmentHasConstParam&) {}
+  CopyAssignmentHasConstParam& operator=(const CopyAssignmentHasConstParam&) { return *this; }
 };
 
 struct CopyAssignmentDoesNotHaveConstParam {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct CopyAssignmentDoesNotHaveConstParam definition
   // CHECK-NOT: CopyAssignment {{.*}} has_const_param{{.*}}
-  CopyAssignmentDoesNotHaveConstParam& operator=(CopyAssignmentDoesNotHaveConstParam&) {}
+  CopyAssignmentDoesNotHaveConstParam& operator=(CopyAssignmentDoesNotHaveConstParam&) { return *this; }
 };
 
 struct UserDeclaredCopyAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct UserDeclaredCopyAssignment definition
   // CHECK: CopyAssignment {{.*}}user_declared{{.*}}
-  UserDeclaredCopyAssignment& operator=(const UserDeclaredCopyAssignment&) {}
+  UserDeclaredCopyAssignment& operator=(const UserDeclaredCopyAssignment&) { return *this; }
 };
 
 struct NonUserDeclaredCopyAssignment {
@@ -288,7 +288,7 @@ struct NeedsImplicitCopyAssignment {
 struct DoesNotNeedImplicitCopyAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct DoesNotNeedImplicitCopyAssignment definition
   // CHECK-NOT: CopyAssignment {{.*}}needs_implicit{{.*}}
-  DoesNotNeedImplicitCopyAssignment& operator=(const DoesNotNeedImplicitCopyAssignment&) {}
+  DoesNotNeedImplicitCopyAssignment& operator=(const DoesNotNeedImplicitCopyAssignment&) { return *this; }
 };
 
 struct DeclaresCopyAssignment {
@@ -352,13 +352,13 @@ struct TrivialMoveAssignment {
 struct NontrivialMoveAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct NontrivialMoveAssignment definition
   // CHECK: MoveAssignment {{.*}}non_trivial{{.*}}
-  NontrivialMoveAssignment& operator=(NontrivialMoveAssignment&&) {}
+  NontrivialMoveAssignment& operator=(NontrivialMoveAssignment&&) { return *this; }
 };
 
 struct UserDeclaredMoveAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct UserDeclaredMoveAssignment definition
   // CHECK: MoveAssignment {{.*}}user_declared{{.*}}
-  UserDeclaredMoveAssignment& operator=(UserDeclaredMoveAssignment&&) {}
+  UserDeclaredMoveAssignment& operator=(UserDeclaredMoveAssignment&&) { return *this; }
 };
 
 struct NonUserDeclaredMoveAssignment {
@@ -375,7 +375,7 @@ struct NeedsImplicitMoveAssignment {
 struct DoesNotNeedImplicitMoveAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct DoesNotNeedImplicitMoveAssignment definition
   // CHECK-NOT: MoveAssignment {{.*}}needs_implicit{{.*}}
-  DoesNotNeedImplicitMoveAssignment& operator=(DoesNotNeedImplicitMoveAssignment&&) {}
+  DoesNotNeedImplicitMoveAssignment& operator=(DoesNotNeedImplicitMoveAssignment&&) { return *this; }
 };
 
 struct MoveAssignmentNeedsOverloadResolution : virtual DeletedDestructor {
diff --git a/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist b/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist
index 32244329c434aa..8b8cc3239bd4bd 100644
--- a/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist
+++ b/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist
@@ -6151,7 +6151,7 @@
    <key>type</key><string>Argument with &apos;nonnull&apos; attribute passed null</string>
    <key>check_name</key><string>core.NonNullParamChecker</string>
    <!-- This hash is experimental and going to change! -->
-   <key>issue_hash_content_of_line_in_context</key><string>c0b359a043c633f1b8d1581f68743361</string>
+   <key>issue_hash_content_of_line_in_context</key><string>4c580a2a9cf15947fa485a0a9e625306</string>
   <key>issue_context_kind</key><string>function</string>
   <key>issue_context</key><string>RDar13295437</string>
   <key>issue_hash_function_offset</key><string>3</string>
diff --git a/clang/test/Analysis/const-method-call.cpp b/clang/test/Analysis/const-method-call.cpp
index 7da7ca5554a23e..b37ce17447bdd2 100644
--- a/clang/test/Analysis/const-method-call.cpp
+++ b/clang/test/Analysis/const-method-call.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
 
 void clang_analyzer_eval(bool);
 
diff --git a/clang/test/Analysis/inline-unique-reports.c b/clang/test/Analysis/inline-unique-reports.c
index e58870ea74ab83..306e314a94e437 100644
--- a/clang/test/Analysis/inline-unique-reports.c
+++ b/clang/test/Analysis/inline-unique-reports.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=plist -Wno-error=implicit-int -o %t > /dev/null 2>&1
+// RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=plist -Wno-error=implicit-int -Wno-error=return-type -o %t > /dev/null 2>&1
 // RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/inline-unique-reports.c.plist -
 
 static inline bug(int *p) {
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index f2f8975b5f0e21..0dc667bc1ed505 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -1914,8 +1914,8 @@ variable 'buf', which is not memory allocated by 'malloc()' [unix.Malloc]}}
 
 (*crash_a)(); // expected-warning{{type specifier missing}}
 // A CallEvent without a corresponding FunctionDecl.
-crash_b() { crash_a(); } // no-crash
-// expected-warning@-1{{type specifier missing}} expected-warning@-1{{non-void}}
+crash_b() { crash_a(); return 0; } // no-crash
+// expected-warning@-1{{type specifier missing}}
 
 long *global_a;
 void realloc_crash(void) {
diff --git a/clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m b/clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
index bfc3cb92b639af..0dfeb298db7426 100644
--- a/clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
+++ b/clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
@@ -1,8 +1,8 @@
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin8 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.1 2>&1
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -triple i386-apple-darwin8 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.1 2>&1
 // RUN: FileCheck -input-file=%t.1 -check-prefix=CHECK-darwin8 %s
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.2 2>&1
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.2 2>&1
 // RUN: FileCheck -input-file=%t.2 -check-prefix=CHECK-darwin9 %s
-// RUN: %clang_analyze_cc1 -triple thumbv6-apple-ios4.0 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.3 2>&1
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -triple thumbv6-apple-ios4.0 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.3 2>&1
 // RUN: FileCheck -input-file=%t.3 -check-prefix=CHECK-darwin9 %s
 
 @interface MyClass {}
@@ -25,53 +25,53 @@ - (void)voidM {}
 @end
 
 void createFoo(void) {
-  MyClass *obj = 0;  
-  
+  MyClass *obj = 0;
+
   void *v = [obj voidPtrM]; // no-warning
   int i = [obj intM]; // no-warning
 }
 
 void createFoo2(void) {
-  MyClass *obj = 0;  
-  
+  MyClass *obj = 0;
+
   long double ld = [obj longDoubleM];
 }
 
 void createFoo3(void) {
   MyClass *obj;
-  obj = 0;  
-  
+  obj = 0;
+
   long long ll = [obj longlongM];
 }
 
 void createFoo4(void) {
-  MyClass *obj = 0;  
-  
+  MyClass *obj = 0;
+
   double d = [obj doubleM];
 }
 
 void createFoo5(void) {
-  MyClass *obj = (id)@"";  
-  
+  MyClass *obj = (id)@"";
+
   double d = [obj doubleM]; // no-warning
 }
 
 void createFoo6(void) {
   MyClass *obj;
-  obj = 0;  
-  
+  obj = 0;
+
   unsigned long long ull = [obj unsignedLongLongM];
 }
 
 void handleNilPruneLoop(MyClass *obj) {
   if (!!obj)
     return;
-  
+
   // Test if [obj intM] evaluates to 0, thus pruning the entire loop.
   for (int i = 0; i < [obj intM]; i++) {
     long long j = [obj longlongM];
   }
-  
+
   long long j = [obj longlongM];
 }
 
diff --git a/clang/test/Analysis/novoidtypecrash.c b/clang/test/Analysis/novoidtypecrash.c
index 197516a2596187..5af30c20104386 100644
--- a/clang/test/Analysis/novoidtypecrash.c
+++ b/clang/test/Analysis/novoidtypecrash.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -std=c89 -Wno-int-conversion -analyzer-checker=core %s
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -std=c89 -Wno-int-conversion -analyzer-checker=core %s
 x;
 y(void **z) { // no-crash
   *z = x;
diff --git a/clang/test/Analysis/plist-output.m b/clang/test/Analysis/plist-output.m
index 96123243a833a0..b89aab0a7c4cfd 100644
--- a/clang/test/Analysis/plist-output.m
+++ b/clang/test/Analysis/plist-output.m
@@ -177,7 +177,7 @@ - (void)test {
 
 struct  RDar13295437_S { int *i; };
 
-int  RDar13295437(void) {
+void RDar13295437(void) {
   struct RDar13295437_S s = {0};
   struct RDar13295437_S *sp = &s;
   RDar13295437_f(sp->i);
diff --git a/clang/test/Analysis/plist-stats-output.c b/clang/test/Analysis/plist-stats-output.c
index 4bcae557d9276d..42e0a802d3e377 100644
--- a/clang/test/Analysis/plist-stats-output.c
+++ b/clang/test/Analysis/plist-stats-output.c
@@ -2,7 +2,7 @@
 // REQUIRES: asserts
 // RUN: FileCheck --input-file=%t.plist %s
 
-int foo(void) {}
+void foo(void) {}
 
 
 // CHECK:  <key>diagnostics</key>
diff --git a/clang/test/Analysis/scopes-cfg-output.cpp b/clang/test/Analysis/scopes-cfg-output.cpp
index 5e6706602d4564..c082bb179545fa 100644
--- a/clang/test/Analysis/scopes-cfg-output.cpp
+++ b/clang/test/Analysis/scopes-cfg-output.cpp
@@ -1074,7 +1074,7 @@ void test_switch_with_compound_with_default() {
 // CHECK-NEXT:   Succs (1): B4
 // CHECK:      [B0 (EXIT)]
 // CHECK-NEXT:   Preds (1): B1
-int test_switch_with_compound_without_default() {
+void test_switch_with_compound_without_default() {
   char c = '1';
   switch (int i = getX()) {
     case 0:
diff --git a/clang/test/Analysis/structured_bindings.cpp b/clang/test/Analysis/structured_bindings.cpp
index 7004c2e7dcf43f..989c584189ab2d 100644
--- a/clang/test/Analysis/structured_bindings.cpp
+++ b/clang/test/Analysis/structured_bindings.cpp
@@ -3,10 +3,10 @@
 void clang_analyzer_eval(bool);
 
 struct s { int a; };
-int foo() {
+void foo() {
   auto [a] = s{1};
   clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
-} // expected-warning{{non-void function does not return a value}}
+}
 
 struct s2 {
   int &x;
diff --git a/clang/test/CXX/drs/cwg605.cpp b/clang/test/CXX/drs/cwg605.cpp
index 2fd9e8155bf77b..b98c483f3118eb 100644
--- a/clang/test/CXX/drs/cwg605.cpp
+++ b/clang/test/CXX/drs/cwg605.cpp
@@ -12,7 +12,7 @@ template <class T>
 static T f(T t) {}
 
 template <>
-int f(int t) {}
+int f(int t) { return 0; }
 
 void g(int a) {
   f(a);
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
index 2a99ff0ea44f90..a07ee2213ce40c 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
@@ -3,7 +3,7 @@
 // An attribute-specifier-seq in a lambda-declarator appertains to the
 // type of the corresponding function call operator.
 void test_attributes() {
-  auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-warning{{on-void lambda does not return a value in all control paths}}
+  auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-error{{non-void lambda does not return a value in all control paths}}
 
   // FIXME: GCC accepts the [[gnu::noreturn]] attribute here.
   auto nrl2 = []() [[gnu::noreturn]] { return; }; // expected-warning{{attribute 'noreturn' ignored}}
@@ -25,7 +25,7 @@ void test_quals() {
   lc();
 
   auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \
-                             // expected-note{{method is not marked volatile}} 
+                             // expected-note{{method is not marked volatile}}
   const decltype(ml) mlc = ml;
   ml();
   mlc(); // expected-error{{no matching function for call to object of type}}
@@ -56,8 +56,8 @@ void test_exception_spec() {
   auto ntl1 = []() throw() {};
   auto ntl2 = []() noexcept(true) {};
   auto ntl3 = []() noexcept {};
-  static_assert(noexcept(ntl1()), "lambda cannot throw");  
-  static_assert(noexcept(ntl2()), "lambda cannot throw");  
-  static_assert(noexcept(ntl3()), "lambda cannot throw");  
+  static_assert(noexcept(ntl1()), "lambda cannot throw");
+  static_assert(noexcept(ntl2()), "lambda cannot throw");
+  static_assert(noexcept(ntl3()), "lambda cannot throw");
 }
 
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp b/clang/test/C...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Jan 18, 2025

@llvm/pr-subscribers-backend-systemz

Author: None (Sirraide)

Changes

This makes -Wreturn-type default to an error as there is virtually no situation where you’d want to fall off the end of a function that is supposed to return a value. The actual change is just adding DefaultError to 6 diagnostics, the rest is fixing tests that have relied on this being a warning, of which there seem to be 3 kinds:

  1. Tests which for no apparent reason have a function that triggers the warning.

    I suspect that a lot of these were on accident (or from before the warning was introduced), since a lot of people will open issues w/ their problematic code in the main function (which is the one case where you don’t need to return from a non-void function, after all...), which someone will then copy, possibly into a namespace, possibly renaming it, the end result of that being that you end up w/ something that definitely is not main anymore, but which still is declared as returning int, and which still has no return statement (another reason why I think this might apply to a lot of these is because usually the actual return type of such problematic functions is quite literally int).

    A lot of these are really old tests that don’t use -verify, which is why no-one noticed or had to care about the extra warning that was already being emitted by them until now.

  2. Tests which test either -Wreturn-type, [[noreturn]], or what codegen and sanitisers do whenever you do fall off the end of a function.

  3. Tests where I struggle to figure out what is even being tested (usually because they’re Objective-C tests, and I don’t know Objective-C), whether falling off the end of a function matters in the first place, and tests where actually spelling out an expression to return would be rather cumbersome (e.g. matrix types currently don’t support list initialisation, so I can’t write e.g. return {}).

For tests that fall into categories 2 and 3, I just added -Wno-error=return-type to the RUN lines and called it a day. This was especially necessary for the former since -Wreturn-type is an analysis-based warning, meaning that it is currently impossible to test for more than one occurrence of it in the same compilation if it defaults to an error since the analysis pass is skipped for subsequent functions as soon as an error is emitted.


Patch is 116.79 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/123464.diff

150 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+6-3)
  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+6-6)
  • (modified) clang/test/ARCMT/autoreleases.m (+1-1)
  • (modified) clang/test/ARCMT/autoreleases.m.result (+1-1)
  • (modified) clang/test/ARCMT/retains.m (+2-2)
  • (modified) clang/test/ARCMT/retains.m.result (+2-2)
  • (modified) clang/test/AST/ast-dump-cxx2b-deducing-this.cpp (+1-1)
  • (modified) clang/test/AST/ast-dump-special-member-functions.cpp (+8-8)
  • (modified) clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist (+1-1)
  • (modified) clang/test/Analysis/const-method-call.cpp (+1-1)
  • (modified) clang/test/Analysis/inline-unique-reports.c (+1-1)
  • (modified) clang/test/Analysis/malloc.c (+2-2)
  • (modified) clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m (+17-17)
  • (modified) clang/test/Analysis/novoidtypecrash.c (+1-1)
  • (modified) clang/test/Analysis/plist-output.m (+1-1)
  • (modified) clang/test/Analysis/plist-stats-output.c (+1-1)
  • (modified) clang/test/Analysis/scopes-cfg-output.cpp (+1-1)
  • (modified) clang/test/Analysis/structured_bindings.cpp (+2-2)
  • (modified) clang/test/CXX/drs/cwg605.cpp (+1-1)
  • (modified) clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp (+5-5)
  • (modified) clang/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp (+4-4)
  • (modified) clang/test/CodeGen/2003-06-26-CFECrash.c (+1-1)
  • (modified) clang/test/CodeGen/2003-08-18-SigSetJmp.c (+1-1)
  • (modified) clang/test/CodeGen/2003-08-23-LocalUnionTest.c (+1-1)
  • (modified) clang/test/CodeGen/2003-10-29-AsmRename.c (+1-1)
  • (modified) clang/test/CodeGen/2003-11-20-ComplexDivision.c (+1-1)
  • (modified) clang/test/CodeGen/2004-06-18-VariableLengthArrayOfStructures.c (+1-1)
  • (modified) clang/test/CodeGen/2004-11-27-StaticFunctionRedeclare.c (+1-1)
  • (modified) clang/test/CodeGen/2005-01-02-VAArgError-ICE.c (+1-1)
  • (modified) clang/test/CodeGen/2005-06-15-ExpandGotoInternalProblem.c (+1-1)
  • (modified) clang/test/CodeGen/2007-01-06-KNR-Proto.c (+1)
  • (modified) clang/test/CodeGen/2008-05-06-CFECrash.c (+1-1)
  • (modified) clang/test/CodeGen/2008-07-30-redef-of-bitcasted-decl.c (+1-1)
  • (modified) clang/test/CodeGen/2008-10-13-FrontendCrash.c (+1-1)
  • (modified) clang/test/CodeGen/2009-01-21-InvalidIterator.c (+1)
  • (modified) clang/test/CodeGen/2009-05-04-EnumInreg.c (+1-1)
  • (modified) clang/test/CodeGen/2009-07-15-pad-wchar_t-array.c (+1)
  • (modified) clang/test/CodeGen/SystemZ/vec-abi-gnuattr-05.c (+1-1)
  • (modified) clang/test/CodeGen/X86/avx512fp16-abi.c (+8)
  • (modified) clang/test/CodeGen/X86/x86_64-atomic-128.c (+1)
  • (modified) clang/test/CodeGen/align-local.c (+1-1)
  • (modified) clang/test/CodeGen/arm-cmse-nonsecure.c (+2-2)
  • (modified) clang/test/CodeGen/arm-cmse-secure.c (+2-2)
  • (modified) clang/test/CodeGen/attr-noinline.cpp (+1-1)
  • (modified) clang/test/CodeGen/attr-noreturn.c (+2-2)
  • (modified) clang/test/CodeGen/block-copy.c (+1-1)
  • (modified) clang/test/CodeGen/builtin-memfns.c (+2-2)
  • (modified) clang/test/CodeGen/catch-undef-behavior.c (+3-3)
  • (modified) clang/test/CodeGen/cfi-unrelated-cast.cpp (+1-1)
  • (modified) clang/test/CodeGen/const-label-addr.c (+1-1)
  • (modified) clang/test/CodeGen/debug-info-crash.c (+1-1)
  • (modified) clang/test/CodeGen/debug-info.c (+2-2)
  • (modified) clang/test/CodeGen/empty-union-init.c (+1)
  • (modified) clang/test/CodeGen/exceptions-seh.c (+1)
  • (modified) clang/test/CodeGen/exprs.c (+6-6)
  • (modified) clang/test/CodeGen/ext-int-cc.c (+7-7)
  • (modified) clang/test/CodeGen/implicit-arg.c (+2-2)
  • (modified) clang/test/CodeGen/msan-param-retval.c (+6-6)
  • (modified) clang/test/CodeGen/msan-param-retval.cpp (+6-6)
  • (modified) clang/test/CodeGen/object-size.c (+1-1)
  • (modified) clang/test/CodeGen/sparcv8-abi.c (+3)
  • (modified) clang/test/CodeGen/sret.c (+1-1)
  • (modified) clang/test/CodeGen/static-order.c (+1)
  • (modified) clang/test/CodeGen/staticinit.c (+2-2)
  • (modified) clang/test/CodeGen/struct.c (+2-2)
  • (modified) clang/test/CodeGen/ubsan-debuglog-return.c (+1-1)
  • (modified) clang/test/CodeGen/union.c (+7-7)
  • (modified) clang/test/CodeGen/ve-abi.c (+1)
  • (modified) clang/test/CodeGenCXX/2007-01-06-PtrMethodInit.cpp (+5)
  • (modified) clang/test/CodeGenCXX/2007-09-10-RecursiveTypeResolution.cpp (+1)
  • (modified) clang/test/CodeGenCXX/2007-10-01-StructResize.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/2009-08-11-VectorRetTy.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/2010-07-23-DeclLoc.cpp (+4-4)
  • (modified) clang/test/CodeGenCXX/address-space-cast-coerce.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/array-value-initialize.cpp (+5-5)
  • (modified) clang/test/CodeGenCXX/attr.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/c-linkage.cpp (+2-1)
  • (modified) clang/test/CodeGenCXX/catch-undef-behavior.cpp (+5-5)
  • (modified) clang/test/CodeGenCXX/conditional-gnu-ext.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/cxx1y-variable-template-linkage.cpp (+3)
  • (modified) clang/test/CodeGenCXX/debug-info-cxx0x.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/debug-info-scoped-class.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/debug-lambda-this.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/expr.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp (+4-3)
  • (modified) clang/test/CodeGenCXX/mangle-exprs.cpp (+6-6)
  • (modified) clang/test/CodeGenCXX/mangle-variadic-templates.cpp (+3-3)
  • (modified) clang/test/CodeGenCXX/mangle.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/matrix-type-operators.cpp (+5-1)
  • (modified) clang/test/CodeGenCXX/matrix-type.cpp (+1-1)
  • (modified) clang/test/CodeGenCXX/microsoft-abi-static-initializers.cpp (+1)
  • (modified) clang/test/CodeGenCXX/new-alias.cpp (+2-1)
  • (modified) clang/test/CodeGenCXX/nrvo.cpp (+3-3)
  • (modified) clang/test/CodeGenCXX/reference-field.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/return.cpp (+4-4)
  • (modified) clang/test/CodeGenCXX/template-instantiation.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/trap-fnattr.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/ubsan-check-debuglocs.cpp (+1-1)
  • (modified) clang/test/CodeGenObjC/2007-10-18-ProDescriptor.m (+1)
  • (modified) clang/test/CodeGenObjC/2008-11-25-Blocks.m (+1-1)
  • (modified) clang/test/CodeGenObjC/debug-info-crash.m (+6-5)
  • (modified) clang/test/CodeGenObjC/encode-test.m (+6-6)
  • (modified) clang/test/CodeGenObjC/message-arrays.m (+1-1)
  • (modified) clang/test/CodeGenObjC/metadata-symbols-32.m (+2-2)
  • (modified) clang/test/CodeGenObjC/metadata-symbols-64.m (+3-3)
  • (modified) clang/test/CodeGenObjC/objc2-weak-compare.m (+3-3)
  • (modified) clang/test/CodeGenObjC/objc2-write-barrier-2.m (+6-5)
  • (modified) clang/test/CodeGenObjC/protocols-lazy.m (+1-1)
  • (modified) clang/test/CodeGenObjC/strong-in-c-struct.m (+4-4)
  • (modified) clang/test/CodeGenObjCXX/debug-info-line.mm (+2-2)
  • (modified) clang/test/CodeGenObjCXX/instantiate-return.mm (+1)
  • (modified) clang/test/CodeGenObjCXX/pr14474-gline-tables-only.mm (+4-4)
  • (modified) clang/test/CodeGenObjCXX/property-dot-reference.mm (+4-4)
  • (modified) clang/test/CodeGenObjCXX/return.mm (+2-2)
  • (modified) clang/test/CoverageMapping/switch.cpp (+1-1)
  • (modified) clang/test/Driver/cc-log-diagnostics.c (+3-3)
  • (modified) clang/test/FixIt/fixit-availability-maccatalyst.m (+1-1)
  • (modified) clang/test/FixIt/fixit-c++11.cpp (+1-1)
  • (modified) clang/test/Frontend/absolute-paths.c (+2-2)
  • (modified) clang/test/Frontend/ast-codegen.c (+2-2)
  • (modified) clang/test/Frontend/ast-main.cpp (+3-3)
  • (modified) clang/test/Index/warning-flags.c (+1-1)
  • (modified) clang/test/Misc/serialized-diags-stable.c (+1-1)
  • (modified) clang/test/Modules/pr61067.cppm (+1)
  • (modified) clang/test/Modules/redecl-merge.m (+1-1)
  • (modified) clang/test/PCH/irgen-rdar13114142.mm (+2)
  • (modified) clang/test/PCH/late-parsed-instantiations.cpp (+6-6)
  • (modified) clang/test/PCH/pr4489.c (+2-2)
  • (modified) clang/test/PCH/va_arg.c (+2)
  • (modified) clang/test/PCH/va_arg.h (+2)
  • (modified) clang/test/Parser/promote_types_in_proto.c (+1-1)
  • (modified) clang/test/Rewriter/rewrite-extern-c.mm (+1-1)
  • (modified) clang/test/Sema/freemain.c (+1-1)
  • (modified) clang/test/Sema/return-type-mismatch.c (+6-6)
  • (modified) clang/test/SemaCXX/attr-noreturn.cpp (+2-2)
  • (modified) clang/test/SemaCXX/constant-expression-cxx14.cpp (+1-1)
  • (modified) clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp (+1-1)
  • (added) clang/test/SemaCXX/err-missing-noreturn-1.cpp (+9)
  • (added) clang/test/SemaCXX/err-missing-noreturn-2.cpp (+15)
  • (modified) clang/test/SemaCXX/return-noreturn.cpp (+2-2)
  • (modified) clang/test/SemaCXX/warn-missing-noreturn.cpp (+1-14)
  • (modified) clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-add-assign.cpp (+7-7)
  • (modified) clang/test/SemaObjC/return-noreturn.m (+1-1)
  • (modified) clang/test/SemaObjC/try-catch.m (+1-1)
  • (modified) clang/test/SemaTemplate/late-parsing-eager-instantiation.cpp (+1-1)
  • (modified) clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (+1-1)
  • (modified) clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (+3-1)
  • (modified) clang/unittests/Tooling/ASTSelectionTest.cpp (+1-1)
  • (modified) clang/unittests/Tooling/LexicallyOrderedRecursiveASTVisitorTest.cpp (+1-1)
  • (modified) clang/unittests/Tooling/Syntax/BuildTreeTest.cpp (+3-3)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9eeb872aa57d79..b017f51658a449 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -81,6 +81,9 @@ code bases.
   ``-fno-strict-overflow`` to opt-in to a language dialect where signed integer
   and pointer overflow are well-defined.
 
+- The `-Wreturn-type` warning now defaults to an error. This behaviour can currently
+  be turned off by specifying `-Wno-error=return-type`.
+
 C/C++ Language Potentially Breaking Changes
 -------------------------------------------
 
@@ -310,7 +313,7 @@ C++23 Feature Support
 
 - Extend lifetime of temporaries in mem-default-init for P2718R0. Clang now fully
   supports `P2718R0 Lifetime extension in range-based for loops <https://wg21.link/P2718R0>`_.
-  
+
 - ``__cpp_explicit_this_parameter`` is now defined. (#GH82780)
 
 C++20 Feature Support
@@ -715,7 +718,7 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses dangling references for C++20's parenthesized aggregate initialization (#101957).
 
-- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings when an unrelated class 
+- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings when an unrelated class
   defined a defaulted comparison operator (#GH116270).
 
   .. code-block:: c++
@@ -934,7 +937,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure caused by invalid default argument substitutions in non-defining
   friend declarations. (#GH113324)
 - Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659)
-- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072) 
+- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072)
 - Fixed a null pointer dereference issue when heuristically computing ``sizeof...(pack)`` expressions. (#GH81436)
 - Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205)
 - Fixed an incorrect lambda scope of generic lambdas that caused Clang to crash when computing potential lambda
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..c84177a9bc75cc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -707,10 +707,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<ReturnType>;
+  InGroup<ReturnType>, DefaultError;
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
-  InGroup<ReturnType>;
+  InGroup<ReturnType>, DefaultError;
 def warn_const_attr_with_pure_attr : Warning<
   "'const' attribute imposes more restrictions; 'pure' attribute ignored">,
   InGroup<IgnoredAttributes>;
@@ -724,10 +724,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<ReturnType>;
+  InGroup<ReturnType>, DefaultError;
 def warn_falloff_nonvoid_coroutine : Warning<
   "non-void coroutine does not return a value">,
-  InGroup<ReturnType>;
+  InGroup<ReturnType>, DefaultError;
 def warn_suggest_noreturn_function : Warning<
   "%select{function|method}0 %1 could be declared with attribute 'noreturn'">,
   InGroup<MissingNoreturn>, DefaultIgnore;
@@ -8358,10 +8358,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<ReturnType>;
+    InGroup<ReturnType>, DefaultError;
   def warn_falloff_nonvoid_lambda : Warning<
     "non-void lambda does not return a value">,
-    InGroup<ReturnType>;
+    InGroup<ReturnType>, 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/ARCMT/autoreleases.m b/clang/test/ARCMT/autoreleases.m
index 4c268c09a715c6..7c046dc227a068 100644
--- a/clang/test/ARCMT/autoreleases.m
+++ b/clang/test/ARCMT/autoreleases.m
@@ -69,7 +69,7 @@ id test2(A* val) {
   return val;
 }
 
-id test3(void) {
+void test3(void) {
   id a = [[A alloc] init];
   [a autorelease];
 }
diff --git a/clang/test/ARCMT/autoreleases.m.result b/clang/test/ARCMT/autoreleases.m.result
index b3aad804a45be6..29d00ea60deed8 100644
--- a/clang/test/ARCMT/autoreleases.m.result
+++ b/clang/test/ARCMT/autoreleases.m.result
@@ -64,6 +64,6 @@ id test2(A* val) {
   return val;
 }
 
-id test3(void) {
+void test3(void) {
   id a = [[A alloc] init];
 }
diff --git a/clang/test/ARCMT/retains.m b/clang/test/ARCMT/retains.m
index 43a94fc16cecf2..df1badf214b692 100644
--- a/clang/test/ARCMT/retains.m
+++ b/clang/test/ARCMT/retains.m
@@ -21,7 +21,7 @@ @implementation Foo
 
 @synthesize bar;
 
--(id)something {}
+-(id)something { return (id)0; }
 
 -(id)test:(id)obj {
   id x = self.bar;
@@ -44,7 +44,7 @@ -(id)test:(id)obj {
   [x release];
   return [self retain];
 }
-  
+
 - (id)test1 {
   id x=0;
   ([x retain]);
diff --git a/clang/test/ARCMT/retains.m.result b/clang/test/ARCMT/retains.m.result
index 4e720d6bb4c112..211c4b50f53519 100644
--- a/clang/test/ARCMT/retains.m.result
+++ b/clang/test/ARCMT/retains.m.result
@@ -21,7 +21,7 @@ id IhaveSideEffect(void);
 
 @synthesize bar;
 
--(id)something {}
+-(id)something { return (id)0; }
 
 -(id)test:(id)obj {
   id x = self.bar;
@@ -39,7 +39,7 @@ id IhaveSideEffect(void);
   // do stuff with x;
   return self;
 }
-  
+
 - (id)test1 {
   id x=0;
   return (((x)));
diff --git a/clang/test/AST/ast-dump-cxx2b-deducing-this.cpp b/clang/test/AST/ast-dump-cxx2b-deducing-this.cpp
index 1b385e0fc33319..854d12b4cdba6e 100644
--- a/clang/test/AST/ast-dump-cxx2b-deducing-this.cpp
+++ b/clang/test/AST/ast-dump-cxx2b-deducing-this.cpp
@@ -5,7 +5,7 @@ struct S {
   int f(this S&);
 };
 
-int main() {
+void main() {
   S s;
   int x = s.f();
   // CHECK: CallExpr 0x{{[^ ]*}} <col:11, col:15> 'int
diff --git a/clang/test/AST/ast-dump-special-member-functions.cpp b/clang/test/AST/ast-dump-special-member-functions.cpp
index b98c90f6760434..0fe2cee615c826 100644
--- a/clang/test/AST/ast-dump-special-member-functions.cpp
+++ b/clang/test/AST/ast-dump-special-member-functions.cpp
@@ -253,25 +253,25 @@ struct TrivialCopyAssignment {
 struct NontrivialCopyAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct NontrivialCopyAssignment definition
   // CHECK: CopyAssignment {{.*}}non_trivial{{.*}}
-  NontrivialCopyAssignment& operator=(const NontrivialCopyAssignment&) {}
+  NontrivialCopyAssignment& operator=(const NontrivialCopyAssignment&) { return *this; }
 };
 
 struct CopyAssignmentHasConstParam {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct CopyAssignmentHasConstParam definition
   // CHECK: CopyAssignment {{.*}}has_const_param{{.*}}
-  CopyAssignmentHasConstParam& operator=(const CopyAssignmentHasConstParam&) {}
+  CopyAssignmentHasConstParam& operator=(const CopyAssignmentHasConstParam&) { return *this; }
 };
 
 struct CopyAssignmentDoesNotHaveConstParam {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct CopyAssignmentDoesNotHaveConstParam definition
   // CHECK-NOT: CopyAssignment {{.*}} has_const_param{{.*}}
-  CopyAssignmentDoesNotHaveConstParam& operator=(CopyAssignmentDoesNotHaveConstParam&) {}
+  CopyAssignmentDoesNotHaveConstParam& operator=(CopyAssignmentDoesNotHaveConstParam&) { return *this; }
 };
 
 struct UserDeclaredCopyAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct UserDeclaredCopyAssignment definition
   // CHECK: CopyAssignment {{.*}}user_declared{{.*}}
-  UserDeclaredCopyAssignment& operator=(const UserDeclaredCopyAssignment&) {}
+  UserDeclaredCopyAssignment& operator=(const UserDeclaredCopyAssignment&) { return *this; }
 };
 
 struct NonUserDeclaredCopyAssignment {
@@ -288,7 +288,7 @@ struct NeedsImplicitCopyAssignment {
 struct DoesNotNeedImplicitCopyAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct DoesNotNeedImplicitCopyAssignment definition
   // CHECK-NOT: CopyAssignment {{.*}}needs_implicit{{.*}}
-  DoesNotNeedImplicitCopyAssignment& operator=(const DoesNotNeedImplicitCopyAssignment&) {}
+  DoesNotNeedImplicitCopyAssignment& operator=(const DoesNotNeedImplicitCopyAssignment&) { return *this; }
 };
 
 struct DeclaresCopyAssignment {
@@ -352,13 +352,13 @@ struct TrivialMoveAssignment {
 struct NontrivialMoveAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct NontrivialMoveAssignment definition
   // CHECK: MoveAssignment {{.*}}non_trivial{{.*}}
-  NontrivialMoveAssignment& operator=(NontrivialMoveAssignment&&) {}
+  NontrivialMoveAssignment& operator=(NontrivialMoveAssignment&&) { return *this; }
 };
 
 struct UserDeclaredMoveAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct UserDeclaredMoveAssignment definition
   // CHECK: MoveAssignment {{.*}}user_declared{{.*}}
-  UserDeclaredMoveAssignment& operator=(UserDeclaredMoveAssignment&&) {}
+  UserDeclaredMoveAssignment& operator=(UserDeclaredMoveAssignment&&) { return *this; }
 };
 
 struct NonUserDeclaredMoveAssignment {
@@ -375,7 +375,7 @@ struct NeedsImplicitMoveAssignment {
 struct DoesNotNeedImplicitMoveAssignment {
   // CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct DoesNotNeedImplicitMoveAssignment definition
   // CHECK-NOT: MoveAssignment {{.*}}needs_implicit{{.*}}
-  DoesNotNeedImplicitMoveAssignment& operator=(DoesNotNeedImplicitMoveAssignment&&) {}
+  DoesNotNeedImplicitMoveAssignment& operator=(DoesNotNeedImplicitMoveAssignment&&) { return *this; }
 };
 
 struct MoveAssignmentNeedsOverloadResolution : virtual DeletedDestructor {
diff --git a/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist b/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist
index 32244329c434aa..8b8cc3239bd4bd 100644
--- a/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist
+++ b/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist
@@ -6151,7 +6151,7 @@
    <key>type</key><string>Argument with &apos;nonnull&apos; attribute passed null</string>
    <key>check_name</key><string>core.NonNullParamChecker</string>
    <!-- This hash is experimental and going to change! -->
-   <key>issue_hash_content_of_line_in_context</key><string>c0b359a043c633f1b8d1581f68743361</string>
+   <key>issue_hash_content_of_line_in_context</key><string>4c580a2a9cf15947fa485a0a9e625306</string>
   <key>issue_context_kind</key><string>function</string>
   <key>issue_context</key><string>RDar13295437</string>
   <key>issue_hash_function_offset</key><string>3</string>
diff --git a/clang/test/Analysis/const-method-call.cpp b/clang/test/Analysis/const-method-call.cpp
index 7da7ca5554a23e..b37ce17447bdd2 100644
--- a/clang/test/Analysis/const-method-call.cpp
+++ b/clang/test/Analysis/const-method-call.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
 
 void clang_analyzer_eval(bool);
 
diff --git a/clang/test/Analysis/inline-unique-reports.c b/clang/test/Analysis/inline-unique-reports.c
index e58870ea74ab83..306e314a94e437 100644
--- a/clang/test/Analysis/inline-unique-reports.c
+++ b/clang/test/Analysis/inline-unique-reports.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=plist -Wno-error=implicit-int -o %t > /dev/null 2>&1
+// RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=plist -Wno-error=implicit-int -Wno-error=return-type -o %t > /dev/null 2>&1
 // RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/inline-unique-reports.c.plist -
 
 static inline bug(int *p) {
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index f2f8975b5f0e21..0dc667bc1ed505 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -1914,8 +1914,8 @@ variable 'buf', which is not memory allocated by 'malloc()' [unix.Malloc]}}
 
 (*crash_a)(); // expected-warning{{type specifier missing}}
 // A CallEvent without a corresponding FunctionDecl.
-crash_b() { crash_a(); } // no-crash
-// expected-warning@-1{{type specifier missing}} expected-warning@-1{{non-void}}
+crash_b() { crash_a(); return 0; } // no-crash
+// expected-warning@-1{{type specifier missing}}
 
 long *global_a;
 void realloc_crash(void) {
diff --git a/clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m b/clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
index bfc3cb92b639af..0dfeb298db7426 100644
--- a/clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
+++ b/clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
@@ -1,8 +1,8 @@
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin8 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.1 2>&1
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -triple i386-apple-darwin8 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.1 2>&1
 // RUN: FileCheck -input-file=%t.1 -check-prefix=CHECK-darwin8 %s
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.2 2>&1
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.2 2>&1
 // RUN: FileCheck -input-file=%t.2 -check-prefix=CHECK-darwin9 %s
-// RUN: %clang_analyze_cc1 -triple thumbv6-apple-ios4.0 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.3 2>&1
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -triple thumbv6-apple-ios4.0 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.3 2>&1
 // RUN: FileCheck -input-file=%t.3 -check-prefix=CHECK-darwin9 %s
 
 @interface MyClass {}
@@ -25,53 +25,53 @@ - (void)voidM {}
 @end
 
 void createFoo(void) {
-  MyClass *obj = 0;  
-  
+  MyClass *obj = 0;
+
   void *v = [obj voidPtrM]; // no-warning
   int i = [obj intM]; // no-warning
 }
 
 void createFoo2(void) {
-  MyClass *obj = 0;  
-  
+  MyClass *obj = 0;
+
   long double ld = [obj longDoubleM];
 }
 
 void createFoo3(void) {
   MyClass *obj;
-  obj = 0;  
-  
+  obj = 0;
+
   long long ll = [obj longlongM];
 }
 
 void createFoo4(void) {
-  MyClass *obj = 0;  
-  
+  MyClass *obj = 0;
+
   double d = [obj doubleM];
 }
 
 void createFoo5(void) {
-  MyClass *obj = (id)@"";  
-  
+  MyClass *obj = (id)@"";
+
   double d = [obj doubleM]; // no-warning
 }
 
 void createFoo6(void) {
   MyClass *obj;
-  obj = 0;  
-  
+  obj = 0;
+
   unsigned long long ull = [obj unsignedLongLongM];
 }
 
 void handleNilPruneLoop(MyClass *obj) {
   if (!!obj)
     return;
-  
+
   // Test if [obj intM] evaluates to 0, thus pruning the entire loop.
   for (int i = 0; i < [obj intM]; i++) {
     long long j = [obj longlongM];
   }
-  
+
   long long j = [obj longlongM];
 }
 
diff --git a/clang/test/Analysis/novoidtypecrash.c b/clang/test/Analysis/novoidtypecrash.c
index 197516a2596187..5af30c20104386 100644
--- a/clang/test/Analysis/novoidtypecrash.c
+++ b/clang/test/Analysis/novoidtypecrash.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -std=c89 -Wno-int-conversion -analyzer-checker=core %s
+// RUN: %clang_analyze_cc1 -Wno-error=return-type -std=c89 -Wno-int-conversion -analyzer-checker=core %s
 x;
 y(void **z) { // no-crash
   *z = x;
diff --git a/clang/test/Analysis/plist-output.m b/clang/test/Analysis/plist-output.m
index 96123243a833a0..b89aab0a7c4cfd 100644
--- a/clang/test/Analysis/plist-output.m
+++ b/clang/test/Analysis/plist-output.m
@@ -177,7 +177,7 @@ - (void)test {
 
 struct  RDar13295437_S { int *i; };
 
-int  RDar13295437(void) {
+void RDar13295437(void) {
   struct RDar13295437_S s = {0};
   struct RDar13295437_S *sp = &s;
   RDar13295437_f(sp->i);
diff --git a/clang/test/Analysis/plist-stats-output.c b/clang/test/Analysis/plist-stats-output.c
index 4bcae557d9276d..42e0a802d3e377 100644
--- a/clang/test/Analysis/plist-stats-output.c
+++ b/clang/test/Analysis/plist-stats-output.c
@@ -2,7 +2,7 @@
 // REQUIRES: asserts
 // RUN: FileCheck --input-file=%t.plist %s
 
-int foo(void) {}
+void foo(void) {}
 
 
 // CHECK:  <key>diagnostics</key>
diff --git a/clang/test/Analysis/scopes-cfg-output.cpp b/clang/test/Analysis/scopes-cfg-output.cpp
index 5e6706602d4564..c082bb179545fa 100644
--- a/clang/test/Analysis/scopes-cfg-output.cpp
+++ b/clang/test/Analysis/scopes-cfg-output.cpp
@@ -1074,7 +1074,7 @@ void test_switch_with_compound_with_default() {
 // CHECK-NEXT:   Succs (1): B4
 // CHECK:      [B0 (EXIT)]
 // CHECK-NEXT:   Preds (1): B1
-int test_switch_with_compound_without_default() {
+void test_switch_with_compound_without_default() {
   char c = '1';
   switch (int i = getX()) {
     case 0:
diff --git a/clang/test/Analysis/structured_bindings.cpp b/clang/test/Analysis/structured_bindings.cpp
index 7004c2e7dcf43f..989c584189ab2d 100644
--- a/clang/test/Analysis/structured_bindings.cpp
+++ b/clang/test/Analysis/structured_bindings.cpp
@@ -3,10 +3,10 @@
 void clang_analyzer_eval(bool);
 
 struct s { int a; };
-int foo() {
+void foo() {
   auto [a] = s{1};
   clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
-} // expected-warning{{non-void function does not return a value}}
+}
 
 struct s2 {
   int &x;
diff --git a/clang/test/CXX/drs/cwg605.cpp b/clang/test/CXX/drs/cwg605.cpp
index 2fd9e8155bf77b..b98c483f3118eb 100644
--- a/clang/test/CXX/drs/cwg605.cpp
+++ b/clang/test/CXX/drs/cwg605.cpp
@@ -12,7 +12,7 @@ template <class T>
 static T f(T t) {}
 
 template <>
-int f(int t) {}
+int f(int t) { return 0; }
 
 void g(int a) {
   f(a);
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
index 2a99ff0ea44f90..a07ee2213ce40c 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
@@ -3,7 +3,7 @@
 // An attribute-specifier-seq in a lambda-declarator appertains to the
 // type of the corresponding function call operator.
 void test_attributes() {
-  auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-warning{{on-void lambda does not return a value in all control paths}}
+  auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-error{{non-void lambda does not return a value in all control paths}}
 
   // FIXME: GCC accepts the [[gnu::noreturn]] attribute here.
   auto nrl2 = []() [[gnu::noreturn]] { return; }; // expected-warning{{attribute 'noreturn' ignored}}
@@ -25,7 +25,7 @@ void test_quals() {
   lc();
 
   auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \
-                             // expected-note{{method is not marked volatile}} 
+                             // expected-note{{method is not marked volatile}}
   const decltype(ml) mlc = ml;
   ml();
   mlc(); // expected-error{{no matching function for call to object of type}}
@@ -56,8 +56,8 @@ void test_exception_spec() {
   auto ntl1 = []() throw() {};
   auto ntl2 = []() noexcept(true) {};
   auto ntl3 = []() noexcept {};
-  static_assert(noexcept(ntl1()), "lambda cannot throw");  
-  static_assert(noexcept(ntl2()), "lambda cannot throw");  
-  static_assert(noexcept(ntl3()), "lambda cannot throw");  
+  static_assert(noexcept(ntl1()), "lambda cannot throw");
+  static_assert(noexcept(ntl2()), "lambda cannot throw");
+  static_assert(noexcept(ntl3()), "lambda cannot throw");
 }
 
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp b/clang/test/C...
[truncated]

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for working on this.

It seems a bit ambitious to do this at the end of the cycle (no time to react to feedback).

However, we might want to take what is offered and minimize churn.

How about

  • in this patch you modify the tests, and the test runner (hopefully lit config can do that, I haven't checked) such that ~all tests (including new ones) use -Werror=return-type (we might want to have tests where it's just a warning to make sure this still works)

  • In a separate patch we flip the default.

it would be a lot less disruptive in case we need to revert something.

WDYT?

@Sirraide Sirraide changed the title [Clang] Make -Wreturn-type default to an error. [Clang] [NFC] Fix unintended -Wreturn-type warnings everywhere in the test suite Jan 18, 2025
@Sirraide
Copy link
Member Author

Sirraide commented Jan 18, 2025

How about

  • in this patch you modify the tests, and the test runner (hopefully lit config can do that, I haven't checked) such that ~all tests (including new ones) use -Werror=return-type (we might want to have tests where it's just a warning to make sure this still works)
  • In a separate patch we flip the default.

Yeah, I agree that that makes sense (I was thinking about splitting it too since there are so many effectively NFC changes that are part of this...); I’ve changed this pr to just refactor all the tests. I don’t expect too many new tests to be added between when this is merged and when the actual change is made to make the warning an error since the vast majority of the tests I had to change (at least of the ones that I spent the most time refactoring) are fairly old (from around 2007–2010).

@Sirraide
Copy link
Member Author

It seems a bit ambitious to do this at the end of the cycle (no time to react to feedback).

Yeah, on the one hand, we could wait until after the branch before we make this change, but on the other hand, doing it now might result in more feedback as to how disruptive defaulting the warning to an error would actually end up being?

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable.
anything you can do to reduce white space only changes?

Comment on lines +304 to +305
// FIXME: We can't actually do 'return m[r][c]' here currently.
static double d;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we supposed to be able to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not entirely sure candidly. On the one hand, maybe exposing a reference to a matrix element is just fundamentally a bad idea, but on the other, support for matrix types is also incomplete in other areas (e.g. list initialisation doesn’t work at all, not even e.g. some_matrix_type{}). I don’t really know which one is the case here, so I felt like I should maybe point out why I’m solving the problem of having to return a double& in a weird way here.

@Sirraide
Copy link
Member Author

anything you can do to reduce white space only changes?

Er, unless there is some way to do it w/ git that I’m not aware of it’d be pretty complicated for me because my IDE deletes trailing whitespace on save (and I’m pretty sure that’s true for a lot of other people too), so it becomes fairly cumbersome to try and edit a file w/o doing that—that and I am so used to it doing that that I’m pretty sure e.g. disabling that setting would have the opposite effect and introduce a bunch of trailing whitespace changes in every file I edit... :(

@Sirraide Sirraide force-pushed the wreturn-type-attempt-2 branch from 96ddccb to e0099cf Compare January 18, 2025 16:45
@Sirraide
Copy link
Member Author

Update: thanks to @cor3ntin and some git black magic, I was able to remove the whitespace-only changes.

@Sirraide Sirraide merged commit 12f78e7 into llvm:main Jan 18, 2025
8 checks passed
Sirraide added a commit that referenced this pull request Feb 20, 2025
…123470)

With the goal of eventually being able to make `-Wreturn-type` default to an 
error in all language modes, this is a follow-up to #123464 and updates even
more tests, mainly clang-tidy and clangd tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:SystemZ backend:X86 clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants