diff options
author | whitequark <whitequark@whitequark.org> | 2020-04-09 04:02:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 04:02:57 +0000 |
commit | f1d9ca15632125eed9dd71df72fa4e191163aa18 (patch) | |
tree | 20da4c563178046fe75f4895eeefbbe520af3f55 /frontends | |
parent | 570f43ec911837a4d0a0b888099b4adebdc3ff8c (diff) | |
parent | b494d4c6565bcf0ef063e632a51b215e199ea22e (diff) | |
download | yosys-f1d9ca15632125eed9dd71df72fa4e191163aa18.tar.gz yosys-f1d9ca15632125eed9dd71df72fa4e191163aa18.tar.bz2 yosys-f1d9ca15632125eed9dd71df72fa4e191163aa18.zip |
Merge pull request #1875 from whitequark/read_ilang-int_overflow
Improve handling of integer literals in RTLIL frontend
Diffstat (limited to 'frontends')
-rw-r--r-- | frontends/ilang/ilang_lexer.l | 13 | ||||
-rw-r--r-- | frontends/ilang/ilang_parser.y | 3 |
2 files changed, 14 insertions, 2 deletions
diff --git a/frontends/ilang/ilang_lexer.l b/frontends/ilang/ilang_lexer.l index 4fd0ae855..62f53d18e 100644 --- a/frontends/ilang/ilang_lexer.l +++ b/frontends/ilang/ilang_lexer.l @@ -29,6 +29,7 @@ #pragma clang diagnostic ignored "-Wdeprecated-register" #endif +#include <cstdlib> #include "frontends/ilang/ilang_frontend.h" #include "ilang_parser.tab.hh" @@ -88,7 +89,16 @@ USING_YOSYS_NAMESPACE "."[0-9]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; } [0-9]+'[01xzm-]* { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_VALUE; } --?[0-9]+ { rtlil_frontend_ilang_yylval.integer = atoi(yytext); return TOK_INT; } +-?[0-9]+ { + char *end = nullptr; + long value = strtol(yytext, &end, 10); + if (end != yytext + strlen(yytext)) + return TOK_INVALID; // literal out of range of long + if (value < INT_MIN || value > INT_MAX) + return TOK_INVALID; // literal out of range of int (relevant mostly for LP64 platforms) + rtlil_frontend_ilang_yylval.integer = value; + return TOK_INT; +} \" { BEGIN(STRING); } <STRING>\\. { yymore(); } @@ -136,4 +146,3 @@ USING_YOSYS_NAMESPACE void *rtlil_frontend_ilang_avoid_input_warnings() { return (void*)&yyinput; } - diff --git a/frontends/ilang/ilang_parser.y b/frontends/ilang/ilang_parser.y index 4e0b62edd..91adc0cc9 100644 --- a/frontends/ilang/ilang_parser.y +++ b/frontends/ilang/ilang_parser.y @@ -179,6 +179,9 @@ wire_options: wire_options TOK_WIDTH TOK_INT { current_wire->width = $3; } | + wire_options TOK_WIDTH TOK_INVALID { + rtlil_frontend_ilang_yyerror("ilang error: invalid wire width"); + } | wire_options TOK_UPTO { current_wire->upto = true; } | |