Commit Graph

49 Commits

Author SHA1 Message Date
Vitaly Mogulian
219a9b1e14 Fortran: Fix suprious dependencies with submodules
In commit 695f0d0d3a (cmFortranParser: Parse keywords as lexical tokens,
2016-09-05, v3.7.0-rc1~150^2) we created keyword-specific variants of
the original `USE WORD other EOSTMT` production, such as
`MODULE WORD other EOSTMT` and `INTERFACE WORD other EOSTMT`.  The same
pattern was used by more keyword-specific productions in commit b5ac8b8aa7
(Fortran: Add support for submodule syntax in dependency scanning,
2016-09-05, v3.7.0-rc1~73^2~1).

The postfix part (`other`) of several keyword-specific productions is
not needed to match Fortran syntax.  See the Fortran 2018 standard,
para.4.1.4/1 on p.28, para.14.2.1/2 on pp.293-294.  The postfix is
needed only for a case of operator 'use':

    use <module-name> [, only : <list-of-vars>]

The unnecessary postfix matching from the keyword-specific productions
such as module, submodule, and interface declarations can cause spurious
module dependencies to be detected, so remove it.

Extend the test suite with examples covering the previously-broken
cases.

Fixes: #18427
2022-08-09 09:11:30 -04:00
Brad King
a7211d6a2f Fortran: Teach lexer to handle CRLF newlines
We read sources in binary format, so we need to explicitly match CR
(`\r`) characters that occur as part of newlines in CRLF sources.
This is particularly important when line continuation (`&`) occurs
in the middle of module declaration or usage.
2022-08-09 09:09:51 -04:00
Brad King
2646d5dfcf LexerParser: Suppress clang -Wunused-but-set-variable warnings 2022-04-06 16:02:03 -04:00
Brad King
8add899c03 LexerParser: Regenerate parsers with bison 3.8.2 2022-04-06 16:02:03 -04:00
Marc Chevrier
e04a352cca Depfile parsing: enhance compatibility with GNU Make 2022-01-16 14:05:59 +01:00
Isuru Fernando
fe3f846e1b Makefiles: Add support for building Fortran intrinsics
Fixes: #21463
2021-06-24 08:39:47 -04:00
Brad King
fda060f030 LexerParser: Do not leak Fortran parser tokens discarded due to errors 2021-06-08 09:13:50 -04:00
Brad King
c1b575f4d1 clang-analyzer: rename from scan-build in comments 2021-06-03 14:59:55 -04:00
Brad King
16275c7f82 LexerParser: Suppress NVHPC warnings in generated code 2021-04-28 10:09:35 -04:00
Brad King
cefda16d35 LexerParser: Regenerate parsers with bison 3.7.5 2021-04-28 10:08:22 -04:00
Brad King
aac80ec1ee LexerParser: Suppress gcc -Wfree-nonheap-object warnings in generated code 2021-02-05 06:48:44 -05:00
Brad King
7c6192472b LexerParser: Suppress -Wused-but-marked-unused warning in cmExprParser 2021-01-26 14:33:52 -05:00
Christoph Grüninger
6f64300a01 LexerParser: Clean up includes following include-what-you-use 2021-01-25 12:06:28 -05:00
Christoph Grüninger
699d50e376 LexerParser: Regenerate parser files with GNU Bison 3.7.4
Adjust expected test output.
2021-01-25 12:06:17 -05:00
Christoph Grüninger
c95442b9b1 LexerParser: Manual removing code from Bison is no longer needed
This was needed to avoid warnings while compiling the sources generated
by older versions of GNU Bison, but is not with GNU Bison 3.7.4.
2021-01-25 12:05:36 -05:00
Christoph Grüninger
5a8a61a798 LexerParser: Do not use GNU Bison's yacc mode, we use Bison extensions
Silence Bison warnings regarding use of Bison extensions.
2021-01-25 12:05:20 -05:00
Kyle Edwards
946adadd40 cmGccDepfileReader: Rework helper code
Fix some of the semantics of the depfile, add error handling, and
refactor cmGccDepfileLexerHelper.
2020-10-13 10:18:02 -04:00
Oleksandr Koval
62d7acc6d4 cmCommandArgumentParserHelper: rework input handling
Old implementation uses involved Flex input management technique that
requires usage of obsolete YY_INPUT macro. This causes a lot of useless
allocations and byte-by-byte scanning. New implementation avoids those
hacks, it uses yy_scan_string() API to setup Flex input. Also it fixes
reporting of syntax error position and corresponding tests.
2020-09-09 15:49:35 +03:00
Cristian Adam
598b676b5e cmake_command: Add command to EVAL a CMake script as a string 2020-03-03 08:42:13 -05:00
Joerg Bornemann
f8c505d4b3 Add a parser for GCC-style depfiles
Introduce the function cmReadGccDepfile that parses a GCC-style depfile
and returns its content. The implementation uses a lexer that is
modeled after the re2c implementation in Ninja.

