drm/amdgpu: Add braces to initialize task_info subojects
Subsystems (2)
PATCH 1/1 drm/amdgpu: Add braces to initialize task_info subojects
Clang warns if there are missing braces around a subobject initializer.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c:1447:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]
struct amdgpu_task_info task_info = { 0 };
^
{}1 warning generated.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c:262:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]
struct amdgpu_task_info task_info = { 0 };
^
{}1 warning generated.
--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -1
@@ -1444,7 +1444,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,gmc_v8_0_set_fault_enable_default (adev, false);if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
@@ -259,7 +259,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, }if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);
Signature · 1 line
2.18.0
Quoted 30 lines · Nathan Chancellor
Clang warns if there are missing braces around a subobject initializer.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c:1447:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c:262:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev, · line 1447
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1
-1@@ -1444,7 +1444,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,gmc_v8_0_set_fault_enable_default (adev, false);if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };
Hi Nathan,
Thanks for this patch. I discussed this syntax with our language lawyers. Turns out, this is not quite correct, as you're now saying "initialize the first subobject to zero, but not the rest of the object." -Wmissing-field-initializers would highlight this, but it's not part of -Wall. It would be more correct to zero initialize the full struct, including all of its subobjects with = {};.
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1
-2@@ -259,7 +259,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, }if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };amdgpu_vm_get_task_info (adev, entry->pasid, &task_info); --2.18.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 34 lines · Nick Desaulniers
Quoted 32 lines · Nathan Chancellor
Clang warns if there are missing braces around a subobject initializer.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c:1447:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c:262:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0@@ -1444,7 +1444,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,gmc_v8_0_set_fault_enable_default (adev, false);
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev, · line 1447
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1
-1if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };Hi Nathan,
Thanks for this patch. I discussed this syntax with our language lawyers. Turns out, this is not quite correct, as you're now saying "initialize the first subobject to zero, but not the rest of the object." -Wmissing-field-initializers would highlight this, but it's not part of -Wall. It would be more correct to zero initialize the full struct, including all of its subobjects with= {};.
Good point, I was debating on which one was correct. There are several places in this driver that use the multiple brace + 0 idiom, which is why I used this form. I will spin up a v2 with your suggestion, thank you for the review!
Nathan
Quoted 24 lines
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1
-2@@ -259,7 +259,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, }if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };amdgpu_vm_get_task_info (adev, entry->pasid, &task_info); --2.18.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 49 lines · Nathan Chancellor
Quoted 34 lines · Nick Desaulniers
Quoted 32 lines · Nathan Chancellor
Clang warns if there are missing braces around a subobject initializer.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c:1447:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c:262:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0@@ -1444,7 +1444,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,gmc_v8_0_set_fault_enable_default (adev, false);Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev, · line 1447
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1
-1if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };Hi Nathan,
Thanks for this patch. I discussed this syntax with our language lawyers. Turns out, this is not quite correct, as you're now saying "initialize the first subobject to zero, but not the rest of the object." -Wmissing-field-initializers would highlight this, but it's not part of -Wall. It would be more correct to zero initialize the full struct, including all of its subobjects with= {};.
Quoted 4 lines
Good point, I was debating on which one was correct. There are several places in this driver that use the multiple brace + 0 idiom, which is why I used this form. I will spin up a v2 with your suggestion, thank you for the review!
Feel free to fix up the others as well. The others were only changed due to the same warning you sent the patch for.
Alex
Quoted 27 lines
Nathan
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1
-1@@ -259,7 +259,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, }if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);Quoted 8 lines
Quoted 3 lines
--
2.18.0--
Thanks,
~Nick Desaulniers
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 56 lines · Alex Deucher
Quoted 49 lines · Nathan Chancellor
Quoted 34 lines · Nick Desaulniers
Quoted 32 lines · Nathan Chancellor
Clang warns if there are missing braces around a subobject initializer.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c:1447:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c:262:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0@@ -1444,7 +1444,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,gmc_v8_0_set_fault_enable_default (adev, false);Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev, · line 1447
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1
-1if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };Hi Nathan,
Thanks for this patch. I discussed this syntax with our language lawyers. Turns out, this is not quite correct, as you're now saying "initialize the first subobject to zero, but not the rest of the object." -Wmissing-field-initializers would highlight this, but it's not part of -Wall. It would be more correct to zero initialize the full struct, including all of its subobjects with= {};.Quoted 4 lines
Good point, I was debating on which one was correct. There are several places in this driver that use the multiple brace + 0 idiom, which is why I used this form. I will spin up a v2 with your suggestion, thank you for the review!
Quoted 5 lines
Feel free to fix up the others as well. The others were only changed due to the same warning you sent the patch for.
Alex
Hi Alex,
Thank you for the information, I will do that in v2.
Thanks,
Nathan
Quoted 31 lines
Quoted 31 lines
Nathan
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1
-1@@ -259,7 +259,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, }if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);Quoted 8 lines
Quoted 3 lines
--
2.18.0--
Thanks,
~Nick Desaulniers_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CAKwvOdkMg_1JxVNhKrUM0CZxF6nQo8c5h7t4zu4RP2xEXyQdKQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 40 lines · Nick Desaulniers
Quoted 18 lines · Nathan Chancellor
Clang warns if there are missing braces around a subobject initializer.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c:1447:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c:262:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
Review
Quoted 8 lines
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.cdrivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct
Quoted 4 lines
index
9333109b210d..968cc1b8cdff100644drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0@@ -1444,7 +1444,7 @@ static int gmc_v8_0_process_interrupt(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev, · line 1447
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1
-1gmc_v8_0_set_fault_enable_default (adev, false);if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };
Quoted 8 lines
Hi Nathan,
Thanks for this patch. I discussed this syntax with our language lawyers. Turns out, this is not quite correct, as you're now saying "initialize the first subobject to zero, but not the rest of the object." -Wmissing-field-initializers would highlight this, but it's not part of -Wall. It would be more correct to zero initialize the full struct, including all of its subobjects with= {};.
Sorry, I think I've caused some confusion here.
Elements with an omitted initializer get implicitly zero-initialized. In C++, it's idiomatic to write = {} to perform aggregate zero-initialization, but in C, that's invalid because at least one initializer is syntactically required within the braces. As a result, = {0} is an idiomatic way to perform zero-initialization of an aggregate in C. Clang intends to suppress the -Wmissing-braces in that case; if the warning is still being produced in a recent version of Clang, that's a bug. However, the warning suppression was added between Clang 5 and Clang 6, so it's very plausible that the compiler being used here is simply older than the warning fix.
(Long story short: the change here seems fine, but should be unnecessary as of Clang 6.)
Quoted 17 lines
Review
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.cdrivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct
Quoted 4 lines
index
72f8018fa2a8..a781a5027212100644drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0@@ -259,7 +259,7 @@ static int gmc_v9_0_process_interrupt(struct
amdgpu_device*adev,Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1
-1}if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);
Quoted 9 lines
Quoted 3 lines
--
2.18.0--
Thanks,
~Nick Desaulniers
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 65 lines · Richard Smith
Quoted 40 lines · Nick Desaulniers
Quoted 18 lines · Nathan Chancellor
Clang warns if there are missing braces around a subobject initializer.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c:1447:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c:262:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
Review
Quoted 8 lines
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.cdrivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct
Quoted 4 lines
index
9333109b210d..968cc1b8cdff100644drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0@@ -1444,7 +1444,7 @@ static int gmc_v8_0_process_interrupt(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev, · line 1447
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1
-1gmc_v8_0_set_fault_enable_default (adev, false);if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };Quoted 8 lines
Hi Nathan,
Thanks for this patch. I discussed this syntax with our language lawyers. Turns out, this is not quite correct, as you're now saying "initialize the first subobject to zero, but not the rest of the object." -Wmissing-field-initializers would highlight this, but it's not part of -Wall. It would be more correct to zero initialize the full struct, including all of its subobjects with= {};.Sorry, I think I've caused some confusion here.
Elements with an omitted initializer get implicitly zero-initialized. In C++, it's idiomatic to write
= {}to perform aggregate zero-initialization, but in C, that's invalid because at least one initializer is syntactically required within the braces. As a result,= {0}is an idiomatic way to perform zero-initialization of an aggregate in C. Clang intends to suppress the -Wmissing-braces in that case; if the warning is still being produced in a recent version of Clang, that's a bug. However, the warning suppression was added between Clang 5 and Clang 6, so it's very plausible that the compiler being used here is simply older than the warning fix.
Quoted 3 lines
(Long story short: the change here seems fine, but should be unnecessary as of Clang 6.)
Interesting...
nathan@flashbox ~/kernels/next (master >) $ clang --version | head -n1 clang version 6.0.1 (tags/RELEASE_601/final)
I guess the v2 I sent is unnecessary then. I'll leave it up to the maintainers to decide which one they want to take.
Thanks!
Nathan
Quoted 27 lines
Quoted 27 lines
Review
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.cdrivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct
Quoted 4 lines
index
72f8018fa2a8..a781a5027212100644drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0@@ -259,7 +259,7 @@ static int gmc_v9_0_process_interrupt(struct
amdgpu_device*adev,Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1
-2}if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };amdgpu_vm_get_task_info (adev, entry->pasid, &task_info); --2.18.0
--
Thanks,
~Nick Desaulniers
Quoted 50 lines · Richard Smith
Quoted 35 lines · Nick Desaulniers
Quoted 32 lines · Nathan Chancellor
Clang warns if there are missing braces around a subobject initializer.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c:1447:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c:262:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0@@ -1444,7 +1444,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,gmc_v8_0_set_fault_enable_default (adev, false);Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev, · line 1447
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1
-1if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };Hi Nathan,
Thanks for this patch. I discussed this syntax with our language lawyers. Turns out, this is not quite correct, as you're now saying "initialize the first subobject to zero, but not the rest of the object." -Wmissing-field-initializers would highlight this, but it's not part of -Wall. It would be more correct to zero initialize the full struct, including all of its subobjects with= {};.
Quoted 3 lines
Sorry, I think I've caused some confusion here.
Elements with an omitted initializer get implicitly zero-initialized. In C++, it's idiomatic to write
= {}to perform aggregate zero-initialization, but in C, that's invalid because at least one initializer is syntactically required within the braces. As a result,= {0}is an idiomatic way to perform zero-initialization of an aggregate in C.
That doesn't seem to be the case:
https://godbolt.org/z/TZzfo6 shouldn't Clang warn in the case of bar()?
Quoted 3 lines
Clang intends to suppress the -Wmissing-braces in that case; if the warning is still being produced in a recent version of Clang, that's a bug. However, the warning suppression was added between Clang 5 and Clang 6, so it's very plausible that the compiler being used here is simply older than the warning fix.
(Long story short: the change here seems fine, but should be unnecessary as of Clang 6.)
The warning was identified from clang-8 ToT synced yesterday.
Signature · 2 lines
Thanks, ~Nick Desaulniers
A message that is not in the archive (sent off-list or not yet received): CAKwvOdkSy74TKqASdMtWwHKOeAVQn+mEfv0Fi8q+-35dGjXtHA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 58 lines · Nick Desaulniers
Quoted 2 lines · Richard Smith
On Wed, Sep 12, 2018 at 10:38 AM Nick Desaulniers <
Quoted 21 lines · [email protected]> wrote:
Quoted 21 lines
Quoted 18 lines · Nathan Chancellor
Clang warns if there are missing braces around a subobject initializer.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c:1447:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c:262:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct amdgpu_task_info task_info = { 0 }; ^ {}1 warning generated.
Quoted 8 lines
Quoted 8 lines
Review
Quoted 8 lines
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.cQuoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct
Quoted 4 lines
index
9333109b210d..968cc1b8cdff100644drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0@@ -1444,7 +1444,7 @@ static int gmc_v8_0_process_interrupt(struct
amdgpu_device*adev,Quoted 15 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev, · line 1447
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1
-1gmc_v8_0_set_fault_enable_default (adev, false);if (printk_ratelimit ()) { -struct amdgpu_task_info task_info = {0 }; +struct amdgpu_task_info task_info = { {0 } };Quoted 7 lines
Hi Nathan,
Thanks for this patch. I discussed this syntax with our language lawyers. Turns out, this is not quite correct, as you're now saying "initialize the first subobject to zero, but not the rest of the object." -Wmissing-field-initializers would highlight this, but it's not part of -Wall. It would be more correct to zero initialize the full struct, including all of its subobjects with= {};.Quoted 3 lines
Sorry, I think I've caused some confusion here.
Elements with an omitted initializer get implicitly zero-initialized. In
Quoted 9 lines
C++, it's idiomatic to write
= {}to perform aggregate zero-initialization, but in C, that's invalid because at least one initializer is syntactically required within the braces. As a result,= {0}is an idiomatic way to perform zero-initialization of an aggregate in C.That doesn't seem to be the case:
https://godbolt.org/z/TZzfo6 shouldn't Clang warn in the case ofbar()?
This is a GNU extension. Use -pedantic-errors to turn off extensions, then Clang and GCC reject bar(): https://godbolt.org/z/pIzI6M
Quoted 11 lines
Quoted 1 line
Clang intends to suppress the -Wmissing-braces in that case; if the
warning is still being produced in a recent version of Clang, that's a bug. However, the warning suppression was added between Clang 5 and Clang 6, so it's very plausible that the compiler being used here is simply older than the warning fix.
Quoted 2 lines
(Long story short: the change here seems fine, but should be unnecessary
as of Clang 6.)
The warning was identified from clang-8 ToT synced yesterday.
Thanks for the testcase. This is a Clang bug. Apparently the warning suppression only works when the first member is of type 'int'!
https://godbolt.org/z/sxnZvv
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx