misc: Updates for gcc7.2 for x86
authorJason Lowe-Power <jason@lowepower.com>
Wed, 13 Dec 2017 18:19:04 +0000 (10:19 -0800)
committerJason Lowe-Power <jason@lowepower.com>
Thu, 14 Dec 2017 00:27:59 +0000 (00:27 +0000)
GCC 7.2 is much stricter than previous GCC versions. The following changes
are needed:

* There is now a warning if there is an implicit fallthrough between two
  case statments. C++17 adds the [[fallthrough]]; declaration. However,
  to support non C++17 standards (i.e., C++11), we use M5_FALLTHROUGH.
  M5_FALLTHROUGH checks for [[fallthrough]] compliant C++17 compiler and
  if that doesn't exist, it defaults to nothing (no older compilers
  generate warnings).
* The above resulted in a couple of bugs that were found. This is noted
  in the review request on gerrit.
* throw() for dynamic exception specification is deprecated
* There were a couple of new uninitialized variable warnings
* Can no longer perform bitwise operations on a bool.
* Must now include <functional> for std::function
* Compiler bug for void* lambda. Changed to auto as work around. See
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82878

Change-Id: I5d4c782a4e133fa4cdb119e35d9aff68c6e2958e
Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-on: https://gem5-review.googlesource.com/5802
Reviewed-by: Gabe Black <gabeblack@google.com>
21 files changed:
ext/dnet/ip.h
ext/drampower/src/Utils.h
src/arch/arm/isa.cc
src/arch/arm/table_walker.cc
src/arch/x86/isa.cc
src/arch/x86/isa/microops/regop.isa
src/base/compiler.hh
src/base/cprintf.cc
src/base/imgwriter.cc
src/cpu/kvm/base.cc
src/cpu/kvm/x86_cpu.cc
src/cpu/minor/dyn_inst.cc
src/dev/arm/generic_timer.cc
src/dev/net/i8254xGBe.cc
src/dev/pci/copy_engine.cc
src/dev/storage/ide_disk.cc
src/dev/x86/i8042.cc
src/kern/linux/printk.cc
src/mem/slicc/symbols/Type.py
src/sim/eventq.hh
src/sim/fd_array.cc

index 95b7718fbaa22aec50d79009525046e6588121ba..d2f9ad1d8bfad8f0063f0a305720033e70a1d808 100644 (file)
@@ -428,47 +428,13 @@ inline int
 ip_cksum_add(const void *buf, size_t len, int cksum)
 {
         uint16_t *sp = (uint16_t *)buf;
-        int n, sn;
+        int sn;
 
         sn = len / 2;
-        n = (sn + 15) / 16;
-
-        /* XXX - unroll loop using Duff's device. */
-        switch (sn % 16) {
-        case 0:        do {
-                cksum += *sp++;
-        case 15:
-                cksum += *sp++;
-        case 14:
-                cksum += *sp++;
-        case 13:
-                cksum += *sp++;
-        case 12:
-                cksum += *sp++;
-        case 11:
-                cksum += *sp++;
-        case 10:
-                cksum += *sp++;
-        case 9:
-                cksum += *sp++;
-        case 8:
-                cksum += *sp++;
-        case 7:
-                cksum += *sp++;
-        case 6:
-                cksum += *sp++;
-        case 5:
-                cksum += *sp++;
-        case 4:
-                cksum += *sp++;
-        case 3:
-                cksum += *sp++;
-        case 2:
-                cksum += *sp++;
-        case 1:
-                cksum += *sp++;
-                } while (--n > 0);
-        }
+
+        do {
+            cksum += *sp++;
+        } while (--sn > 0);
         if (len & 1)
                 cksum += htons(*(u_char *)sp << 8);
 
index 80f4390c7f6186f789f6845d2ee01f5f1cd37531..7c165a303472d3b7086e06a798c046b3d2daf15a 100644 (file)
@@ -46,7 +46,6 @@
 template<typename T>
 T fromString(const std::string& s,
              std::ios_base& (*f)(std::ios_base &) = std::dec)
-throw(std::runtime_error)
 {
   std::istringstream is(s);
   T t;
index a490e5fb79ca079a464e6339271eec751cb42e1a..44e4ff37681aab33becb0e5f136ca9aaf449e743 100644 (file)
@@ -1653,6 +1653,7 @@ ISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
                     newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask));
                 }
             }
