Bug 100227 - gl_marshal.py: generating duplicate declaration specifiers
Summary: gl_marshal.py: generating duplicate declaration specifiers
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: git
Hardware: Other All
: medium normal
Assignee: mesa-dev
QA Contact: mesa-dev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-16 10:50 UTC by Tapani Pälli
Modified: 2018-05-02 03:10 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
attempt to fix warnings (1.77 KB, patch)
2017-03-16 11:13 UTC, Tapani Pälli
Details | Splinter Review

Description Tapani Pälli 2017-03-16 10:50:31 UTC
generator is generating following code:

const const GLvoid * pointer = cmd->pointer;

that results later as compilation warning:

--- 8< ---
marshal_generated.c:15836:10: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier] const const GLvoid * pointer = cmd->pointer;
--- 8< ---

I've tried to fix this by inserting const decl specifier only if p.string() does not already start with 'const' but this will create new compilation warnings like:

--- 8< ---
main/marshal_generated.c:29774:18: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
     GLbyte * v = cmd->v;
--- 8< ---

I'm filing this so that some Python guru can take a look at it.
Comment 1 Tapani Pälli 2017-03-16 11:13:11 UTC
Created attachment 130255 [details] [review]
attempt to fix warnings

this was my 1st attempt to fix this
Comment 2 Gustaw Smolarczyk 2017-05-04 17:36:51 UTC
I didn't really looked at the python generator, but this is what came to my mind: maybe one of the consts was meant to be applied to the pointee type? So instead of "const const GLvoid *", it should be "const GLvoid *const"?
Comment 3 Bartosz Tomczyk 2017-05-05 11:14:54 UTC
I agree with  Gustaw, that it should be changed to  "const GLvoid *const".

Something like that should work(not tested):

--- a/src/mapi/glapi/gen/gl_marshal.py
+++ b/src/mapi/glapi/gen/gl_marshal.py
@@ -177,11 +177,11 @@ class PrintCode(gl_XML.gl_print_base):
         with indent():
             for p in func.fixed_params:
                 if p.count:
-                    out('const {0} * {1} = cmd->{1};'.format(
-                            p.get_base_type_string(), p.name))
+                    out('const {0} * const {1} = cmd->{1};'.format(
+                            p.get_base_type_string().lstrip('const'), p.name))
                 else:
                     out('const {0} {1} = cmd->{1};'.format(
-                            p.type_string(), p.name))
+                            p.type_string().lstrip('const'), p.name))
             if func.variable_params:
                 for p in func.variable_params:
                     out('const {0} * {1};'.format(
Comment 4 Nicolai Hähnle 2017-05-08 09:45:00 UTC
Gustaw, you're right. Can you prepare a patch that moves the const in the right place?

Bartosz, the lstrip() should not be required.
Comment 5 Timothy Arceri 2018-05-02 03:10:21 UTC
Fixed by:

commit 31c3c440b5361299fc0529bcf049e9b271d4fab9
Author: Chad Versace <chadversary@chromium.org>
Date:   Thu Jun 22 15:12:29 2017 -0700

    glapi: Fix -Wduplicate-decl-specifier due to double-const
    
    Fix all lines in src/mesa/main/marshal_generated.c that declare
    double-const variables. Below is all such lines, with duplicates
    removed:
    
       $ grep 'const const' marshal_generated.c | sort -u
       const const GLboolean * pointer = cmd->pointer;
       const const GLvoid * indices = cmd->indices;
       const const GLvoid * pointer = cmd->pointer;
    
    Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.