Skip to content

[Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present #148552

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
Jul 14, 2025

Conversation

cor3ntin
Copy link
Contributor

Fix a false positve warning which was introduced by #146234.

Fix a false positve warning which was introduced by llvm#146234.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 13, 2025

@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)

Changes

Fix a false positve warning which was introduced by #146234.


Full diff: https://github.com/llvm/llvm-project/pull/148552.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaDeclAttr.cpp (+1-1)
  • (modified) clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp (+22)
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7ebb53318702c..72972221d23c5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1976,7 +1976,7 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) {
       Diags.isIgnored(diag::warn_suggest_noreturn_function, FD->getLocation()))
     return;
 
-  if (!FD->hasAttr<NoReturnAttr>() && !FD->hasAttr<InferredNoReturnAttr>() &&
+  if (!FD->isNoReturn() && !FD->hasAttr<InferredNoReturnAttr>() &&
       isKnownToAlwaysThrow(FD)) {
     NonConstFD->addAttr(InferredNoReturnAttr::CreateImplicit(S.Context));
 
diff --git a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
index 7548ba8904a71..8beffcd39e85c 100644
--- a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
+++ b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
@@ -21,3 +21,25 @@ int ensureZero(int i) {
   if (i == 0) return 0;
   throwError("ERROR"); // no-warning
 }
+
+
+template <typename Ex>
+[[noreturn]]
+void tpl_throws(Ex const& e) {
+    throw e;
+}
+
+[[noreturn]]
+void tpl_throws_test() {
+    tpl_throws(0);
+}
+
+[[gnu::noreturn]]
+int gnu_throws() {
+    throw 0;
+}
+
+[[noreturn]]
+int cxx11_throws() {
+    throw 0;
+}

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for the fix!

@cor3ntin cor3ntin merged commit afffa0d into llvm:main Jul 14, 2025
12 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 14, 2025

LLVM Buildbot has detected a new failure on builder openmp-gcc-x86_64-linux-debian running on gribozavr4 while building clang at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/70/builds/10641

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: test (failure)
******************** TEST 'libomp :: tasking/issue-94260-2.c' FAILED ********************
Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/./bin/clang -fopenmp   -I /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test -L /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -fno-omit-frame-pointer -I /b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test/ompt /b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic && /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/./bin/clang -fopenmp -I /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test -L /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -I /b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test/ompt /b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic
# executed command: /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--

********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants