]> granicus.if.org Git - llvm/commitdiff
Fix -Wimplicit-fallthrough warnings in regcomp.c
authorNathan Huckleberry <nhuck@google.com>
Wed, 21 Aug 2019 17:07:43 +0000 (17:07 +0000)
committerNathan Huckleberry <nhuck@google.com>
Wed, 21 Aug 2019 17:07:43 +0000 (17:07 +0000)
Summary:
Since clang does not support comment style fallthrough annotations
these should be switched.

Reviewers: aaron.ballman, nickdesaulniers, xbolva00

Reviewed By: aaron.ballman, nickdesaulniers, xbolva00

Subscribers: xbolva00, nickdesaulniers, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66487

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369549 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 43114ad3a43c0e1e74fc38a94c3311dfd1803478..e1f124379ddc6eaf57104cc4da6ddff758823fd5 100644 (file)
@@ -16,7 +16,9 @@
 
 #include "llvm/Config/llvm-config.h"
 
+#ifdef __cplusplus
 #include <new>
+#endif
 #include <stddef.h>
 
 #if defined(_MSC_VER)
 #define LLVM_FALLTHROUGH [[fallthrough]]
 #elif __has_cpp_attribute(gnu::fallthrough)
 #define LLVM_FALLTHROUGH [[gnu::fallthrough]]
-#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
+#elif !defined(__cplusplus) && __has_attribute(fallthrough)
+#define LLVM_FALLTHROUGH __attribute__((fallthrough))
 #elif __has_cpp_attribute(clang::fallthrough)
 #define LLVM_FALLTHROUGH [[clang::fallthrough]]
 #else
@@ -527,6 +527,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
 #define LLVM_ENABLE_EXCEPTIONS 1
 #endif
 
+#ifdef __cplusplus
 namespace llvm {
 
 /// Allocate a buffer of memory with the given size and alignment.
@@ -569,4 +570,5 @@ inline void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment) {
 
 } // End namespace llvm
 
+#endif // __cplusplus
 #endif
index ca283869be988dc88584d98ca61029a435c3aa5b..ee2a1d87a267267689ea403fe2506388dee16c93 100644 (file)
@@ -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 @@ p_ere_exp(struct parse *p)
                break;
        case '{':               /* okay as ordinary except if digit follows */
                REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
-               /* fall through */
+               LLVM_FALLTHROUGH;
        default:
                ordinary(p, c);
                break;
@@ -733,7 +734,7 @@ p_simp_re(struct parse *p,
                break;
        case '*':
                REQUIRE(starordinary, REG_BADRPT);
-               /* fall through */
+               LLVM_FALLTHROUGH;
        default:
                ordinary(p, (char)c);
                break;
@@ -1635,7 +1636,7 @@ findmust(struct parse *p, struct re_guts *g)
                                        return;
                                }
                        } while (OP(s) != O_QUEST && OP(s) != O_CH);
-                       /* fall through */
+                       LLVM_FALLTHROUGH;
                default:                /* things that break a sequence */
                        if (newlen > g->mlen) {         /* ends one */
                                start = newstart;