From 611348e67bd45dcf0322e9a32ce7160c008c3e26 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 20 Dec 2020 09:44:30 +0100 Subject: [PATCH] glr2.cc: more checks * data/skeletons/glr2.cc: Clarify use of magic numbers. (glr_stack_item::getState): Check the returned state. --- README-hacking.md | 10 ++++++++++ data/skeletons/glr2.cc | 15 +++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README-hacking.md b/README-hacking.md index 028feae2..538f08e2 100644 --- a/README-hacking.md +++ b/README-hacking.md @@ -487,6 +487,16 @@ useful. Here's one way to set ASAN up with GCC 10 on Mac Ports $ make check-local TESTSUITEFLAGS='-j5 -k cex' ASAN_OPTIONS=detect_leaks=1 +5. You might need a suppression file. See + https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer#suppressions. + With G++ on a Mac, you might need a suppression file (say + leak.suppression) that contains: + + leak:std::clog + + and pass the additional flags + `LSAN_OPTIONS=suppressions=$PWD/leak.suppressions,print_suppressions=0` + ## make maintainer-check-valgrind This target uses valgrind both to check bison, and the generated parsers. diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc index 0a97937c..abd90256 100644 --- a/data/skeletons/glr2.cc +++ b/data/skeletons/glr2.cc @@ -1215,7 +1215,7 @@ public: glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW : is_state_ (other.is_state_)]b4_parse_assert_if([[ - , magic_ (0xDEAD1ACC)]])[ + , magic_ (MAGIC)]])[ {]b4_parse_assert_if([[ other.check_ ();]])[ std::memcpy (raw_, other.raw_, union_size); @@ -1256,7 +1256,9 @@ public: check_ ();]])[ YYDASSERT (is_state ()); void *yyp = raw_; - return *static_cast (yyp); + glr_state& res = *static_cast (yyp);]b4_parse_assert_if([[ + res.check_ ();]])[ + return res; } const glr_state& getState () const @@ -1264,7 +1266,9 @@ public: check_ ();]])[ YYDASSERT (is_state ()); const void *yyp = raw_; - return *static_cast (yyp); + const glr_state& res = *static_cast (yyp);]b4_parse_assert_if([[ + res.check_ ();]])[ + return res; } semantic_option& getOption () @@ -1313,7 +1317,7 @@ public: YYASSERT (this->is_state_ == false || this->is_state_ == true); } // A magic number to check our pointer arithmetics is sane. - enum { MAGIC = 0xDEAD1ACC }; + enum { MAGIC = 0xDEAD1ACC }; // 3735886540. const unsigned int magic_;]])[ }; @@ -2349,8 +2353,7 @@ public: YYASSERT (yyk.get() == 0); glr_stack_item* yyrhs = yystateStack.firstTop()->asItem(); YY_REDUCE_PRINT ((true, yyrhs, yyk, yyrule, yyparser)); - const YYRESULTTAG res = yyuserAction (yyrule, yynrhs, yyrhs, - yyvalp]b4_locations_if([, yylocp])[); + const YYRESULTTAG res = yyuserAction (yyrule, yynrhs, yyrhs, yyvalp]b4_locations_if([, yylocp])[); yystateStack.pop_back(static_cast(yynrhs)); yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState()); return res;