From patchwork Sat May 7 20:37:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 764872 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p47KbB76004811 for ; Sat, 7 May 2011 20:37:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753348Ab1EGUhH (ORCPT ); Sat, 7 May 2011 16:37:07 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:48129 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753119Ab1EGUhG convert rfc822-to-8bit (ORCPT ); Sat, 7 May 2011 16:37:06 -0400 Received: by wwa36 with SMTP id 36so4560606wwa.1 for ; Sat, 07 May 2011 13:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=txYY+ATvCOblmpxEBRLFuDQsZ4cPW/R1JpuVgIs07E0=; b=VpPwRxcoT2goayK/PbNmpgk4pUif7ixLwn47K4ZGuP5O83V5GbAuANA/Y6MfDrkhnQ zb7bw7uXvS4VQZDvmsNbI/4PxQQLqi0jyJ9RTpqUExFzJBxPrElsMalqjTt6uWZe45s1 xG+2o+0ZcSnZYBLTknfp53J5mLawla7S9I/hw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=Rc7i+UW7trSzKzLvKeMXtUFJB+JUYhZEGYlDrneBgZI7jyJK6kIsN1E/J529MxICcI Tw0tMhQ85RQHhCQlGrYzHovEfPh6XblnmcnysD1oKP6NXg7yp6fs3rG0Kxl8slX9iQG9 +NKSpGSeiqcpLBmkG+SRPW/vjK3yCdTtGQiS8= MIME-Version: 1.0 Received: by 10.216.143.88 with SMTP id k66mr1066238wej.15.1304800624783; Sat, 07 May 2011 13:37:04 -0700 (PDT) Received: by 10.216.229.219 with HTTP; Sat, 7 May 2011 13:37:04 -0700 (PDT) In-Reply-To: <1304552394-16280-1-git-send-email-blp@nicira.com> References: <1304552394-16280-1-git-send-email-blp@nicira.com> Date: Sat, 7 May 2011 13:37:04 -0700 X-Google-Sender-Auth: XttkEDBlRWJdNB-nepilfBcyx2c Message-ID: Subject: Re: [PATCH] evaluate: Allow sizeof(_Bool) to succeed. From: Christopher Li To: Ben Pfaff Cc: linux-sparse@vger.kernel.org Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 07 May 2011 20:37:11 +0000 (UTC) On Wed, May 4, 2011 at 4:39 PM, Ben Pfaff wrote: > Without this commit, sizeof(_Bool) provokes an error with "cannot size > expression" because _Bool is a 1-bit type and thus not a multiple of a full > byte in size.  But sizeof(_Bool) is valid C that should evaluate to 1, so > this commit fixes the problem and adds a regression test. Thanks for the patch. The sizeof _Bool is implementation define. Gcc make sizeof(_Bool) as 1. I modify your patch to issue an warning. Applied and pushed. The incremental change follows. Please check that works for you or not. Chris --- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/evaluate.c b/evaluate.c index f196dbc..1309001 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2028,14 +2028,18 @@ static struct symbol *evaluate_sizeof(struct expression *expr) size = bits_in_char; } + if (size == 1 && is_bool_type(type)) { + warning(expr->pos, "expression using sizeof bool"); + size = bits_in_char; + } + if (is_function(type->ctype.base_type)) { warning(expr->pos, "expression using sizeof on a function"); size = bits_in_char; } - if (is_bool_type(type)) - size = bits_in_char; - else if ((size < 0) || (size & (bits_in_char - 1))) + + if ((size < 0) || (size & (bits_in_char - 1))) expression_error(expr, "cannot size expression"); expr->type = EXPR_VALUE; diff --git a/validation/sizeof-bool.c b/validation/sizeof-bool.c index dfcb12a..6c68748 100644 --- a/validation/sizeof-bool.c +++ b/validation/sizeof-bool.c @@ -6,4 +6,7 @@ static int a(void) * check-name: sizeof(_Bool) is valid * check-description: sizeof(_Bool) was rejected because _Bool is not an even * number of bytes + * check-error-start +sizeof-bool.c:3:16: warning: expression using sizeof bool + * check-error-end */