ValhallaTeam / angleproject

Automatically exported from code.google.com/p/angleproject
Other
0 stars 0 forks source link

glslang_lex.cpp does not compile with -Wshorten-64-to-32 #409

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile ANGLE with clang with -Wshorten-64-to-32 warning enabled.

What is the expected output? What do you see instead?
Expected no warnings.  Got warnings.

What version of the product are you using? On what operating system?
ANGLE r1641 merged into the WebKit project.

Please provide any additional information below.

glslang_lex.cpp:1546:19: error: implicit conversion loses integer precision: 
'long' to 'int' [-Werror,-Wshorten-64-to-32]
{ yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }
                ~ ^~~~~~~~~~~~~~~~~~~~
glslang_lex.cpp:1550:19: error: implicit conversion loses integer precision: 
'long' to 'int' [-Werror,-Wshorten-64-to-32]
{ yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }
                ~ ^~~~~~~~~~~~~~~~~~~~
glslang_lex.cpp:1558:19: error: implicit conversion loses integer precision: 
'long' to 'int' [-Werror,-Wshorten-64-to-32]
{ yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }
                ~ ^~~~~~~~~~~~~~~~~~~~
glslang_lex.cpp:2012:21: error: implicit conversion loses integer precision: 
'yy_size_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
                        yyg->yy_n_chars, num_to_read );
                        ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
glslang_lex.cpp:822:32: note: expanded from:
    result = string_input(buf, max_size, yyscanner);
             ~~~~~~~~~~~~      ^
glslang_lex.cpp:2954:51: error: implicit conversion loses integer precision: 
'size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
    int len = token.type == pp::Token::LAST ? 0 : token.text.size();
                                            ~     ^~~~~~~~~~~~~~~~~
5 errors generated.

The first three errors are because the 'i' member of struct lex in gslang_tab.h 
is defined as an 'int':

    struct {
        TSourceLoc line;
        union {
            TString *string;
            float f;
            int i;
            bool b;
        };
        TSymbol* symbol;
    } lex;

 and it is being assigned the output of strtol():

{ yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }

The fourth error is because the string_input() method uses an 'int' for the 
'max_size' parameter instead of 'size_t':

int string_input(char* buf, int max_size, yyscan_t yyscanner) {

The fifth error is because the local 'len' variable in string_input() is an 
'int' instead of a 'size_t'.


Original issue reported on code.google.com by ddkilzer@gmail.com on 27 Jan 2013 at 10:36

GoogleCodeExporter commented 9 years ago
Ironically, of all the -Wshorten-64-to-32 issues, this is the most 
straightforward to fix.

Attached a patch to fix this against WebKit r140912.  Parts of it may need to 
be ignored or fixed manually to apply to the ANGLE source.

Original comment by ddkilzer@gmail.com on 27 Jan 2013 at 10:42

Attachments:

GoogleCodeExporter commented 9 years ago
Note that after changing the local 'len' variable to 'size_t' in 
string_input(), that causes another -Wshorten-64-to-32 compiler error because 
string_input() returns 'int'.  However, changing string_input() to return 
'size_t' instead works fine because 'result' in the YY_INPUT() macro is 
'yyg->yy_n_chars' and yy_n_chars is of type 'yy_size_t' which is 'size_t'.

Original comment by ddkilzer@gmail.com on 27 Jan 2013 at 10:49

GoogleCodeExporter commented 9 years ago

Original comment by kbr@chromium.org on 7 Feb 2013 at 1:14

GoogleCodeExporter commented 9 years ago
Fixed in https://code.google.com/p/angleproject/source/detail?r=1826 .

Original comment by kbr@chromium.org on 12 Feb 2013 at 3:11