2023-07-31 13:05:51

by Christian König

[permalink] [raw]
Subject: [PATCH 1/2] drm/exec: use unique instead of local label

GCC forbids to jump to labels in loop conditions and a new clang
check stumbled over this.

So instead using a local label inside the loop condition use an
unique label outside of it.

Fixes: commit 09593216bff1 ("drm: execution context for GEM buffers v7")
Link: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
Link: https://github.com/ClangBuiltLinux/linux/issues/1890
Link: https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067
Reported-by: Nathan Chancellor <[email protected]>
Reported-by: Naresh Kamboju <[email protected]>
CC: Boris Brezillon <[email protected]>
Signed-off-by: Christian König <[email protected]>
---
include/drm/drm_exec.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
index 73205afec162..e0462361adf9 100644
--- a/include/drm/drm_exec.h
+++ b/include/drm/drm_exec.h
@@ -3,6 +3,7 @@
#ifndef __DRM_EXEC_H__
#define __DRM_EXEC_H__

+#include <linux/compiler.h>
#include <linux/ww_mutex.h>

#define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0)
@@ -74,13 +75,12 @@ struct drm_exec {
* Since labels can't be defined local to the loops body we use a jump pointer
* to make sure that the retry is only used from within the loops body.
*/
-#define drm_exec_until_all_locked(exec) \
- for (void *__drm_exec_retry_ptr; ({ \
- __label__ __drm_exec_retry; \
-__drm_exec_retry: \
- __drm_exec_retry_ptr = &&__drm_exec_retry; \
- (void)__drm_exec_retry_ptr; \
- drm_exec_cleanup(exec); \
+#define drm_exec_until_all_locked(exec) \
+__PASTE(__drm_exec_, __LINE__): \
+ for (void *__drm_exec_retry_ptr; ({ \
+ __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\
+ (void)__drm_exec_retry_ptr; \
+ drm_exec_cleanup(exec); \
});)

/**
--
2.34.1



2023-07-31 13:26:28

by Christian König

[permalink] [raw]
Subject: [PATCH 2/2] drm/exec: add test case for using a drm_exec multiple times

Not really a common use case, but let's make sure that we don't
accidentially break that somehow.

CC: Boris Brezillon <[email protected]>
Signed-off-by: Christian König <[email protected]>
---
drivers/gpu/drm/tests/drm_exec_test.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_exec_test.c b/drivers/gpu/drm/tests/drm_exec_test.c
index 727ac267682e..7b0238c5d9fa 100644
--- a/drivers/gpu/drm/tests/drm_exec_test.c
+++ b/drivers/gpu/drm/tests/drm_exec_test.c
@@ -138,6 +138,26 @@ static void test_prepare_array(struct kunit *test)
drm_exec_fini(&exec);
}

+static void test_multiple_loops(struct kunit *test)
+{
+ struct drm_exec exec;
+
+ drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
+ drm_exec_until_all_locked(&exec)
+ {
+ break;
+ }
+ drm_exec_fini(&exec);
+
+ drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
+ drm_exec_until_all_locked(&exec)
+ {
+ break;
+ }
+ drm_exec_fini(&exec);
+ KUNIT_SUCCEED(test);
+}
+
static struct kunit_case drm_exec_tests[] = {
KUNIT_CASE(sanitycheck),
KUNIT_CASE(test_lock),
@@ -145,6 +165,7 @@ static struct kunit_case drm_exec_tests[] = {
KUNIT_CASE(test_duplicates),
KUNIT_CASE(test_prepare),
KUNIT_CASE(test_prepare_array),
+ KUNIT_CASE(test_multiple_loops),
{}
};

--
2.34.1


2023-07-31 16:21:12

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

On Mon, 31 Jul 2023 08:31:19 -0700
Nathan Chancellor <[email protected]> wrote:

> On Mon, Jul 31, 2023 at 02:36:24PM +0200, Christian König wrote:
> > GCC forbids to jump to labels in loop conditions and a new clang
> > check stumbled over this.
> >
> > So instead using a local label inside the loop condition use an
> > unique label outside of it.
> >
> > Fixes: commit 09593216bff1 ("drm: execution context for GEM buffers v7")
> > Link: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1890
> > Link: https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067
> > Reported-by: Nathan Chancellor <[email protected]>
> > Reported-by: Naresh Kamboju <[email protected]>
> > CC: Boris Brezillon <[email protected]>

Reviewed-by: Boris Brezillon <[email protected]>

> > Signed-off-by: Christian König <[email protected]>
>
> Passes my build tests and I inspected the preprocessed output to make
> sure it should work. I ran the KUnit tests, which all pass (although [1]
> is needed to fix a tangential issue):
>
> Tested-by: Nathan Chancellor <[email protected]>
>
> Thanks for fixing this!
>
> [1]: https://lore.kernel.org/[email protected]/
>
> > ---
> > include/drm/drm_exec.h | 14 +++++++-------
> > 1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
> > index 73205afec162..e0462361adf9 100644
> > --- a/include/drm/drm_exec.h
> > +++ b/include/drm/drm_exec.h
> > @@ -3,6 +3,7 @@
> > #ifndef __DRM_EXEC_H__
> > #define __DRM_EXEC_H__
> >
> > +#include <linux/compiler.h>
> > #include <linux/ww_mutex.h>
> >
> > #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0)
> > @@ -74,13 +75,12 @@ struct drm_exec {
> > * Since labels can't be defined local to the loops body we use a jump pointer
> > * to make sure that the retry is only used from within the loops body.
> > */
> > -#define drm_exec_until_all_locked(exec) \
> > - for (void *__drm_exec_retry_ptr; ({ \
> > - __label__ __drm_exec_retry; \
> > -__drm_exec_retry: \
> > - __drm_exec_retry_ptr = &&__drm_exec_retry; \
> > - (void)__drm_exec_retry_ptr; \
> > - drm_exec_cleanup(exec); \
> > +#define drm_exec_until_all_locked(exec) \
> > +__PASTE(__drm_exec_, __LINE__): \
> > + for (void *__drm_exec_retry_ptr; ({ \
> > + __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\
> > + (void)__drm_exec_retry_ptr; \
> > + drm_exec_cleanup(exec); \
> > });)
> >
> > /**
> > --
> > 2.34.1
> >
> >


2023-07-31 16:36:39

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

On Mon, Jul 31, 2023 at 02:36:24PM +0200, Christian K?nig wrote:
> GCC forbids to jump to labels in loop conditions and a new clang
> check stumbled over this.
>
> So instead using a local label inside the loop condition use an
> unique label outside of it.
>
> Fixes: commit 09593216bff1 ("drm: execution context for GEM buffers v7")
> Link: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
> Link: https://github.com/ClangBuiltLinux/linux/issues/1890
> Link: https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067
> Reported-by: Nathan Chancellor <[email protected]>
> Reported-by: Naresh Kamboju <[email protected]>
> CC: Boris Brezillon <[email protected]>
> Signed-off-by: Christian K?nig <[email protected]>

Passes my build tests and I inspected the preprocessed output to make
sure it should work. I ran the KUnit tests, which all pass (although [1]
is needed to fix a tangential issue):

Tested-by: Nathan Chancellor <[email protected]>

Thanks for fixing this!

[1]: https://lore.kernel.org/[email protected]/

> ---
> include/drm/drm_exec.h | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
> index 73205afec162..e0462361adf9 100644
> --- a/include/drm/drm_exec.h
> +++ b/include/drm/drm_exec.h
> @@ -3,6 +3,7 @@
> #ifndef __DRM_EXEC_H__
> #define __DRM_EXEC_H__
>
> +#include <linux/compiler.h>
> #include <linux/ww_mutex.h>
>
> #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0)
> @@ -74,13 +75,12 @@ struct drm_exec {
> * Since labels can't be defined local to the loops body we use a jump pointer
> * to make sure that the retry is only used from within the loops body.
> */
> -#define drm_exec_until_all_locked(exec) \
> - for (void *__drm_exec_retry_ptr; ({ \
> - __label__ __drm_exec_retry; \
> -__drm_exec_retry: \
> - __drm_exec_retry_ptr = &&__drm_exec_retry; \
> - (void)__drm_exec_retry_ptr; \
> - drm_exec_cleanup(exec); \
> +#define drm_exec_until_all_locked(exec) \
> +__PASTE(__drm_exec_, __LINE__): \
> + for (void *__drm_exec_retry_ptr; ({ \
> + __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\
> + (void)__drm_exec_retry_ptr; \
> + drm_exec_cleanup(exec); \
> });)
>
> /**
> --
> 2.34.1
>
>

2023-08-01 20:59:07

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

On Mon, Jul 31, 2023 at 5:36 AM Christian König
<[email protected]> wrote:
>
> GCC forbids to jump to labels in loop conditions and a new clang
> check stumbled over this.
>
> So instead using a local label inside the loop condition use an
> unique label outside of it.
>
> Fixes: commit 09593216bff1 ("drm: execution context for GEM buffers v7")
> Link: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
> Link: https://github.com/ClangBuiltLinux/linux/issues/1890
> Link: https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067
> Reported-by: Nathan Chancellor <[email protected]>
> Reported-by: Naresh Kamboju <[email protected]>
> CC: Boris Brezillon <[email protected]>
> Signed-off-by: Christian König <[email protected]>

Works for me; thanks for the patch!
Reviewed-by: Nick Desaulniers <[email protected]>

I suspect it's possible to change the indirect goto into a direct goto
with some further refactoring (macros can take block statements; if
drm_exec_until_all_locked accepted a block statement arg then you
could introduce a new scope, and a new local label to that scope, then
just use direct goto), but this will probably apply cleaner. (oh, is
09593216bff1 only in next at the moment? The AuthorDate threw me.)

There are some curious cases where __attribute__((cleanup())) doesn't
mesh well with indirect gotos.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37722

May not ever be a problem here...

> ---
> include/drm/drm_exec.h | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
> index 73205afec162..e0462361adf9 100644
> --- a/include/drm/drm_exec.h
> +++ b/include/drm/drm_exec.h
> @@ -3,6 +3,7 @@
> #ifndef __DRM_EXEC_H__
> #define __DRM_EXEC_H__
>
> +#include <linux/compiler.h>

If you wanted to be more specific (if this addition is due to
__PASTE), then `compiler_types.h` is more precise.

> #include <linux/ww_mutex.h>
>
> #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0)
> @@ -74,13 +75,12 @@ struct drm_exec {
> * Since labels can't be defined local to the loops body we use a jump pointer
> * to make sure that the retry is only used from within the loops body.
> */
> -#define drm_exec_until_all_locked(exec) \
> - for (void *__drm_exec_retry_ptr; ({ \
> - __label__ __drm_exec_retry; \
> -__drm_exec_retry: \
> - __drm_exec_retry_ptr = &&__drm_exec_retry; \
> - (void)__drm_exec_retry_ptr; \
> - drm_exec_cleanup(exec); \
> +#define drm_exec_until_all_locked(exec) \
> +__PASTE(__drm_exec_, __LINE__): \
> + for (void *__drm_exec_retry_ptr; ({ \
> + __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\
> + (void)__drm_exec_retry_ptr; \
> + drm_exec_cleanup(exec); \
> });)
>
> /**
> --
> 2.34.1
>


--
Thanks,
~Nick Desaulniers

2023-08-02 09:16:07

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

On Tue, 1 Aug 2023 13:35:13 -0700
Nick Desaulniers <[email protected]> wrote:

> On Mon, Jul 31, 2023 at 5:36 AM Christian König
> <[email protected]> wrote:
> >
> > GCC forbids to jump to labels in loop conditions and a new clang
> > check stumbled over this.
> >
> > So instead using a local label inside the loop condition use an
> > unique label outside of it.
> >
> > Fixes: commit 09593216bff1 ("drm: execution context for GEM buffers v7")
> > Link: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1890
> > Link: https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067
> > Reported-by: Nathan Chancellor <[email protected]>
> > Reported-by: Naresh Kamboju <[email protected]>
> > CC: Boris Brezillon <[email protected]>
> > Signed-off-by: Christian König <[email protected]>
>
> Works for me; thanks for the patch!
> Reviewed-by: Nick Desaulniers <[email protected]>
>
> I suspect it's possible to change the indirect goto into a direct goto
> with some further refactoring (macros can take block statements; if
> drm_exec_until_all_locked accepted a block statement arg then you
> could introduce a new scope, and a new local label to that scope, then
> just use direct goto),

Maybe I'm wrong, but this sounds like the version I proposed here [1].

> but this will probably apply cleaner. (oh, is
> 09593216bff1 only in next at the moment? The AuthorDate threw me.)
>
> There are some curious cases where __attribute__((cleanup())) doesn't
> mesh well with indirect gotos.
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37722
>
> May not ever be a problem here...

[1]https://patchwork.freedesktop.org/patch/543077/

2023-08-02 21:43:31

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

On Wed, Aug 2, 2023 at 1:44 AM Boris Brezillon
<[email protected]> wrote:
>
> On Tue, 1 Aug 2023 13:35:13 -0700
> Nick Desaulniers <[email protected]> wrote:
>
> > On Mon, Jul 31, 2023 at 5:36 AM Christian König
> > <[email protected]> wrote:
> > >
> > > GCC forbids to jump to labels in loop conditions and a new clang
> > > check stumbled over this.
> > >
> > > So instead using a local label inside the loop condition use an
> > > unique label outside of it.
> > >
> > > Fixes: commit 09593216bff1 ("drm: execution context for GEM buffers v7")
> > > Link: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/1890
> > > Link: https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067
> > > Reported-by: Nathan Chancellor <[email protected]>
> > > Reported-by: Naresh Kamboju <[email protected]>
> > > CC: Boris Brezillon <[email protected]>
> > > Signed-off-by: Christian König <[email protected]>
> >
> > Works for me; thanks for the patch!
> > Reviewed-by: Nick Desaulniers <[email protected]>
> >
> > I suspect it's possible to change the indirect goto into a direct goto
> > with some further refactoring (macros can take block statements; if
> > drm_exec_until_all_locked accepted a block statement arg then you
> > could introduce a new scope, and a new local label to that scope, then
> > just use direct goto),
>
> Maybe I'm wrong, but this sounds like the version I proposed here [1].

Nearly; here's what I was imagining:
```
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 977e1804718d..3ea8beb159f0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -904,7 +904,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
e->user_invalidated = userpage_invalidated;
}

- drm_exec_until_all_locked(&p->exec) {
+ drm_exec_until_all_locked(&p->exec, {
r = amdgpu_vm_lock_pd(&fpriv->vm, &p->exec, 1 + p->gang_size);
drm_exec_retry_on_contention(&p->exec);
if (unlikely(r))
@@ -928,7 +928,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
if (unlikely(r))
goto out_free_user_pages;
}
- }
+ })

amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
struct mm_struct *usermm;
diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
index 73205afec162..8e32a9b704e7 100644
--- a/include/drm/drm_exec.h
+++ b/include/drm/drm_exec.h
@@ -74,14 +74,13 @@ struct drm_exec {
* Since labels can't be defined local to the loops body we use a jump pointer
* to make sure that the retry is only used from within the loops body.
*/
-#define drm_exec_until_all_locked(exec) \
- for (void *__drm_exec_retry_ptr; ({ \
- __label__ __drm_exec_retry; \
-__drm_exec_retry: \
- __drm_exec_retry_ptr = &&__drm_exec_retry; \
- (void)__drm_exec_retry_ptr; \
- drm_exec_cleanup(exec); \
- });)
+#define drm_exec_until_all_locked(exec, block) \
+ { \
+ __label__ __drm_exec_retry; \
+__drm_exec_retry: \
+ while (drm_exec_cleanup(exec)) \
+ block \
+}

/**
* drm_exec_retry_on_contention - restart the loop to grap all locks
@@ -93,7 +92,7 @@ __drm_exec_retry:
\
#define drm_exec_retry_on_contention(exec) \
do { \
if (unlikely(drm_exec_is_contended(exec))) \
- goto *__drm_exec_retry_ptr; \
+ goto __drm_exec_retry; \
} while (0)

/**
```
(only updated one macro expansion site in
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c, didn't add proper trailing
tabs to macro but you get the gist).

But I think both compilers can optimize out the unnecessary
indirection when it's obvious, so I don't think it matters much, other
than the tastes of whoever has to maintain this.


>
> > but this will probably apply cleaner. (oh, is
> > 09593216bff1 only in next at the moment? The AuthorDate threw me.)
> >
> > There are some curious cases where __attribute__((cleanup())) doesn't
> > mesh well with indirect gotos.
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37722
> >
> > May not ever be a problem here...
>
> [1]https://patchwork.freedesktop.org/patch/543077/



--
Thanks,
~Nick Desaulniers

2023-08-09 15:55:54

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

Hi Christian,

Can this be applied to drm-misc? Other drivers are starting to make use
of this API and our builds with clang-17 and clang-18 have been broken
for some time due to this.

Cheers,
Nathan

On Mon, Jul 31, 2023 at 02:36:24PM +0200, Christian K?nig wrote:
> GCC forbids to jump to labels in loop conditions and a new clang
> check stumbled over this.
>
> So instead using a local label inside the loop condition use an
> unique label outside of it.
>
> Fixes: commit 09593216bff1 ("drm: execution context for GEM buffers v7")
> Link: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
> Link: https://github.com/ClangBuiltLinux/linux/issues/1890
> Link: https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067
> Reported-by: Nathan Chancellor <[email protected]>
> Reported-by: Naresh Kamboju <[email protected]>
> CC: Boris Brezillon <[email protected]>
> Signed-off-by: Christian K?nig <[email protected]>
> ---
> include/drm/drm_exec.h | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
> index 73205afec162..e0462361adf9 100644
> --- a/include/drm/drm_exec.h
> +++ b/include/drm/drm_exec.h
> @@ -3,6 +3,7 @@
> #ifndef __DRM_EXEC_H__
> #define __DRM_EXEC_H__
>
> +#include <linux/compiler.h>
> #include <linux/ww_mutex.h>
>
> #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0)
> @@ -74,13 +75,12 @@ struct drm_exec {
> * Since labels can't be defined local to the loops body we use a jump pointer
> * to make sure that the retry is only used from within the loops body.
> */
> -#define drm_exec_until_all_locked(exec) \
> - for (void *__drm_exec_retry_ptr; ({ \
> - __label__ __drm_exec_retry; \
> -__drm_exec_retry: \
> - __drm_exec_retry_ptr = &&__drm_exec_retry; \
> - (void)__drm_exec_retry_ptr; \
> - drm_exec_cleanup(exec); \
> +#define drm_exec_until_all_locked(exec) \
> +__PASTE(__drm_exec_, __LINE__): \
> + for (void *__drm_exec_retry_ptr; ({ \
> + __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\
> + (void)__drm_exec_retry_ptr; \
> + drm_exec_cleanup(exec); \
> });)
>
> /**
> --
> 2.34.1
>

2023-08-10 07:10:33

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

On Wed, 9 Aug 2023 08:37:55 -0700
Nathan Chancellor <[email protected]> wrote:

> Hi Christian,
>
> Can this be applied to drm-misc? Other drivers are starting to make use
> of this API and our builds with clang-17 and clang-18 have been broken
> for some time due to this.

Queued to drm-misc-next.

2023-08-10 07:26:41

by Christian König

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

Am 10.08.23 um 08:40 schrieb Boris Brezillon:
> On Wed, 9 Aug 2023 08:37:55 -0700
> Nathan Chancellor <[email protected]> wrote:
>
>> Hi Christian,
>>
>> Can this be applied to drm-misc? Other drivers are starting to make use
>> of this API and our builds with clang-17 and clang-18 have been broken
>> for some time due to this.
> Queued to drm-misc-next.

Sorry for the delay I have been on vacation last week and haven't yet
catched up to this point in my mails.

Thanks for taking care of this,
Christian.

2023-08-10 09:22:10

by Rasmus Villemoes

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

On 01/08/2023 22.35, Nick Desaulniers wrote:

> I suspect it's possible to change the indirect goto into a direct goto
> with some further refactoring (macros can take block statements;

Well, with some somewhat subtle restrictions. C99, 6.10.3.11. "The
sequence of preprocessing tokens bounded by the outside-most matching
parentheses forms the list of arguments for the function-like macro. The
individual arguments within the list are separated by comma
preprocessing tokens, but comma preprocessing tokens between matching
inner parentheses do not separate arguments."

cpp doesn't care about the {} tokens when trying to figure out what
constitutes the "block" argument, so if that block contained any comma
outside a () pair, cpp would barf something like

error: macro "foo" passed 3 arguments, but takes just 2

So while the commas inside function calls (and other macro invocations)
are fine, constructs like

int x, y;

or

struct s s = {.a = 3, .b = 4}

would be verboten inside that block.

One way around that is to make block a variadic argument so it just
gobbles up all preprocessor token. Or have the users pass a statement
expression instead of a block.

Rasmus


2023-08-10 15:07:40

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH 1/2] drm/exec: use unique instead of local label

On Thu, Aug 10, 2023 at 08:48:05AM +0200, Christian K?nig wrote:
> Am 10.08.23 um 08:40 schrieb Boris Brezillon:
> > On Wed, 9 Aug 2023 08:37:55 -0700
> > Nathan Chancellor <[email protected]> wrote:
> >
> > > Hi Christian,
> > >
> > > Can this be applied to drm-misc? Other drivers are starting to make use
> > > of this API and our builds with clang-17 and clang-18 have been broken
> > > for some time due to this.
> > Queued to drm-misc-next.
>
> Sorry for the delay I have been on vacation last week and haven't yet
> catched up to this point in my mails.

No worries, 'tis the season :) hope it was a good time and thank you
both for getting this fixed!

Cheers,
Nathan