From patchwork Tue Jun 20 20:19:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9800181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 775546038C for ; Tue, 20 Jun 2017 20:19:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BC3B22AFC for ; Tue, 20 Jun 2017 20:19:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 600E7283AF; Tue, 20 Jun 2017 20:19:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E10B922AFC for ; Tue, 20 Jun 2017 20:19:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751774AbdFTUTk (ORCPT ); Tue, 20 Jun 2017 16:19:40 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36002 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751118AbdFTUTk (ORCPT ); Tue, 20 Jun 2017 16:19:40 -0400 Received: by mail-wr0-f194.google.com with SMTP id 77so20322944wrb.3 for ; Tue, 20 Jun 2017 13:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GzQ8YjW80ZkcaFYI1Iet5JpBvHjNCHKi7Eac5o+mHs0=; b=oN09O6RwsTOzPINuQYEaKYyAYShzYikBzl7PzBPW0DPZ4TUsC0zAdoA4O1RqolFDoM GRTL6e1bF9NBFrf+cPsfyzG46fZT5m34K45bTl4JcGTdk3IYq96ZS9OiD0Co2ocjc5/t NWVfLn/X+830ioxP9PIt+FFv/ktbLbGs/lexVyft+j+ghuDaXqJbT2ZJMEO4XfdD5Bs5 qubJLyMWswOA00jvMfIax4DoM8MmRpN3O2FMcVkCX3pjbHAwIYgKamyOg8+0pztmQibJ WkjLEUQrnE1rpG0NKLRKUezGIg25jd0EzrjeLkJGB1DVCyLwZ2hmT7jQKv63qaBHVjaV xtLg== 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:in-reply-to :references; bh=GzQ8YjW80ZkcaFYI1Iet5JpBvHjNCHKi7Eac5o+mHs0=; b=f8098BjumJAtTHpcv+KgtJ/8WeuGoJa8yPqGKo8+zAsBV/aS1K8kgxVWgkOgi83umn Wet1uaidaTrCN5FUXxlZRJitTrcoT7RM5kfV5zTnjNzDYKHWbZgcXUvqokt+TZQa6tWG ntX7TFnY/1ySkWhSivoBuwLekOsImbNEaYGzpyvs1FWjr60sjlqaFeKU8JtkhYOhpvXE TJHon8g9t/f3PEcSubVjAsKH/6ZTqA8SaHTVgiEkT0GAPiwaowf0M5HHjLnCidi76NCJ 3+xZoOltuGfmKmthHVZb7vl8hiuklJDg/DGVZ4mLEAl3RpiomUO8mC11kkPqGMS86lnI npDQ== X-Gm-Message-State: AKS2vOy5qYkhiN7wC9meHKIE4BwwTnZ2fYgvOo/i2/u6OxTWhdZoUF90 bhF9gdvZ64huD8snhYc= X-Received: by 10.80.173.235 with SMTP id b40mr22824551edd.110.1497989978500; Tue, 20 Jun 2017 13:19:38 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:837:f300:4131:d708:a975:bd4c]) by smtp.gmail.com with ESMTPSA id r28sm8047501edd.33.2017.06.20.13.19.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 13:19:37 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH 2/3] teach sparse about __{BIG,LITTLE}_ENDIAN__ Date: Tue, 20 Jun 2017 22:19:30 +0200 Message-Id: <20170620201931.92864-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170620201931.92864-1-luc.vanoostenryck@gmail.com> References: <20170620201931.92864-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some macros, structures definitions, ... depends on the endianness. This is generaly done via some header file but these headers need information from the compiler via the macros __{BIG,LITTLE}_ENDIAN__. Let sparse predefine these macros like compilers do. Signed-off-by: Luc Van Oostenryck --- lib.c | 3 +++ validation/endian-big.c | 11 +++++++++++ validation/endian-little.c | 11 +++++++++++ 3 files changed, 25 insertions(+) create mode 100644 validation/endian-big.c create mode 100644 validation/endian-little.c diff --git a/lib.c b/lib.c index a22635ecc..daf7d0219 100644 --- a/lib.c +++ b/lib.c @@ -961,6 +961,9 @@ static void predefined_macros(void) predefined_sizeof("FLOAT", bits_in_float); predefined_sizeof("DOUBLE", bits_in_double); predefined_sizeof("LONG_DOUBLE", bits_in_longdouble); + + add_pre_buffer("#weak_define __%s_ENDIAN__ 1\n", + arch_big_endian ? "BIG" : "LITTLE"); } void declare_builtin_functions(void) diff --git a/validation/endian-big.c b/validation/endian-big.c new file mode 100644 index 000000000..d535748cd --- /dev/null +++ b/validation/endian-big.c @@ -0,0 +1,11 @@ +#if defined(__LITTLE_ENDIAN__) +#error "__LITTLE_ENDIAN__ defined!" +#endif +#if (__BIG_ENDIAN__ != 1) +#error "__BIG_ENDIAN__ not correctly defined!" +#endif + +/* + * check-name: endian-big.c + * check-command: sparse -mbig-endian $file + */ diff --git a/validation/endian-little.c b/validation/endian-little.c new file mode 100644 index 000000000..cc4a14f73 --- /dev/null +++ b/validation/endian-little.c @@ -0,0 +1,11 @@ +#if defined(__BIG_ENDIAN__) +#error "__BIG_ENDIAN__ defined!" +#endif +#if (__LITTLE_ENDIAN__ != 1) +#error "__LITTLE_ENDIAN__ not correctly defined!" +#endif + +/* + * check-name: endian-little.c + * check-command: sparse -mlittle-endian $file + */