[clang] [clang] Add -Wimplicit-fallthrough to -Wextra (PR #97926)
Max Coplan via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 6 17:28:45 PDT 2024
https://github.com/vegerot created https://github.com/llvm/llvm-project/pull/97926
This patch adds -Wimplicit-fallthrough to -Wextra. GCC already includes it in -Wextra.
This patch also adds a test to check that -Wimplicit-fallthrough is included in -Wextra.
Note: This patch may regress performance when building with -Wextra.
This is because -Wextra requires forming a CFG for every function.
>From 2ba0fe208a6f676cc6ab6ccabb015bb8788e145e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Max=20=F0=9F=91=A8=F0=9F=8F=BD=E2=80=8D=F0=9F=92=BB=20Copl?=
=?UTF-8?q?an?= <mchcopl at gmail.com>
Date: Sat, 6 Jul 2024 17:22:55 -0700
Subject: [PATCH] [clang] Add -Wimplicit-fallthrough to -Wextra
This patch adds -Wimplicit-fallthrough to -Wextra. GCC already includes it in -Wextra.
This patch also adds a test to check that -Wimplicit-fallthrough is included in -Wextra.
Note: This patch may regress performance when building with -Wextra.
This is because -Wextra requires forming a CFG for every function.
---
clang/include/clang/Basic/DiagnosticGroups.td | 1 +
clang/test/Sema/fallthrough-attr.c | 1 +
clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp | 1 +
3 files changed, 3 insertions(+)
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e2..a875f665b10f9d 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1063,6 +1063,7 @@ def Extra : DiagGroup<"extra", [
StringConcatation,
FUseLdPath,
CastFunctionTypeMismatch,
+ ImplicitFallthrough,
]>;
def Most : DiagGroup<"most", [
diff --git a/clang/test/Sema/fallthrough-attr.c b/clang/test/Sema/fallthrough-attr.c
index de50ebf39d42f6..6cc19136f30a7e 100644
--- a/clang/test/Sema/fallthrough-attr.c
+++ b/clang/test/Sema/fallthrough-attr.c
@@ -2,6 +2,7 @@
// RUN: %clang_cc1 -fsyntax-only -std=gnu99 -verify -Wimplicit-fallthrough %s
// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify -Wimplicit-fallthrough %s
// RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wextra %s
// RUN: %clang_cc1 -fsyntax-only -std=c2x -DC2X -verify -Wimplicit-fallthrough %s
int fallthrough_attribute_spelling(int n) {
diff --git a/clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp b/clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp
index 11df2cbfb53f09..cbbff1f1793b88 100644
--- a/clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp
+++ b/clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp
@@ -3,6 +3,7 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCLANG_PREFIX -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[fallthrough]] -DUNCHOSEN=[[clang::fallthrough]] %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wextra -DCOMMAND_LINE_FALLTHROUGH=[[fallthrough]] -DUNCHOSEN=[[clang::fallthrough]] %s
int fallthrough_compatibility_macro_from_command_line(int n) {
switch (n) {
More information about the cfe-commits
mailing list