The sample files of the autotest have been created with gcc 8.3.0.

This depfile reader is to be used by the Autogen facility to make use
of the depfiles that are generated by Qt's meta object compiler.
2020-01-28 11:16:11 -05:00
Tiziano Müller
154b8d1a27 Fortran: ignore CPP line directives in line-continued USE stmts
Issue: #18188
2019-11-13 11:30:19 -05:00
Kitware Robot
34b7dbbfc3 LexerParser: Regenerate parsers with bison 3.4.2 2019-11-13 11:29:48 -05:00
Brad King
73a40b19ff CTest: Rename "Processes" lexer to "ResourceGroups"
The corresponding test property `PROCESSES` has been renamed to
`RESOURCE_GROUPS`.
2019-11-05 12:08:35 -05:00
Kyle Edwards
bb4a141059 CTest: Add lexer for PROCESSES property 2019-10-02 09:33:54 -04:00
Gabor Bencze
d427f12b73 math(EXPR): Implement ~(exp_NOT) expression as documented
Fixes: #19252
2019-07-23 07:33:50 -04:00
Brad King
8f0b3f92d5 LexerParser: Regenerate parsers with bison 3.3
Run `Utilities/Scripts/regenerate-parsers.bash`.
2019-07-22 08:45:40 -04:00
Artur Ryt
30bb14c657 Modernize: Enable modernize-raw-string-literal in clang-tidy 2019-04-02 19:59:54 +02:00
Zsolt Parragi
76a5ac2100 cmListFileLexer: Add missing include to avoid possible pointer truncation
The `cmsys/Enconding.h` include had a typo in its surrounding ifdef,
possibly causing a missing function declaration (`cmsysEncoding_DupToWide`).
As this is C code, this resulted in the code compiling, but with a truncated
return value, possibly causing crashes.
2019-02-13 10:22:59 -05:00
Sean McBride
b056bc3425 Fix most clang -Wextra-semi-stmt warnings in C++ files
Suppress one in code generated by flex.
2019-01-15 14:09:46 -05:00
Kyle Edwards
9e4b6bcbe8 Source/LexerParser: Suppress "Use of zero-allocated memory" warning
clang scan-build warns about YY_CURRENT_BUFFER_LVALUE being zero-
allocated, but the whole point of the macro is to know that it's
not zero. Wrap the entire file in an "#ifndef __clang_analyzer__"
block in order to suppress the warning.
2019-01-14 10:31:38 -05:00
Brad King
ead16adfc8 Fortran: Fix module dependency scanning with upper-case SUBMODULE
The lexical token expression added by commit v3.7.0-rc1~73^2~1 (Fortran:
Add support for submodule syntax in dependency scanning, 2016-09-05)
has a typo and does not match upper-case `B` in `SUBMODULE`.  Fix it.

Fixes: #18595
2018-11-20 14:16:26 -05:00
Brad King
34257b0dd4 LexerParser: Suppress GCC -Wconversion warnings
GCC 8 warns about some of the conversions in bison-generated code.
Suppress the warnings.
2018-07-31 09:34:55 -04:00
Brad King
406f397e8b math: Restore toleration of unexpected characters in an expression
Prior to commit 7c4c13ffef (math: Reject unexpected expression input
explicitly, 2018-05-18) we ignored unexpected characters in an
expression that otherwise can be parsed.  In order to preserve
compatibility with projects that accidentally used this, convert the
error to a warning.
2018-07-16 14:46:43 -04:00
Brad King
ca733cdf45 Merge topic 'math-hex'
5dbee9d2d0 math: Add options to calculate and format output as hexadecimal
8661e7052c math: Diagnose divide-by-zero
7c4c13ffef math: Reject unexpected expression input explicitly
5b0f73a15a math: Use 64-bit integer type for computation
963b8d9f6c math: Add RunCMake.math test to prepare for error cases

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2056
2018-07-05 10:26:05 -04:00
Daniel Franke
5dbee9d2d0 math: Add options to calculate and format output as hexadecimal 2018-07-03 09:55:58 -04:00
Daniel Franke
8661e7052c math: Diagnose divide-by-zero 2018-06-26 14:21:18 -04:00
Daniel Franke
7c4c13ffef math: Reject unexpected expression input explicitly
Switch to C++ exceptions for lexer/parser error handling.
Teach the lexer/parser to fail on unexpected input.
2018-06-26 14:15:21 -04:00
Brad King
b29842a818 ListFileLexer: Do not match null bytes in input
Extend the fix from commit v3.10.0-rc1~188^2 (ListFileLexer: fix
heap-buffer-overflow on malicious input, 2017-08-26) to apply to all
lexer token matches.  Replace all `.` with `[^\0\n]`.  Update all
`[^...]` match expressions to not match `\0`.

