[clang] Add new flag -Wreturn-mismatch (PR #82872)

Bhuminjay Soni via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 24 00:33:53 PST 2024


https://github.com/11happy created https://github.com/llvm/llvm-project/pull/82872

**Overview:**
This pull request fixes #72116 where a new flag is introduced for compatibility with GCC 14, the functionality of -Wreturn-type is modified to split some of its behaviors into -Wreturn-mismatch 

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-02-24 13-56-24](https://github.com/llvm/llvm-project/assets/76656712/3a0303c1-22e5-4b74-a674-6b772752ed2e)
- Sample working:
```
int foo(int x){
  x = 1;
  return;
}
```
![Screenshot from 2024-02-24 14-01-21](https://github.com/llvm/llvm-project/assets/76656712/2352588b-17be-40b5-869e-66fe3af83a95)




**Dependencies:**
- No dependencies on other pull requests.



>From 557ee75d60f0fdb4dd2b353c819b4f22f71b46d7 Mon Sep 17 00:00:00 2001
From: 11happy <soni5happy at gmail.com>
Date: Sat, 24 Feb 2024 13:50:30 +0530
Subject: [PATCH] add new flag -Wreturn-mismatch

Signed-off-by: 11happy <soni5happy at gmail.com>
---
 clang/include/clang/Basic/DiagnosticGroups.td    | 1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +++---
 clang/test/Analysis/null-deref-ps.c              | 4 ++--
 clang/test/CodeGen/statements.c                  | 2 +-
 clang/test/CodeGen/volatile-1.c                  | 2 +-
 clang/test/Sema/return-silent.c                  | 2 +-
 clang/test/Sema/return.c                         | 2 +-
 7 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..7a786a24083583 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -607,6 +607,7 @@ def RedundantMove : DiagGroup<"redundant-move">;
 def Register : DiagGroup<"register", [DeprecatedRegister]>;
 def ReturnTypeCLinkage : DiagGroup<"return-type-c-linkage">;
 def ReturnType : DiagGroup<"return-type", [ReturnTypeCLinkage]>;
+def ReturnMismatch : DiagGroup<"return-mismatch">;
 def BindToTemporaryCopy : DiagGroup<"bind-to-temporary-copy",
                                     [CXX98CompatBindToTemporaryCopy]>;
 def SelfAssignmentField : DiagGroup<"self-assign-field">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 24d32cb87c89e2..7057b4b2123671 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10212,14 +10212,14 @@ def warn_second_parameter_to_va_arg_never_compatible : Warning<
 
 def warn_return_missing_expr : Warning<
   "non-void %select{function|method}1 %0 should return a value">, DefaultError,
-  InGroup<ReturnType>;
+  InGroup<ReturnMismatch>;
 def ext_return_missing_expr : ExtWarn<
   "non-void %select{function|method}1 %0 should return a value">, DefaultError,
-  InGroup<ReturnType>;
+  InGroup<ReturnMismatch>;
 def ext_return_has_expr : ExtWarn<
   "%select{void function|void method|constructor|destructor}1 %0 "
   "should not return a value">,
-  DefaultError, InGroup<ReturnType>;
+  DefaultError, InGroup<ReturnMismatch>;
 def ext_return_has_void_expr : Extension<
   "void %select{function|method|block}1 %0 should not return void expression">;
 def err_return_init_list : Error<
diff --git a/clang/test/Analysis/null-deref-ps.c b/clang/test/Analysis/null-deref-ps.c
index d80de15c05a3fe..2682ad02ee37f9 100644
--- a/clang/test/Analysis/null-deref-ps.c
+++ b/clang/test/Analysis/null-deref-ps.c
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -verify %s -Wno-error=return-type
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type -Wno-error=return-mismatch
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -verify %s -Wno-error=return-type -Wno-error=return-mismatch
 
 typedef unsigned uintptr_t;
 
diff --git a/clang/test/CodeGen/statements.c b/clang/test/CodeGen/statements.c
index 07ae075d6d807e..76f4f254dfd1dc 100644
--- a/clang/test/CodeGen/statements.c
+++ b/clang/test/CodeGen/statements.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -Wno-error=return-type -Wno-error=int-conversion %s -emit-llvm-only
+// RUN: %clang_cc1 -Wno-error=return-type -Wno-error=return-mismatch -Wno-error=int-conversion %s -emit-llvm-only
 // REQUIRES: LP64
 
 // Mismatched type between return and function result.
diff --git a/clang/test/CodeGen/volatile-1.c b/clang/test/CodeGen/volatile-1.c
index cd919c78989fe2..80c40d21cf593e 100644
--- a/clang/test/CodeGen/volatile-1.c
+++ b/clang/test/CodeGen/volatile-1.c
@@ -1,5 +1,5 @@
 // XFAIL: target=aarch64-pc-windows-msvc
-// RUN: %clang_cc1 -Wno-return-type -Wno-unused-value -emit-llvm %s -w -o - | FileCheck %s
+// RUN: %clang_cc1 -Wno-return-type -Wno-return-mismatch -Wno-unused-value -emit-llvm %s -w -o - | FileCheck %s
 
 // CHECK: @i = {{(dso_local )?}}global [[INT:i[0-9]+]] 0
 volatile int i, j, k;
diff --git a/clang/test/Sema/return-silent.c b/clang/test/Sema/return-silent.c
index 720128d7ea60b2..e510c9c678c2bd 100644
--- a/clang/test/Sema/return-silent.c
+++ b/clang/test/Sema/return-silent.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -Wno-return-type -fsyntax-only -verify
+// RUN: %clang_cc1 %s -Wno-return-type -Wno-return-mismatch -fsyntax-only -verify
 // expected-no-diagnostics
 
 int t14(void) {
diff --git a/clang/test/Sema/return.c b/clang/test/Sema/return.c
index 14d5300e819492..b4f3f132dce7a1 100644
--- a/clang/test/Sema/return.c
+++ b/clang/test/Sema/return.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -fsyntax-only -Wignored-qualifiers -Wno-error=return-type -Wno-error=implicit-int -verify -fblocks -Wno-unreachable-code -Wno-unused-value -Wno-strict-prototypes
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -fsyntax-only -Wignored-qualifiers -Wno-error=return-type -Wno-error=return-mismatch -Wno-error=implicit-int -verify -fblocks -Wno-unreachable-code -Wno-unused-value -Wno-strict-prototypes
 
 // clang emits the following warning by default.
 // With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the



More information about the cfe-commits mailing list