From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id ADB3F393A426 for ; Thu, 8 Apr 2021 01:54:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ADB3F393A426 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jimw@sifive.com Received: by mail-pf1-x42d.google.com with SMTP id a12so647460pfc.7 for ; Wed, 07 Apr 2021 18:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=LQiP/xR1kSd4mfa821peHbXLMSnHZN201Oy52GeV3iU=; b=m/N7wb9BsN3a9g0cjgzROmo/ohlpCH1gnuTJZcbIYEYxUyJp6auSVkJnl02v8SRW8d 3NkNd0HDuVJt9kGyVOU7xblJx4mj/7+PX7tOtBbuTgtR/srNnPS9XQQ9s5Dc7+WzhOA0 uMPVRCj7LP5aFCxLJvuHhQl2CGBxqLewGbvJLDo36o4a9+GmeETSKVcIcJu+vj0jltmg 7rEm5wYw4nA/Z7KwyymJYsIqKoC6hRQmVnM6bRbdIVHa0JdR6f8wUO0YRIlm1WBevB9a LOuE4I/r5wMac5LNXBDa3uCgMQ88G1FPzPeDvED4bAQ/PalPu9y4bPlnFszb1yMe3zwg MWkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LQiP/xR1kSd4mfa821peHbXLMSnHZN201Oy52GeV3iU=; b=eQqEf1v6lcIUiHqrgdO6oa2+zp/8mbgv6zLK3iUs+XjrObG3Ky7yCjE+d9H4MCeF9K MHRit2XxmOZPKXuHjmeQiJndvDjCdQGGwLe2moCj0LiGmpQ3fHuD7AdHqJlBf316ts2P 5iZn7oTMuJ7FmYJwtRIqislyjFtxhRYZleXnrZwasQQ2eUlNLkN8Je8O9UPjOHCHEEuW MkLmmO2hKSco8RnJ4TUR4J2Aecuevt5TqISptHXzXGwRT6e5vHdw1pqjMiLBRhSEC1O/ v/dErPRJegpwA+p/W7IbSk1T1pVXDlwpEZFDYfIVvP9OU86IfFIkU0VQXtiNog2UWiz8 dYBA== X-Gm-Message-State: AOAM530VNac4FDLeXtvDjdhl7ZqQidSig2cLjpYCo8hIAlSA+/R8QSyV 2QSYNTO8tx76DSliZvz84HW2tpVNDpmPpg== X-Google-Smtp-Source: ABdhPJzq2QzoX1rZnb+WFu3Tn3YWq1BfujIBu+o7VWkom1Nsq8/nmoFi8IOlKrc2H79CM37MObTInw== X-Received: by 2002:a63:5f54:: with SMTP id t81mr5813762pgb.283.1617846863494; Wed, 07 Apr 2021 18:54:23 -0700 (PDT) Received: from rohan.hsd1.ca.comcast.net ([2601:646:c180:b150:79e0:b30f:ff81:4f33]) by smtp.gmail.com with ESMTPSA id j3sm20703788pfc.49.2021.04.07.18.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 18:54:23 -0700 (PDT) From: Jim Wilson To: gdb-patches@sourceware.org Subject: [PATCH] Aarch64 sim fix for gcc-10 miscompilation. Date: Wed, 7 Apr 2021 18:54:03 -0700 Message-Id: <20210408015403.29192-1-jimw@sifive.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Apr 2021 01:54:26 -0000 This fixes a problem that occurs when compiled by gcc-10, as the code is relying on undefined overflow behavior. This is fixed by replacing compares between 32-bit and 64-bit results with compares that just use the 64-bit results with a cast. Tested with the simulator make check and a gcc make check. There were no regressions. Committed. PR sim/27483 * simulator.c (set_flags_for_add32): Compare uresult against itself. Compare sresult against itself. --- sim/aarch64/simulator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sim/aarch64/simulator.c b/sim/aarch64/simulator.c index 6ba29a0ed57..e0b428d26d9 100644 --- a/sim/aarch64/simulator.c +++ b/sim/aarch64/simulator.c @@ -1650,10 +1650,10 @@ set_flags_for_add32 (sim_cpu *cpu, int32_t value1, int32_t value2) if (result & (1 << 31)) flags |= N; - if (uresult != (uint32_t)result) + if (uresult != (uint32_t)uresult) flags |= C; - if (sresult != result) + if (sresult != (int32_t)sresult) flags |= V; aarch64_set_CPSR (cpu, flags); -- 2.17.1