From patchwork Fri Feb 6 14:34:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 44485 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3FE5121521 for ; Fri, 6 Feb 2015 14:34:14 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id u14sf6180817lbd.3 for ; Fri, 06 Feb 2015 06:34:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=b61R8ZR4noCH6P4T8EQitO0i+0DfaMWXKg+/aI9LGHo=; b=dPeuVSPxQ8jbYmPNi1ZZ7uNAWK3wlDWlu0htG4HGP8YDwKnwcq4G5HIkzm5TQeuQz6 twGgYJEskpj84h1Sjjc+tZO8FeG8fjzdycm4ABDyEeFRaOOHUy+BMeEcvTvjs+DLc0d0 M5WK5Ih/Jyr/6Mw75BSk7Qhb6p20r/WTRw8xNfMCdN74tOfa130Tt4cITqBkv4YCg7qU qhXJtnT3k6gGhBJSCalb6vJzxQ5iyCxrc/3xELKQTUzc624W27EKwgyYnsoYSRr+dsTD wy052HTukpu47rZIj990rn6zN2X3wD+/3KkqQ6apmejQLCcbW8o4EZ4XwBcpE6URX/hL IlBA== X-Gm-Message-State: ALoCoQkvSDfTDYrrnRB5jmBBEzh5c8QufLCcwvupCy2qGTe3jslkA0EMDQKhrwXYOrrrRSC9VLbu X-Received: by 10.112.46.106 with SMTP id u10mr4500lbm.3.1423233253149; Fri, 06 Feb 2015 06:34:13 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.166 with SMTP id t6ls318875lat.89.gmail; Fri, 06 Feb 2015 06:34:12 -0800 (PST) X-Received: by 10.152.6.101 with SMTP id z5mr3068661laz.19.1423233252910; Fri, 06 Feb 2015 06:34:12 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id wn10si1498333lac.76.2015.02.06.06.34.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Feb 2015 06:34:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id l4so18235634lbv.13 for ; Fri, 06 Feb 2015 06:34:12 -0800 (PST) X-Received: by 10.152.8.104 with SMTP id q8mr3125180laa.56.1423233252784; Fri, 06 Feb 2015 06:34:12 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1840068lbj; Fri, 6 Feb 2015 06:34:12 -0800 (PST) X-Received: by 10.180.88.234 with SMTP id bj10mr3810890wib.81.1423233252331; Fri, 06 Feb 2015 06:34:12 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id gf7si4670930wjd.23.2015.02.06.06.34.12 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 06 Feb 2015 06:34:12 -0800 (PST) Received-SPF: none (google.com: pm215@archaic.org.uk does not designate permitted sender hosts) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1YJjz1-00048L-3a; Fri, 06 Feb 2015 14:34:11 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Richard Henderson Subject: [PATCH 3/4] target-arm: A64: Avoid left shifting negative integers in disas_pc_rel_addr Date: Fri, 6 Feb 2015 14:34:09 +0000 Message-Id: <1423233250-15853-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1423233250-15853-1-git-send-email-peter.maydell@linaro.org> References: <1423233250-15853-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Shifting a negative integer left is undefined behaviour in C. Avoid it by assembling and shifting the offset fields as unsigned values and then sign extending as the final action. Signed-off-by: Peter Maydell --- target-arm/translate-a64.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index 94b3bf4..68c5b23 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -2662,11 +2662,12 @@ static void disas_pc_rel_adr(DisasContext *s, uint32_t insn) { unsigned int page, rd; uint64_t base; - int64_t offset; + uint64_t offset; page = extract32(insn, 31, 1); /* SignExtend(immhi:immlo) -> offset */ - offset = ((int64_t)sextract32(insn, 5, 19) << 2) | extract32(insn, 29, 2); + offset = sextract64(insn, 5, 19); + offset = offset << 2 | extract32(insn, 29, 2); rd = extract32(insn, 0, 5); base = s->pc - 4;