+            M5_FALLTHROUGH;
           case MISCREG_TTBR0:
           case MISCREG_TTBR1:
             {
@@ -1666,12 +1667,14 @@ ISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
                     }
                 }
             }
+            M5_FALLTHROUGH;
           case MISCREG_SCTLR_EL1:
             {
                 tc->getITBPtr()->invalidateMiscReg();
                 tc->getDTBPtr()->invalidateMiscReg();
                 setMiscRegNoEffect(misc_reg, newVal);
             }
+            M5_FALLTHROUGH;
           case MISCREG_CONTEXTIDR:
           case MISCREG_PRRR:
           case MISCREG_NMRR:
index 2d6664264c2a859831ad357451cda757b0dba84d..63b67f56a80f44100f575072fc4648bba21b137a 100644 (file)
@@ -1398,6 +1398,7 @@ TableWalker::memAttrsAArch64(ThreadContext *tc, TlbEntry &te,
           case 0x1 ... 0x3: // Normal Memory, Inner Write-through transient
           case 0x9 ... 0xb: // Normal Memory, Inner Write-through non-transient
             warn_if(!attr_hi, "Unpredictable behavior");
+            M5_FALLTHROUGH;
           case 0x4:         // Device-nGnRE memory or
                             // Normal memory, Inner Non-cacheable
           case 0x8:         // Device-nGRE memory or
index 9dd7fbb52a0d3bcb4abe93b8e550a093dfc5edd1..f092f441821f2c6ac5499e678358e00440624525 100644 (file)
@@ -316,7 +316,7 @@ ISA::setMiscReg(int miscReg, MiscReg val, ThreadContext * tc)
         break;
       case MISCREG_DR4:
         miscReg = MISCREG_DR6;
-        /* Fall through to have the same effects as DR6. */
+        M5_FALLTHROUGH;
       case MISCREG_DR6:
         {
             DR6 dr6 = regVal[MISCREG_DR6];
@@ -333,7 +333,7 @@ ISA::setMiscReg(int miscReg, MiscReg val, ThreadContext * tc)
         break;
       case MISCREG_DR5:
         miscReg = MISCREG_DR7;
-        /* Fall through to have the same effects as DR7. */
+        M5_FALLTHROUGH;
       case MISCREG_DR7:
         {
             DR7 dr7 = regVal[MISCREG_DR7];
index 4fd3b2aa656c57285ba49cc938ab03bdf869622d..2d5ae048a5781622255b46fc1906f097b668d50a 100644 (file)
@@ -1427,6 +1427,7 @@ let {{
                         if (bits(newVal, 63, 4))
                             fault = std::make_shared<GeneralProtection>(0);
                     }
+                    break;
                   default:
                     fault = std::make_shared<GenericISA::M5PanicFault>(
                             "Unrecognized control register %d.\\n", dest);
@@ -1528,7 +1529,7 @@ let {{
                     fault = std::make_shared<GeneralProtection>(selector);
                     break;
                 }
-                // Fall through on purpose
+                M5_FALLTHROUGH;
               case SegIntGateCheck:
                 // Make sure the gate's the right type.
                 if ((m5reg.mode == LongMode && (desc.type & 0xe) != 0xe) ||
index 2fdd323b968c972619e517f82d9482d6040f5376..6920dad104aaba1c3653f07f98a64b003d078535 100644 (file)
 #  define M5_CLASS_VAR_USED
 #endif
 
+// This can be removed once all compilers support C++17
+#if defined __has_cpp_attribute
+    // Note: We must separate this if statement because GCC < 5.0 doesn't
+    //       support the function-like syntax in #if statements.
+    #if __has_cpp_attribute(fallthrough)
+        #define M5_FALLTHROUGH [[fallthrough]]
+    #else
+        #define M5_FALLTHROUGH
+    #endif
+#else
+    // Unsupported (and no warning) on GCC < 7.
+    #define M5_FALLTHROUGH
+#endif
+
 // std::make_unique redefined for C++11 compilers
 namespace m5
 {
index 5daf196f1f4200d15c742e2b11b3071e362edcde..caf1bb847c51758c0e0fddddab1f733c6c139ca5 100644 (file)
@@ -35,6 +35,8 @@
 #include <iostream>
 #include <sstream>
 
+#include "base/compiler.hh"
+
 using namespace std;
 
 namespace cp {
@@ -138,6 +140,7 @@ Print::process_flag()
 
           case 'X':
             fmt.uppercase = true;
+            M5_FALLTHROUGH;
           case 'x':
             fmt.base = Format::hex;
             fmt.format = Format::integer;
@@ -159,6 +162,7 @@ Print::process_flag()
 
           case 'G':
             fmt.uppercase = true;
+            M5_FALLTHROUGH;
           case 'g':
             fmt.format = Format::floating;
             fmt.float_format = Format::best;
@@ -167,6 +171,7 @@ Print::process_flag()
 
           case 'E':
             fmt.uppercase = true;
+            M5_FALLTHROUGH;
           case 'e':
             fmt.format = Format::floating;
             fmt.float_format = Format::scientific;
@@ -213,6 +218,7 @@ Print::process_flag()
                 fmt.fill_zero = true;
                 break;
             }
+            M5_FALLTHROUGH;
           case '1':
           case '2':
           case '3':
index 40de3d7ccc388e31825c8de8af431f9a599bc114..13ff86c3049cacafda1b3fb4059cebb2678f60c3 100644 (file)
@@ -59,7 +59,7 @@ createImgWriter(Enums::ImageFormat type, const FrameBuffer *fb)
         // gem5 will try PNG first, and it will fallback to BMP if not
         // available.
 
-        /* FALLTHROUGH */
+        M5_FALLTHROUGH;
 #if USE_PNG
       case Enums::Png:
         return std::unique_ptr<PngWriter>(new PngWriter(fb));
index ab83e5d2ff0c950d917e0e901cf4c3fc1b5c8ee6..3df0fddda5e9be28c3314fd613eec3d2549b62bc 100644 (file)
@@ -383,7 +383,7 @@ BaseKvmCPU::drain()
             deschedule(tickEvent);
         _status = Idle;
 
-        /** FALLTHROUGH */
+        M5_FALLTHROUGH;
       case Idle:
         // Idle, no need to drain
         assert(!tickEvent.scheduled());
index 467e1baaf609ccc45ebe99bff701caf4acf6697d..1a23b6717922e3e79e187f53f1eb24915e362da8 100644 (file)
@@ -396,6 +396,7 @@ checkSeg(const char *name, const int idx, const struct kvm_segment &seg,
       case MISCREG_ES:
         if (seg.unusable)
             break;
+        M5_FALLTHROUGH;
       case MISCREG_CS:
         if (seg.base & 0xffffffff00000000ULL)
             warn("Illegal %s base: 0x%x\n", name, seg.base);
@@ -433,7 +434,7 @@ checkSeg(const char *name, const int idx, const struct kvm_segment &seg,
           case 3:
             if (sregs.cs.type == 3 && seg.dpl != 0)
                 warn("CS type is 3, but SS DPL is != 0.\n");
-            /* FALLTHROUGH */
+            M5_FALLTHROUGH;
           case 7:
             if (!(sregs.cr0 & 1) && seg.dpl != 0)
                 warn("SS DPL is %i, but CR0 PE is 0\n", seg.dpl);
@@ -477,6 +478,7 @@ checkSeg(const char *name, const int idx, const struct kvm_segment &seg,
       case MISCREG_GS:
         if (seg.unusable)
             break;
+        M5_FALLTHROUGH;
       case MISCREG_CS:
         if (!seg.s)
             warn("%s: S flag not set\n", name);
@@ -485,6 +487,7 @@ checkSeg(const char *name, const int idx, const struct kvm_segment &seg,
       case MISCREG_TSL:
         if (seg.unusable)
             break;
+        M5_FALLTHROUGH;
       case MISCREG_TR:
         if (seg.s)
             warn("%s: S flag is set\n", name);
@@ -500,6 +503,7 @@ checkSeg(const char *name, const int idx, const struct kvm_segment &seg,
       case MISCREG_TSL:
         if (seg.unusable)
             break;
+        M5_FALLTHROUGH;
       case MISCREG_TR:
       case MISCREG_CS:
         if (!seg.present)
index 756b214bd7d62b828b116d5674de34f5e2794c43..3531637582bed06ecdfd73a4e5396a5b13614b7a 100644 (file)
@@ -169,6 +169,7 @@ printRegName(std::ostream &os, const RegId& reg)
         break;
       case CCRegClass:
         os << 'c' << static_cast<unsigned int>(reg.index());
+        break;
       default:
         panic("Unknown register class: %d", (int)reg.classValue());
     }
index 35086748840c161d19759062402d95ccbee5a3df..f8433bd2d2c9d5b53c1c820e22e4937ff47cf84f 100644 (file)
@@ -385,7 +385,7 @@ GenericTimer::setMiscReg(int reg, unsigned cpu, MiscReg val)
       case MISCREG_CNTPS_CVAL_EL1:
       case MISCREG_CNTPS_TVAL_EL1:
       case MISCREG_CNTPS_CTL_EL1:
-        /* FALLTHROUGH */
+        M5_FALLTHROUGH;
 
       // PL2 phys. timer, non-secure
       case MISCREG_CNTHCTL:
@@ -466,7 +466,7 @@ GenericTimer::readMiscReg(int reg, unsigned cpu)
       case MISCREG_CNTPS_CVAL_EL1:
       case MISCREG_CNTPS_TVAL_EL1:
       case MISCREG_CNTPS_CTL_EL1:
-        /* FALLTHROUGH */
+        M5_FALLTHROUGH;
 
       // PL2 phys. timer, non-secure
       case MISCREG_CNTHCTL:
index 3dde72ac7e3db722c2e0542027d699c12d9bcaa1..3359b0d61a286c75c3177bc28e5e010138a55877 100644 (file)
@@ -2290,14 +2290,13 @@ IGbE::rxStateMachine()
         int descLeft = rxDescCache.descLeft();
         DPRINTF(EthernetSM, "RXS: descLeft: %d rdmts: %d rdlen: %d\n",
                 descLeft, regs.rctl.rdmts(), regs.rdlen());
-        switch (regs.rctl.rdmts()) {
-          case 2: if (descLeft > .125 * regs.rdlen()) break;
-          case 1: if (descLeft > .250 * regs.rdlen()) break;
-          case 0: if (descLeft > .500 * regs.rdlen())  break;
+
+        // rdmts 2->1/8, 1->1/4, 0->1/2
+        int ratio = (1ULL << (regs.rctl.rdmts() + 1));
+        if (descLeft * ratio <= regs.rdlen()) {
             DPRINTF(Ethernet, "RXS: Interrupting (RXDMT) "
                     "because of descriptors left\n");
             postInterrupt(IT_RXDMT);
-            break;
         }
 
         if (rxFifo.empty())
index 3c7df7d3abed01dd54feab2764b502b36e0fc4fe..7c87da1c071f5db8f6d3de71929e832c907d5ff7 100644 (file)
@@ -249,7 +249,7 @@ CopyEngine::CopyEngineChannel::channelRead(Packet *pkt, Addr daddr, int size)
         break;
       case CHAN_STATUS:
         assert(size == sizeof(uint64_t));
-        pkt->set<uint64_t>(cr.status() | ~busy);
+        pkt->set<uint64_t>(cr.status() | (busy ? 0 : 1));
         break;
       case CHAN_CHAINADDR:
         assert(size == sizeof(uint64_t) || size == sizeof(uint32_t));
index 08d374fa392da6bff270f9d4f1332f37cfdd5ffe..020e4582de469b28f3d2151272cb7fcad7bbdc69 100644 (file)
@@ -705,6 +705,7 @@ IdeDisk::startCommand()
         // Supported DMA commands
       case WDCC_WRITEDMA:
         dmaRead = true;  // a write to the disk is a DMA read from memory
+        M5_FALLTHROUGH;
       case WDCC_READDMA:
         if (!(cmdReg.drive & DRIVE_LBA_BIT))
             panic("Attempt to perform CHS access, only supports LBA\n");
index 39b02055b3f6ca6b9b8d4de96d028354329c2425..c5fca1b47e0238622b122a2c0537a9450f913946 100644 (file)
@@ -455,10 +455,12 @@ X86ISA::I8042::write(PacketPtr pkt)
           case WriteOutputPort:
             warn("i8042 \"Write output port\" command not implemented.\n");
             lastCommand = WriteOutputPort;
+            break;
           case WriteKeyboardOutputBuff:
             warn("i8042 \"Write keyboard output buffer\" "
                     "command not implemented.\n");
             lastCommand = WriteKeyboardOutputBuff;
+            break;
           case WriteMouseOutputBuff:
             DPRINTF(I8042, "Got command to write to mouse output buffer.\n");
             lastCommand = WriteMouseOutputBuff;
index adc2009df7e52f1ba6590580afaf4c6976febbef..788a343b36a27c7bdb3b2f8672e525ece663a2f3 100644 (file)
@@ -101,6 +101,7 @@ Printk(stringstream &out, Arguments args)
                   break;
                 case 'P':
                   format = true;
+                  M5_FALLTHROUGH;
                 case 'p':
                   hexnum = true;
                   break;
@@ -258,4 +259,3 @@ Printk(stringstream &out, Arguments args)
     }
 
 }
-
index 4f4f0585dc4445bc38771dbaa43c8bc9ce5e0cbb..188d6dd7582c5558165827ff099d61820a7a71fe 100644 (file)
@@ -734,6 +734,7 @@ ${{self.c_ident}}_base_number(const ${{self.c_ident}}& obj)
                     code('    base += ${{enum.ident}}_Controller::getNumControllers();')
                 else:
                     code('    base += 0;')
+                code('    M5_FALLTHROUGH;')
                 code('  case ${{self.c_ident}}_${{enum.ident}}:')
             code('    break;')
             code.dedent()
index 0a0405fefb9d673419565a528e44ecde9eeaca05..781bcdbf98e9170700357b7c34d61937c1228383 100644 (file)
@@ -41,6 +41,7 @@
 #include <algorithm>
 #include <cassert>
 #include <climits>
+#include <functional>
 #include <iosfwd>
 #include <memory>
 #include <mutex>
index 15cfe11efb85ee8a079eb5cebf1f64937cf3d2f0..7f3f7dd2478c7f7343b8a936f10de11577408999 100644 (file)
@@ -131,8 +131,7 @@ FDArray::restoreFileOffsets()
      * possible to guarantee that the simulation will proceed as it should
      * have in the same way that it would have proceeded sans checkpoints.
      */
-    void (*seek)(std::shared_ptr<FileFDEntry>)
-        = [] (std::shared_ptr<FileFDEntry> ffd)
+    auto seek = [] (std::shared_ptr<FileFDEntry> ffd)
     {
         if (lseek(ffd->getSimFD(), ffd->getFileOffset(), SEEK_SET) < 0)
             fatal("Unable to seek to location in %s", ffd->getFileName());