From 4fcae53ed9180dfbb41c922540e7db769bd118d8 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 10 Jul 2020 16:13:26 -0400 Subject: some cleanup --- Makefile | 3 ++- build.sh | 5 ++++- copy.c | 2 ++ identifiers.c | 13 ++----------- main.c | 1 - test.toc | 8 ++++++-- toc.c | 15 +++++++++++++-- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 856e88c..ac7ede4 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ debug: *.[ch] build.sh ./build.sh release: *.[ch] build.sh ./build.sh release - +profile: *.[ch] build.sh + ./build.sh profile clean: rm toc *.o diff --git a/build.sh b/build.sh index 17eaf9f..f0ba897 100755 --- a/build.sh +++ b/build.sh @@ -47,10 +47,13 @@ if [ "$CC" = "gcc" ]; then elif [ "$CC" = "clang" ]; then DEBUG_FLAGS="$DEBUG_FLAGS -no-pie -gdwarf-2 -pipe" fi -RELEASE_FLAGS="-O3 -s -DNDEBUG $WARNINGS -std=c11" +RELEASE_FLAGS="-O3 -s -DNDEBUG $WARNINGS" +PROFILE_FLAGS="-O3 -g -pg -DNDEBUG $WARNINGS" if [ "$1" = "release" ]; then FLAGS="$RELEASE_FLAGS $ADDITIONAL_FLAGS" +elif [ "$1" = "profile" ]; then + FLAGS="$PROFILE_FLAGS $ADDITIONAL_FLAGS" else FLAGS="$DEBUG_FLAGS $ADDITIONAL_FLAGS" fi diff --git a/copy.c b/copy.c index ea5a9d4..96cb8fa 100644 --- a/copy.c +++ b/copy.c @@ -138,7 +138,9 @@ static void copy_type(Copier *c, Type *out, Type *in) { *outfn = *infn; size_t constness_bytes = (ntypes-1) * sizeof *outfn->constness; outfn->constness = allocr_malloc(c->allocr, constness_bytes); + gcc_no_bounds_warnings_start memmove(outfn->constness, infn->constness, constness_bytes); + gcc_no_bounds_warnings_end outfn->types = NULL; arr_set_lena(outfn->types, ntypes, c->allocr); diff --git a/identifiers.c b/identifiers.c index c3f64b7..3232811 100644 --- a/identifiers.c +++ b/identifiers.c @@ -80,18 +80,9 @@ static char *ident_to_str(Identifier i) { char *str = err_malloc(i->len + 1); /* for some reason, GCC thinks that i->len is -1 when this is called from type_to_str_ (in release mode) */ -#if !defined(__clang__) && defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstringop-overflow" -#pragma GCC diagnostic ignored "-Wrestrict" -#pragma GCC diagnostic ignored "-Warray-bounds" -#endif +gcc_no_bounds_warnings_start memcpy(str, i->str, i->len); - - -#if !defined(__clang__) && defined(__GNUC__) -#pragma GCC diagnostic pop -#endif +gcc_no_bounds_warnings_end str[i->len] = 0; return str; } diff --git a/main.c b/main.c index 033b58f..3e06c41 100644 --- a/main.c +++ b/main.c @@ -8,7 +8,6 @@ /* @TODO: -start passing Types instead of pointers to Type figure out how printf is gonna work if we do #include "foo.toc", bar; and foo.toc fails, bar should be declared as TYPE_UNKNOWN (right now it's undeclared) fix #foreign not at global scope - right now the cgen'd definition doesn't use the proper type diff --git a/test.toc b/test.toc index 536cf34..48c31a6 100644 --- a/test.toc +++ b/test.toc @@ -2,8 +2,12 @@ #include "std/mem.toc"; main ::= fn() { - for i, v : (float, int) = 10,-1,.0 { - io.puti(i as int); + file, err := io.fopen_write("test.txt"); + + for i := 0.,1000000 { + io.fputs(file, "!"); } + + io.fclose(file); } main(); diff --git a/toc.c b/toc.c index c63dc36..6f4ca1d 100644 --- a/toc.c +++ b/toc.c @@ -46,14 +46,25 @@ #endif -#else +#else /* __STDC_VERSION >= 201112 ... */ #define toc_alignof sizeof #define possibly_static_assert(cond) assert(cond) +#endif /* __STDC_VERSION >= 201112 ... */ + +/* this is to prevent erroneous warnings from GCC (v. 8.3.0) with -O3 */ +#if !defined(__clang__) && defined(__GNUC__) +#define gcc_no_bounds_warnings_start _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wstringop-overflow\"") \ + _Pragma("GCC diagnostic ignored \"-Wrestrict\"") \ + _Pragma("GCC diagnostic ignored \"-Warray-bounds\"") +#define gcc_no_bounds_warnings_end _Pragma("GCC diagnostic pop") +#else +#define gcc_no_bounds_warnings_start +#define gcc_no_bounds_warnings_end #endif - #include "types.h" /* forward declarations for debugging */ -- cgit v1.2.3