From e754dd54bac1bf0443cf9c7f477af4d0675c1f0a Mon Sep 17 00:00:00 2001 From: Igor Molchanov Date: Thu, 7 Feb 2019 11:11:13 +0300 Subject: [PATCH] Some compatibility fixes for Elbrus compiler (and others based on EDG front end) (#157) * Reduce alignment to 16 due to stack variables alignment On some archs (e.g. elbrus) there is no possibility to align variables on stack by more that 16 bytes. * Added check for -Wno-typedef-redefinition In C11, there is legal to redefine typedef with the same type, but some compilers like elbrus's lcc and, probably, intel's icc generate a warning about that. So we disable it. * Typo fix * Fix __builtin_unreachable() warning on some frontends like EDG * Added check for __attribute__((designated_init)) It doesn't work for elbrus'c lcc and clang; but clang does not generate warning by default, but we still disable it just in case. * A hack to avoid -Wtype-limits for compilers with unsigned enums * Rewritten unreachable __builtin_unreachable() behavior. According to https://bugs.llvm.org/show_bug.cgi?id=13910, old clang versions also suffer from this issue along with lcc. And also this warning option is removed from gcc since 4.5.0, and it's likely there is no unreachable code analysis at all: https://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Warning-Options.html * Fixed unneeded stray UNREACHABLE which caused warnings * Removed alignas() which is unneeded after lowering alignment requirements * Removed a hack of -Wunreachable-code disabling on certain compilers Actually, there was a wrong opinion that most of unreachable code warnings are produced by __builtin_unreachable() itself, not the certain use of it. After commit 36493d3, it is finally figured out that it wasn't the case. * Added dummy element to a struct in a test for designated_init This test will enexpectedly fail when GNU extensions are not available --- meson.build | 3 ++- src/entity.h | 2 -- src/renderer/common/sprite_batch.c | 2 +- src/util/compat.h | 2 +- src/util/meson.build | 10 ++++++++++ src/version.h | 6 +++++- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index afb1acfb..cfdc8f7d 100644 --- a/meson.build +++ b/meson.build @@ -49,6 +49,7 @@ taisei_c_args = cc.get_supported_arguments( '-Winit-self', '-Wlogical-op', '-Wmissing-prototypes', + '-Wno-typedef-redefinition', '-Wno-long-long', '-Wnull-dereference', '-Wparentheses', @@ -56,8 +57,8 @@ taisei_c_args = cc.get_supported_arguments( '-Wsometimes-uninitialized', '-Wstrict-prototypes', '-Wtype-limits', - '-Wunneeded-internal-declaration', '-Wunreachable-code', + '-Wunneeded-internal-declaration', '-Wunreachable-code-loop-increment', ) diff --git a/src/entity.h b/src/entity.h index af9c19cf..95ca2bca 100644 --- a/src/entity.h +++ b/src/entity.h @@ -108,8 +108,6 @@ static inline attr_must_inline const char* ent_type_name(EntityType type) { #undef ENT_TYPE default: return "ENT_INVALID"; } - - UNREACHABLE; } #define ENT_TYPE_ID(typename) (_ENT_TYPEID_##typename) diff --git a/src/renderer/common/sprite_batch.c b/src/renderer/common/sprite_batch.c index e72b49ea..e963c6f6 100644 --- a/src/renderer/common/sprite_batch.c +++ b/src/renderer/common/sprite_batch.c @@ -183,7 +183,7 @@ void r_flush_sprites(void) { } static void _r_sprite_batch_add(Sprite *spr, const SpriteParams *params, SDL_RWops *stream) { - SpriteAttribs alignas(32) attribs; + SpriteAttribs attribs; r_mat_current(MM_MODELVIEW, attribs.transform); r_mat_current(MM_TEXTURE, attribs.tex_transform); diff --git a/src/util/compat.h b/src/util/compat.h index 8e0395e9..c375b0d5 100644 --- a/src/util/compat.h +++ b/src/util/compat.h @@ -215,7 +215,7 @@ typedef signed char schar; __attribute__ ((always_inline)) // Structure must not be initialized with an implicit (non-designated) initializer. -#if __has_attribute(designated_init) +#if __has_attribute(designated_init) && defined(TAISEI_BUILDCONF_USE_DESIGNATED_INIT) #define attr_designated_init \ __attribute__ ((designated_init)) #else diff --git a/src/util/meson.build b/src/util/meson.build index a0eb019a..d845da3c 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -23,6 +23,16 @@ if is_developer_build util_src += files('debug.c') endif +use_designated_init = cc.compiles(''' +struct { int dummy; } __attribute__((designated_init)) x; +''', name : '__attribute__((designated_init)) with -Werror', args : [ '-Wattributes', '-Werror' ] ) + +if use_designated_init + config.set('TAISEI_BUILDCONF_USE_DESIGNATED_INIT', true) +else + config.set('TAISEI_BUILDCONF_USE_DESIGNATED_INIT', false) +endif + if host_machine.system() == 'windows' # NOTE: Even if we ever build this with something like Midipix, we'd # probably still want to use the winapi implementation of this here. diff --git a/src/version.h b/src/version.h index 5d2d530b..3d010184 100644 --- a/src/version.h +++ b/src/version.h @@ -44,7 +44,11 @@ typedef struct TaiseiVersion { ) typedef enum { - VCMP_MAJOR, + // Start filling this enum from nonzero value. + // This would help avoid a warning on some compilers like + // those with EDG frontend. Actual values of VCMP_... + // don't matter, the thing which does matter is its order. + VCMP_MAJOR = 1, VCMP_MINOR, VCMP_PATCH, VCMP_TWEAK,