Skip to content

Commit

Permalink
Change GNUC_NORETURN to NORETURN and define for MSVC too
Browse files Browse the repository at this point in the history
This prevents MSVC warnings after assert(0, ...) at end of functions that
returns a value only at their middle.
  • Loading branch information
ampli committed May 30, 2024
1 parent 267dada commit b4f22e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions link-grammar/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "link-includes.h"
#include "externs.h" // verbosity
#include "utilities.h" // GNUC_NORETURN, STRINGIFY
#include "utilities.h" // NORETURN, STRINGIFY

/* User verbosity levels are 1-4, to be used for user info/debug.
* For now hard-coded numbers are still used instead of D_USER_BASIC/TIMES. */
Expand Down Expand Up @@ -97,8 +97,9 @@ void lg_lib_failure(void);

extern void (* assert_failure_trap)(void);
#define FILELINE __FILE__ ":" STRINGIFY(__LINE__)
NORETURN
void assert_failure(const char[], const char[], const char *, const char *, ...)
GNUC_PRINTF(4,5) GNUC_NORETURN;
GNUC_PRINTF(4,5);

/* Define a private version of assert() with a printf-like error
* message. The C one is not used. */
Expand Down
2 changes: 1 addition & 1 deletion link-grammar/parse/count.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef uint8_t WordIdx_m; /* Storage representation of word index */
const bool ENABLE_WORD_SKIP_VECTOR = true;
const bool ENABLE_MATCH_LIST_CACHE = true;
const bool ENABLE_TABLE_LRCNT = true; // Also controls the above two caches.
const bool USE_TABLE_TRACON = false; // The table is always maintained.
const bool USE_TABLE_TRACON = true; // The table is always maintained.
const bool USE_PSEUDOCOUNT = true; // Controls only the non-cyclic solutions.

typedef struct Table_tracon_s Table_tracon;
Expand Down
11 changes: 7 additions & 4 deletions link-grammar/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ static inline char *_strndupa3(char *new_s, const char *s, size_t n)
* support C11. So it already supports all the features below. */

/* Optimizations etc. that only gcc understands */
/* FIXME: Change to ATTR_* and define also for MSVC. */
/* FIXME: Define also for MSVC. */
#if __GNUC__
#define GCC_DIAGNOSTIC
#define UNREACHABLE(x) (__extension__ ({if (x) __builtin_unreachable();}))
#define GNUC_MALLOC __attribute__ ((__malloc__))
#define GNUC_UNUSED __attribute__ ((__unused__))
#define GNUC_NORETURN __attribute__ ((__noreturn__))
#define NORETURN __attribute__ ((__noreturn__))
#define ATTR_PURE __attribute__ ((__pure__))
#define NO_SAN __attribute__ ((no_sanitize_address, no_sanitize_undefined))

Expand All @@ -271,7 +271,6 @@ static inline char *_strndupa3(char *new_s, const char *s, size_t n)
#else
#define NO_SAN_DICT
#endif

#ifndef DONT_EXPECT
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
Expand All @@ -281,14 +280,18 @@ static inline char *_strndupa3(char *new_s, const char *s, size_t n)
#define UNREACHABLE(x)
#define GNUC_MALLOC
#define GNUC_UNUSED
#define GNUC_NORETURN
#define NORETURN
#define ATTR_PURE
#define NO_SAN_DICT

#define likely(x) x
#define unlikely(x) x
#endif

#ifdef _MSC_VER
#undef NORETURN
#define NORETURN __declspec(noreturn)
#endif

/* Apply a pragma to a specific code section only.
* XXX According to the GCC docs, we cannot use here something like
Expand Down

0 comments on commit b4f22e4

Please sign in to comment.