We cannot safely process null bytes in strings.

Fixes: #18124
2018-06-26 11:54:34 -04:00
Brad King
402735314e Fortran: Add support for submodule dependencies
Since commit v3.7.0-rc1~73^2~1 (Fortran: Add support for submodule
syntax in dependency scanning, 2016-09-05) we support parsing Fortran
sources that use submodule syntax, but it left addition of `.smod`
dependencies to future work.  Add it now.

The syntax

    submodule (module_name) submodule_name

means the current source requires `module_name.mod` and provides
`module_name@submodule_name.smod`.  The syntax

    submodule (module_name:submodule_name) nested_submodule_name

means the current source requires `module_name@submodule_name.smod`
provides `module_name@nested_submodule_name.smod`.

Fixes: #17017
2018-04-20 10:57:31 -04:00
Rolf Eike Beer
576c079faa cmCommandArgumentParser: remove the variable tokens from the class
Make them local constants in the lexer file.
2017-10-25 19:56:33 +02:00
Matthias Maennich
14d9a11be9 ListFileLexer: fix heap-buffer-overflow on malicious input
In case a list file contains a null terminated string that is continued
until a later space, the lexer token information got inconsistent:

e.g. an argument   "TEST\0FOOBAR"    is passed by the lexer as a token

char* = "TEST\0FOOBAR" and length 11
             ^^ note: ascii 0x00

Using strdup in cmListFileLexer leads lexer->token.text to be allocated
with size 5 and lexer->token.length to be set to 11

A subsequent call to this function with an argument of  5 < length <= 11
wrongly assumed a sufficiently sized buffer and therefore corrupted the
heap buffer. The program might crash due to this corruption.
The case "NullTerminatedArgument" is intentionally using a quite large
'rest' to increase the chance to actually hit the issue. It will reliably
crash with address sanitizer enabled though.

This fix addresses all rules where arbitrary characters are matched to
ignore \0 in order to fall through to the rule that matches an arbitrary
character as BadCharacter.

Signed-off-by: Matthias Maennich <matthias@maennich.net>
2017-08-30 11:28:51 -04:00
Matthias Maennich
376c13958d cmFortranLexer: regenerate with flex 2.6.4 (previously 2.6.1)
flex 2.6.3 introduces symbol remapping through macro definitions. hence the
change appears bigger than one would expect from a minor version upgrade.

In addition some manual cleanup that had to be done previously is now
obsolete. namely:
  - the size_t cast of _yybytes_len in yy_scan_bytes
    (i is now also defined int and not size_t anymore)
  - the redefinition of yyl within yy_find_action
    (yyl is now already defined as int)

