Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: kernel test robot <lkp@intel.com>,
	oe-kbuild-all@lists.linux.dev, Tejun Heo <tj@kernel.org>,
	Yury Norov <yury.norov@gmail.com>,
	clang-built-linux@googlegroups.com,
	"llvm@lists.linux.dev" <llvm@lists.linux.dev>
Subject: Re: [linux-next:master 3203/9634] arch/powerpc/include/asm/bitops.h:126:26: error: constraint 'n' expects an integer constant expression
Date: Sun, 9 Mar 2025 21:47:23 +0100	[thread overview]
Message-ID: <Z83-WxJsAN53G6Pj@gpd3> (raw)
In-Reply-To: <4967dc7d-dc87-48d9-a44d-2d667c2841f0@csgroup.eu>

Hi Christophe,

On Sun, Mar 09, 2025 at 07:48:56PM +0100, Christophe Leroy wrote:
...
> #define DEFINE_CLROP(fn, prefix)					\
> static inline void fn(unsigned long mask, volatile unsigned long *_p)	\
> {									\
> 	unsigned long old;						\
> 	unsigned long *p = (unsigned long *)_p;				\
> 									\
> 	if (IS_ENABLED(CONFIG_PPC32) &&					\
> 	    __builtin_constant_p(mask) && is_rlwinm_mask_valid(~mask)) {\
> 		asm volatile (						\
> 			prefix						\
> 		"1:"	"lwarx	%0,0,%3\n"				\
> 			"rlwinm	%0,%0,0,%2\n"				\
> 			"stwcx.	%0,0,%3\n"				\
> 			"bne- 1b\n"					\
> 			: "=&r" (old), "+m" (*p)			\
> 			: "n" (~mask), "r" (p)				\
> 			: "cc", "memory");				\
> 	} else {							\
> 		asm volatile (						\
> 			prefix						\
> 		"1:"	PPC_LLARX "%0,0,%3,0\n"				\
> 			"andc %0,%0,%2\n"				\
> 			PPC_STLCX "%0,0,%3\n"				\
> 			"bne- 1b\n"					\
> 			: "=&r" (old), "+m" (*p)			\
> 			: "r" (mask), "r" (p)				\
> 			: "cc", "memory");				\
> 	}								\
> }
> 
> 
> clang says "constraint 'n' expects an integer constant expression" ?
> 
> The only place I see 'n' constraint in that macro is the '"n" (~mask)' in
> the if __builtin_constant_p(mask) branch. As far as I know if mask is a
> constant (~mask) is also a constant ?

Right, that's my understanding as well.

> 
> Must be a clang bug ?

Possibly...

> 
> Maybe try with __builtin_constant_p(~mask) instead of
> __builtin_constant_p(mask)

I tried using ~mask, and even tried to use just mask throughout the
entire macro (although the code would be incorrect), but I still get the
same build error.

The only way that I found to fix this is by adding
!IS_ENABLED(CONFIG_CC_IS_CLANG) to the if, which isn't really elegant, but
maybe it's a reasonable workaround? I'll also open a clang issue in the
meantime.

Thanks,
-Andrea

      reply	other threads:[~2025-03-09 20:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <202503090435.wITkzD2e-lkp@intel.com>
     [not found] ` <Z81TSQHHaNq_Aj4x@gpd3>
2025-03-09 18:48   ` [linux-next:master 3203/9634] arch/powerpc/include/asm/bitops.h:126:26: error: constraint 'n' expects an integer constant expression Christophe Leroy
2025-03-09 20:47     ` Andrea Righi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z83-WxJsAN53G6Pj@gpd3 \
    --to=arighi@nvidia.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=clang-built-linux@googlegroups.com \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox