From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by sourceware.org (Postfix) with ESMTPS id 0CC283858D37 for ; Mon, 13 Jul 2020 20:02:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0CC283858D37 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-ua1-x933.google.com with SMTP id p6so4559884uaq.12 for ; Mon, 13 Jul 2020 13:02:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=PAKanlUyqCmjvQm1P3B1Dydnx+0B2oatinRJMygogus=; b=bQRuypZ+hviLv8CpWtWiS64/yqxm1wmEhL4bitUK6E/SMaMydfti4BfwXZl30nJuMt 7+JzWWf/EkVVSvNulrydpaMOtpJ79ua+TkHihdWIDKaIVCGfaKlEybHou8kWhqIch6M5 +20WOgmu4KnSolb0UxsCD2lu5XGZwqfRaztCw6X/m2gzd2MRl0lv2uD2mlkEmV9mZvBZ JprZ3WZzItB34LrsG5oFaN1GaIpdV11BaTRk0otIru5s6rr3opv/wRj9t36/1+vD5LKl rCYlV34SEgdQNILI5PnbbKaviuyFca3cGwkIRdOHGXapm95zgm9xEYse2ffMV9S+EbvT 5ucQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=PAKanlUyqCmjvQm1P3B1Dydnx+0B2oatinRJMygogus=; b=Y2o6O3dML2h91fgDsw9bQ1OXWR7zzgmXnbMHR+rzyG5Qr9igDZHMxuVc5+XpGW5UjK AKzO76haITABzzNhVKGhvIgVSW6rTAgeQuKJXl2W8DzIvw3kmdkUuF5GHVW5PAVt3QvB H2t8CfN3AiJqXaQ94iINPnHmSNC2yXtCoy2nWrQ8jrla/mFHcL08ssNddFNd7JHy0a1Y 17wqylRaaNOAZPtyScYOoO2bj0nUhTbIXgxzXtZGE8BoEH6F+hZHZDusByhzbT1JpMkw ynWyTUr4h26cUXNF+hzex4c0p6REGcOEAwlNZVSTmJ8NAL8UUikXrkFGxOueXWMZtCN1 EcEw== X-Gm-Message-State: AOAM531NFbStVCw0gOANE8u7EoNDcmPMrgmqWEH8wH4EVYeMcQu4Cg6L kJZYDbcXedLk0O81XtZH6xt/5spoLN3ZkEsgwjMOLc7DPPY= X-Google-Smtp-Source: ABdhPJx9DYatz4kEEW77Zh66jYBzu0bF3DeNjif1W4qKp5j99O800/PTV++kGLnr6p5R0cxluMtUh+zioTcTcQr8FhU= X-Received: by 2002:a9f:380e:: with SMTP id p14mr964493uad.21.1594670538301; Mon, 13 Jul 2020 13:02:18 -0700 (PDT) MIME-Version: 1.0 From: Jim Wilson Date: Mon, 13 Jul 2020 13:02:07 -0700 Message-ID: Subject: __restrict defined away for C++ To: Newlib Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jul 2020 20:02:20 -0000 This problem was originally reported on the RISC-V sw-dev mailing list. https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/b55LI9OSFwo/m/d8-_NGmlAQAJ I see that newlib/libc/include/sys/cdefs.h has /* * GCC 2.95 provides `__restrict' as an extension to C90 to support the * C99-specific `restrict' type qualifier. We happen to use `__restrict' as * a way to define the `restrict' type qualifier without disturbing older * software that is unaware of C99 keywords. */ #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 #define __restrict #else #define __restrict restrict #endif #endif The flaw here is that C++ compilers don't define __STDC_VERSION so this always causes __restrict to be defined away, even if the C++ compiler supports it. This prevents use of the GNU extension __restrict in C++ code. The workaround is to use __restrict__ in user code which GNU C++ also supports, and which newlib doesn't define away. I don't have a patch. I'm hoping someone else writes one. One possible solution is to use a different keyword inside newlib, e.g. __newlib_retrict. This way we don't conflict with the compiler __restrict feature. Though this means newlib functions will be declared without __restrict. Another solution would be to check for C++ compilers with __restrict support and support them. Or maybe both of these are appropriate. We may not need the gcc-2.95 support anymore. Jim