[PATCH] D66487: Fix -Wimplicit-fallthrough warnings in regcomp.c

Nathan Huckleberry via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 13:00:38 PDT 2019


Nathan-Huckleberry updated this revision to Diff 216221.
Nathan-Huckleberry added a comment.

- Add attribute to compiler.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66487/new/

https://reviews.llvm.org/D66487

Files:
  llvm/include/llvm/Support/Compiler.h
  llvm/lib/Support/regcomp.c


Index: llvm/lib/Support/regcomp.c
===================================================================
--- llvm/lib/Support/regcomp.c
+++ llvm/lib/Support/regcomp.c
@@ -48,6 +48,7 @@
 #include "regex2.h"
 
 #include "llvm/Config/config.h"
+#include "llvm/Support/Compiler.h"
 
 /* character-class table */
 static struct cclass {
@@ -537,7 +538,7 @@
 		break;
 	case '{':		/* okay as ordinary except if digit follows */
 		REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
-		/* FALLTHROUGH */
+		LLVM_FALLTHROUGH;
 	default:
 		ordinary(p, c);
 		break;
@@ -733,7 +734,7 @@
 		break;
 	case '*':
 		REQUIRE(starordinary, REG_BADRPT);
-		/* FALLTHROUGH */
+		LLVM_FALLTHROUGH;
 	default:
 		ordinary(p, (char)c);
 		break;
@@ -1635,7 +1636,7 @@
 					return;
 				}
 			} while (OP(s) != O_QUEST && OP(s) != O_CH);
-			/* fallthrough */
+			LLVM_FALLTHROUGH;
 		default:		/* things that break a sequence */
 			if (newlen > g->mlen) {		/* ends one */
 				start = newstart;
Index: llvm/include/llvm/Support/Compiler.h
===================================================================
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -16,7 +16,9 @@
 
 #include "llvm/Config/llvm-config.h"
 
+#if __cplusplus
 #include <new>
+#endif
 #include <stddef.h>
 
 #if defined(_MSC_VER)
@@ -255,7 +257,11 @@
 #elif !__cplusplus
 // Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
 // error when __has_cpp_attribute is given a scoped attribute in C mode.
-#define LLVM_FALLTHROUGH
+  #if __has_attribute(fallthrough)
+  #define LLVM_FALLTHROUGH __attribute__((fallthorugh))
+  #else
+  #define LLVM_FALLTHROUGH
+  #endif
 #elif __has_cpp_attribute(clang::fallthrough)
 #define LLVM_FALLTHROUGH [[clang::fallthrough]]
 #else
@@ -527,6 +533,7 @@
 #define LLVM_ENABLE_EXCEPTIONS 1
 #endif
 
+#if __cplusplus
 namespace llvm {
 
 /// Allocate a buffer of memory with the given size and alignment.
@@ -570,3 +577,4 @@
 } // End namespace llvm
 
 #endif
+#endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66487.216221.patch
Type: text/x-patch
Size: 2014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190820/de0e72e3/attachment.bin>


More information about the llvm-commits mailing list