From patchwork Fri Oct 2 10:12:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 7314481 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 146B79F1D5 for ; Fri, 2 Oct 2015 10:14:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B96552089E for ; Fri, 2 Oct 2015 10:14:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5E122089B for ; Fri, 2 Oct 2015 10:14:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751342AbbJBKOM (ORCPT ); Fri, 2 Oct 2015 06:14:12 -0400 Received: from mail-la0-f43.google.com ([209.85.215.43]:34342 "EHLO mail-la0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751170AbbJBKOL (ORCPT ); Fri, 2 Oct 2015 06:14:11 -0400 Received: by labzv5 with SMTP id zv5so90207090lab.1 for ; Fri, 02 Oct 2015 03:14:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id; bh=QZuaHD2ETeRGBxVg4iENOlIarp3BLIpo2Up8dshmN4U=; b=BUUb3viPRNadsQ+gGOsmD05Eb2xTee1epoCgnIMLv7YpSuLCYbGMglABJuvfvO9fGo ymzDx/0plUH7qncHt67JZSf1fFlMwZFis3isIkzCYiQOlgOwa7kPovfUBPkmtQhCGnGT c/wFilq3JtnEXR/sGkkMVUtq/e0X9VdZ7kmTE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QZuaHD2ETeRGBxVg4iENOlIarp3BLIpo2Up8dshmN4U=; b=Tyk0ZkV9Ls27hYekpU5tOJG/V9JyqNiBtkf40cTH7gcSfUBZ6Fv1gbYFoyYBO+svOG Aue1Eyqf9Vx7KvQ2AcdfBMdW/TuiTF2wRwZROrnuOMEbucwWTq8EJi4UkJ6qXXS0w5U4 qWJ10C/SPtrr9RYYcK1mpGo7xUr0ZLYxuD27fo47OWVVBtvFeDMrQtTzed+BcCKptY9k lNSL/LJO7Du/YPtSI8OiCY9GNvtCBE+AvOjce3kHnNPnEuk7b5Iyutxx70wYzgVs9eKu XxxAUr01lJvowt++eYilMViQg1NB5N9MdsTeiUvGeC36SDm6QwJEchnCEPbnHcCNNmpp Ysew== X-Gm-Message-State: ALoCoQllUVA1SzYRrcn8lUMsK1QzorDDSEg5YpioFreKm526w1koS9kuOlOelj6bUXY8hh7Nbx09 X-Received: by 10.112.55.2 with SMTP id n2mr5367042lbp.59.1443780849313; Fri, 02 Oct 2015 03:14:09 -0700 (PDT) Received: from spencer.imf.au.dk ([130.225.20.51]) by smtp.gmail.com with ESMTPSA id h7sm1361640lbk.8.2015.10.02.03.14.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 03:14:08 -0700 (PDT) From: Rasmus Villemoes To: Andrew Morton , David Rientjes , Christopher Li Cc: Rasmus Villemoes , linux-kernel@vger.kernel.org, linux-sparse@vger.kernel.org Subject: [PATCH 1/2] compiler.h: add support for function attribute assume_aligned Date: Fri, 2 Oct 2015 12:12:54 +0200 Message-Id: <1443780775-10304-1-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.3 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP gcc 4.9 added the function attribute assume_aligned, indicating to the caller that the returned pointer may be assumed to have a certain minimal alignment. This is useful if, for example, the return value is passed to memset(). Add a shorthand macro for that. Signed-off-by: Rasmus Villemoes --- include/linux/compiler-gcc.h | 17 +++++++++++++++++ include/linux/compiler.h | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index dfaa7b3e9ae9..18606a460baf 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -210,6 +210,23 @@ #define __visible __attribute__((externally_visible)) #endif + +#if GCC_VERSION >= 40900 +/* + * __assume_aligned(n, k): Tell the optimizer that the returned + * pointer can be assumed to be k modulo n. The second argument is + * optional (default 0), so we use a variadic macro to make the + * shorthand. + * + * Beware: Do not apply this to functions which may return + * ERR_PTRs. Also, it is probably unwise to apply it to functions + * returning extra information in the low bits (but in that case the + * compiler should see some alignment anyway, when the return value is + * massaged by 'flags = ptr & 3; ptr &= ~3;'). + */ +#define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__))) +#endif + /* * GCC 'asm goto' miscompiles certain code sequences: * diff --git a/include/linux/compiler.h b/include/linux/compiler.h index c836eb2dc44d..6167ca663ad9 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -393,6 +393,14 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s #define __visible #endif +/* + * Assume alignment of return value. + */ +#ifndef __assume_aligned +#define __assume_aligned(a, ...) +#endif + + /* Are two types/vars the same type (ignoring qualifiers)? */ #ifndef __same_type # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))