From patchwork Tue Mar 13 22:07:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10281031 X-Patchwork-Delegate: sean.hefty@intel.com 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 6964A6038F for ; Tue, 13 Mar 2018 22:07:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5351D2580E for ; Tue, 13 Mar 2018 22:07:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47FF628484; Tue, 13 Mar 2018 22:07:51 +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_SIGNED, 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 D0B8E2580E for ; Tue, 13 Mar 2018 22:07:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752209AbeCMWHs (ORCPT ); Tue, 13 Mar 2018 18:07:48 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:45280 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751305AbeCMWHq (ORCPT ); Tue, 13 Mar 2018 18:07:46 -0400 Received: by mail-pl0-f65.google.com with SMTP id v9-v6so594840plp.12 for ; Tue, 13 Mar 2018 15:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pXlFEgTYf5crn8Of+cx3hTPhEEWyv3AJtqI2vJyOCPc=; b=MHr8yQnoQ1urORRsFueRsRfMPVsXQLzF2G5zk8oNMABaiJC6Rl+2ASPVt5c1cIUfHI WAqw7XXxqdUy41AEHXfCJ5vge9h6sF7/ZJ++MECPbD7gAwO7FHMhUlOBvyek0daUkcp9 HhKr04bV1JW7F1yo7+VyShZ2K+yqLGKdKIBqYob7BAsD3um/jAymQ2DxWIhzYy9SmJXl EYlmQIBkdKTjO+UwMxrzOlEqi/TDCkgJwokr35vuGZlQo5OylKr9NCZQPUePKpCN1P9C 6+SivRS8ixuCst6aILFOrM/2OAaBHLB/zx1EO4qIQDhut2qd3l9vVT48l8hwp1Dcr9Bp E4ZA== 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=pXlFEgTYf5crn8Of+cx3hTPhEEWyv3AJtqI2vJyOCPc=; b=RpaYgbEBqgHprq7YjNdOQSqD+YJMwJZ9FHa4Fauf6hbG7CdWzvObzZ0jSzOEzgPWQn 7/AqVe6uHxoj4oWugEslYEnd0WEcnBocBapbEb9rK0xwIiiJuDloFwkZMeF/ldTmsjEL T/S+CZ7zLqyw5cZoqdTXXNcTEGnhf3ccKY6hnsTt/8AgKGqxkmoFYrde3kl3VjcrD1Ua SbA4j03Xz2mHOJCHTR+PQ+psSalD0fYF5LuRjJhfRZWKRnOqpo7w4huFIraIVMT75Jix PIpuS9iJrn2fA09kOExE9S7Wnx1XVeYQAumVaHD2Fv87haNEbIFQP+2YP+ge4l76GzuO W02A== X-Gm-Message-State: AElRT7En31vAR9QE270sAKllUwxFi+/Wp6lC3fyrNqxDMPzgqSNoC+QB s45qYr++wkgKOpmn9DoUiPajjABUgq4= X-Google-Smtp-Source: AG47ELsQ0rIHiyrXgnat34mP4153etNakALhpvKk0AyuUFfAxg4HFHGsZfg8E3gVTMtb7ZlNerHbLQ== X-Received: by 2002:a17:902:6b02:: with SMTP id o2-v6mr1971026plk.334.1520978866048; Tue, 13 Mar 2018 15:07:46 -0700 (PDT) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id c67sm2050019pfl.106.2018.03.13.15.07.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 15:07:42 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.86_2) (envelope-from ) id 1evs57-0001Aq-3u; Tue, 13 Mar 2018 16:07:41 -0600 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 4/8] Allow static_assert to be used Date: Tue, 13 Mar 2018 16:07:33 -0600 Message-Id: <20180313220737.4336-5-jgg@ziepe.ca> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180313220737.4336-1-jgg@ziepe.ca> References: <20180313220737.4336-1-jgg@ziepe.ca> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jason Gunthorpe There are some places where this is just the simplest solution and we don't care if all compilers support the check. Provide a shim for old compilers. Signed-off-by: Jason Gunthorpe --- CMakeLists.txt | 13 +++++++++++++ buildlib/fixup-include/assert.h | 10 ++++++++++ 2 files changed, 23 insertions(+) create mode 100644 buildlib/fixup-include/assert.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f458efbda5a19..47b2dd8b823e86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -405,6 +405,16 @@ if (NOT LIBC_HAS_LIBRT) set(RT_LIBRARIES "rt") endif() +# Check for static_assert +CHECK_C_SOURCE_COMPILES(" +#include +static_assert(1, \"failed\"); +int main(int argc,const char *argv[]) { + static_assert(1, \"failed\"); + return 0; +};" HAVE_STATIC_ASSERT) +RDMA_DoFixup("${HAVE_STATIC_ASSERT}" "assert.h") + #------------------------- # Final warning flags @@ -521,6 +531,9 @@ endif() if (NOT HAVE_STDATOMIC) message(STATUS " C11 stdatomic.h NOT available (old compiler)") endif() +if (NOT HAVE_STATIC_ASSERT) + message(STATUS " C11 static_assert NOT available (old compiler)") +endif() if (NOT HAVE_VALGRIND_MEMCHECK) message(STATUS " Valgrind memcheck.h NOT enabled") endif() diff --git a/buildlib/fixup-include/assert.h b/buildlib/fixup-include/assert.h new file mode 100644 index 00000000000000..848c9310c1ff2a --- /dev/null +++ b/buildlib/fixup-include/assert.h @@ -0,0 +1,10 @@ +#ifndef _FIXUP_ASSERT_H +#define _FIXUP_ASSERT_H + +#include_next + +/* Without C11 compiler support it is not possible to implement static_assert */ +#undef static_assert +#define static_assert(_cond, msg) + +#endif