Line number preprocessor directives (#line) were previously generated into
the c source file. This actually breaks debugging as debuggers have a hard
time finding the original cmFortranLexer.in.l and mapping the current
instruction to a meaningful location within that file.

The prefix "cmFortran_yy" can already be set as %option directly.

For convenience also provide a sed command for all the manual steps that
need to be done after generating.

Signed-off-by: Matthias Maennich <matthias@maennich.net>
2017-08-29 00:34:36 +02:00
Matthias Maennich
80c08c7c0a cmExprLexer: regenerate with flex 2.6.4 (previously 2.6.1)
flex 2.6.3 introduces symbol remapping through macro definitions. hence the
change appears bigger than one would expect from a minor version upgrade.

In addition some manual cleanup that had to be done previously is now
obsolete. namely:
  - the size_t cast of _yybytes_len in yy_scan_bytes
    (i is now also defined int and not size_t anymore)
  - the redefinition of yyl within yy_find_action
    (yyl is now already defined as int)

Line number preprocessor directives (#line) were previously generated into
the c source file. This actually breaks debugging as debuggers have a hard
time finding the original cmExprLexer.in.l and mapping the current
instruction to a meaningful location within that file.

The prefix "cmExpr_yy" can already be set as %option directly.

For convenience also provide a sed command for all the manual steps that
need to be done after generating.

Signed-off-by: Matthias Maennich <matthias@maennich.net>
2017-08-29 00:31:15 +02:00
Matthias Maennich
59f78dcb23 cmDependsJavaLexer: regenerate with flex 2.6.4 (previously 2.6.1)
flex 2.6.3 introduces symbol remapping through macro definitions. hence the
change appears bigger than one would expect from a minor version upgrade.

In addition some manual cleanup that had to be done previously is now
obsolete. namely:
  - the size_t cast of _yybytes_len in yy_scan_bytes
    (i is now also defined int and not size_t anymore)
  - the redefinition of yyl within yy_find_action
    (yyl is now already defined as int)

Line number preprocessor directives (#line) were previously generated into
the c source file. This actually breaks debugging as debuggers have a hard
time finding the original cmDependsJavaLexer.in.l and mapping the current
instruction to a meaningful location within that file.

The prefix "cmDependsJava_yy" can already be set as %option directly.

For convenience also provide a sed command for all the manual steps that
need to be done after generating.

Signed-off-by: Matthias Maennich <matthias@maennich.net>
2017-08-29 00:25:02 +02:00
Matthias Maennich
d2e8351a4d cmCommandArgumentLexer: regenerate with flex 2.6.4 (previously 2.6.1)
flex 2.6.3 introduces symbol remapping through macro definitions. hence the
change appears bigger than one would expect from a minor version upgrade.

In addition some manual cleanup that had to be done previously is now
obsolete. namely:
  - the size_t cast of _yybytes_len in yy_scan_bytes
    (i is now also defined int and not size_t anymore)
  - the redefinition of yyl within yy_find_action
    (yyl is now already defined as int)

Line number preprocessor directives (#line) were previously generated into
the c source file. This actually breaks debugging as debuggers have a hard
time finding the original cmCommandArgumentLexer.in.l and mapping the current
instruction to a meaningful location within that file.

The prefix "cmCommandArgument_yy" can already be set as %option directly.

For convenience also provide a sed command for all the manual steps that
need to be done after generating.

Signed-off-by: Matthias Maennich <matthias@maennich.net>
2017-08-29 00:18:06 +02:00
Matthias Maennich
ef41bf8531 cmListFileLexer: regenerate with flex 2.6.4 (previously 2.6.1)
flex 2.6.3 introduces symbol remapping through macro definitions. hence the
change appears bigger than one would expect from a minor version upgrade.

In addition some manual cleanup that had to be done previously is now
obsolete. namely:
  - the size_t cast of _yybytes_len in yy_scan_bytes
    (i is now also defined int and not size_t anymore)
  - the redefinition of yyl within yy_find_action
    (yyl is now already defined as int)

Line number preprocessor directives (#line) were previously generated into
the c source file. This actually breaks debugging as debuggers have a hard
time finding the original cmListFileLexer.in.l and mapping the current
instruction to a meaningful location within that file.

The prefix "cmListFileLexer_yy" can already be set as %option directly.

For convenience also provide a sed command for all the manual steps that
need to be done after generating.

Signed-off-by: Matthias Maennich <matthias@maennich.net>
2017-08-25 16:54:41 +02:00
Matthias Maennich
9cacb0cba4 cmListFileLexer: fix 'bail out on seek-errors' also in original file
The commit v3.9.0-rc1~502^2 (cmListFileLexer: bail out on seek-errors,
2017-02-19) for bug # 16607 was only applied to the generated file.

Also apply the fix now to the original.

Signed-off-by: Matthias Maennich <matthias@maennich.net>
2017-08-25 16:53:19 +02:00
Daniel Pfeifer
7f4eaf2348 LexerParser: disable clang-tidy checks 2017-04-28 23:10:39 +02:00
Daniel Pfeifer
9bad0dfcce LexerParser: move to custom directory 2017-04-28 23:10:39 +02:00