Commit Graph

2083 Commits

Author SHA1 Message Date
Alex Lorenz ebbbb81266 [refactor][extract] insert semicolons into extracted/inserted code
when needed

This commit implements the semicolon insertion logic into the extract
refactoring. The following rules are used:

- extracting expression: add terminating ';' to the extracted function.
- extracting statements that don't require terminating ';' (e.g. switch): add
  terminating ';' to the callee.
- extracting statements with ';':  move (if possible) the original ';' from the
  callee and add terminating ';'.
- otherwise, add ';' to both places.

Differential Revision: https://reviews.llvm.org/D39441

llvm-svn: 317343
2017-11-03 18:11:22 +00:00
Kostya Kortchinsky 8acdc98271 [Driver] Add Scudo as a possible -fsanitize= option
Summary:
This change adds Scudo as a possible Sanitizer option via -fsanitize=.
This allows for easier static & shared linking of the Scudo library, it allows
us to enforce PIE (otherwise the security of the allocator is moot), and check
for incompatible Sanitizers combo.

In its current form, Scudo is not compatible with any other Sanitizer, but the
plan is to make it work in conjunction with UBsan (-fsanitize=scudo,undefined),
which will require additional work outside of the scope of this change.

Reviewers: eugenis, kcc, alekseyshl

Reviewed By: eugenis, alekseyshl

Subscribers: llvm-commits, srhines

Differential Revision: https://reviews.llvm.org/D39334

llvm-svn: 317337
2017-11-03 17:04:13 +00:00
Erik Verbruggen 4d1eb2d5cb [preamble] Also record the "skipping" state of the preprocessor
When a preamble ends in a conditional preprocessor block that is being
skipped, the preprocessor needs to continue skipping that block when
the preamble is used.

This fixes PR34570.

llvm-svn: 317308
2017-11-03 09:40:07 +00:00
Aaron Ballman 606093a53b Add -f[no-]double-square-bracket-attributes as new driver options to control use of [[]] attributes in all language modes. This is the initial implementation of WG14 N2165, which is a proposal to add [[]] attributes to C2x, but also allows you to enable these attributes in C++98, or disable them in C++11 or later.
llvm-svn: 315856
2017-10-15 15:01:42 +00:00
Benjamin Kramer 8b54a1c686 [Lex] Remove unused variables. No functionality change.
llvm-svn: 315845
2017-10-15 04:27:37 +00:00
Faisal Vali 1826842865 [c++2a] Implement P0306 __VA_OPT__ (Comma omission and comma deletion)
This patch implements an extension to the preprocessor:

__VA_OPT__(contents) --> which expands into its contents if variadic arguments are supplied to the parent macro, or behaves as an empty token if none.

  - Currently this feature is only enabled for C++2a (this could be enabled, with some careful tweaks, for other dialects with the appropriate extension or compatibility warnings)

  - The patch was reviewed here: https://reviews.llvm.org/D35782 and asides from the above (and moving some of the definition and expansion recognition logic into the corresponding state machines), I believe I incorporated all of Richard's suggestions.

A few technicalities (most of which were clarified through private correspondence between rsmith, hubert and thomas) are worth mentioning.  Given:

    #define F(a,...) a #__VA_OPT__(a ## a)  a ## __VA_OPT__(__VA_ARGS__)

    - The call F(,) Does not supply any tokens for the variadic arguments and hence VA_OPT behaves as a placeholder.
    - When expanding VA_OPT (for e.g. F(,1) token pasting occurs eagerly within its contents if the contents need to be stringified.
    - A hash or a hashhash prior to VA_OPT does not inhibit expansion of arguments if they are the first token within VA_OPT.
    - When a variadic argument is supplied, argument substitution occurs within the contents as does stringification - and these resulting tokens are inserted back into the macro expansions token stream just prior to the entire stream being rescanned and concatenated.

See wg21.link/P0306 for further details on the feature.


Acknowledgment: This patch would have been poorer if not for Richard Smith's usual thoughtful analysis and feedback.
llvm-svn: 315840
2017-10-15 01:26:26 +00:00
Alex Lorenz d5bf436d3a [Lex] Avoid out-of-bounds dereference in SkipLineComment
Credit to OSS-Fuzz for discovery:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3145

rdar://34526482

llvm-svn: 315785
2017-10-14 01:18:30 +00:00
NAKAMURA Takumi 12ab07e000 Fix warnings. [-Wdocumentation]
llvm-svn: 315573
2017-10-12 09:42:14 +00:00
Alex Lorenz c1e32fca96 A '<' with a trigraph '#' is not a valid editor placeholder
Credit to OSS-Fuzz for discovery:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3137#c5

rdar://34923985

llvm-svn: 315398
2017-10-11 00:41:20 +00:00
Faisal Vali 03b7b15f8e Add parens around the boolean condition of one of the added asserts in r314747 ...
... in the hopes of teaching the bots the gift of silence ;)

For quick reference: https://reviews.llvm.org/rL314747




  

llvm-svn: 314753
2017-10-03 01:33:36 +00:00
Faisal Vali 675cf03f6e Remove an assertion I added from the refactoring of pasteTokens (https://reviews.llvm.org/rL314747).
- it made the bots v angry!

I'm not exactly sure why the assertion doesn't hold - if anyone has any insight - would appreciate it.

Thanks!

llvm-svn: 314748
2017-10-03 01:20:40 +00:00
Faisal Vali b8ece9faa8 [NFC] Refactor PasteTokens so that it can be passed the Token Stream and Index to start concatenating at.
In passing:
    - change the name of the function to pasteTokens c/w coding standards
    - rename CurToken to CurTokenIdx (since it is not the token, but the index)
    - add doxygen comments to document some of pasteTokens' functionality
    - use parameter names different from the data member names.

This will be useful for implementing __VA_OPT__ (https://reviews.llvm.org/D35782#inline-322587)

llvm-svn: 314747
2017-10-03 00:52:14 +00:00
Faisal Vali 7ae3c3fee3 [NFC] Add assertion that we assume a valid macro argument index.
llvm-svn: 314600
2017-09-30 19:34:27 +00:00
Faisal Vali 333133e2c8 [NFC] Remove superfluous parameter
- MacroArgs already knows the maximum number of arguments that can be supplied to the macro.  No need to pass MacroInfo (information about the macro definition) to the call to getPreExpArgument (which by the way might benefit from being called getExpandedArgument() ?) for it to compute the number of arguments.

llvm-svn: 314593
2017-09-30 13:58:38 +00:00
Faisal Vali e8f430af68 [NFC] Replace 'arguments' with 'parameters' in comments relating to lexing a macro definition.
llvm-svn: 314484
2017-09-29 02:43:22 +00:00
Faisal Vali 33df391e39 [NFC] Rename variable 'Arguments' to 'Parameters' when lexing the Macro Definition.
llvm-svn: 314483
2017-09-29 02:17:31 +00:00
Benjamin Kramer 32c99824a0 Use std::is_trivial instead of is_trivially_copyable.
The oldest versions of GCC we support (before 5) didn't support that
trait. is_trivial is stronger superset that clang::Token fulfills, so
just use that instead.

llvm-svn: 314391
2017-09-28 08:50:30 +00:00
Faisal Vali c5fa1f1f50 [NFC] Don't use C++17 standard lib variable template helper traits, instead use ::value.
llvm-svn: 314373
2017-09-28 02:00:40 +00:00
Faisal Vali 02d8dde149 [NFC] Modernize MacroArgs using TrailingObjects
Refactor MacroArgs to use TrailingObjects when creating a variably sized object on the heap to store the unexpanded tokens immediately after the MacroArgs object.

llvm-svn: 314372
2017-09-28 01:50:23 +00:00
Eli Friedman 16fee08410 [Preprocessor] Preserve #pragma clang assume_nonnull in preprocessed output
Patch by Zbigniew Sarbinowski!

Differential Revision: https://reviews.llvm.org/D37861

llvm-svn: 314364
2017-09-27 23:29:37 +00:00
Nico Weber dffc55c1cd Delete trailing whitespace.
llvm-svn: 314232
2017-09-26 18:38:56 +00:00
Cameron Desrochers 531aec2e90 Fixed unused variable warning introduced in r313796 causing build failure
llvm-svn: 313802
2017-09-20 19:37:37 +00:00
Cameron Desrochers 84fd064ef9 [PCH] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)
This patch fixes broken preamble-skipping when the preamble region includes a byte order mark (BOM). Previously, parsing would fail if preamble PCH generation was enabled and a BOM was present.

This also fixes preamble invalidation when a BOM appears or disappears. This may seem to be an obscure edge case, but it happens regularly with IDEs that pass buffer overrides that never (or always) have a BOM, yet the underlying file from the initial parse that generated a PCH might (or might not) have a BOM.

I've included a test case for these scenarios.

Differential Revision: https://reviews.llvm.org/D37491

llvm-svn: 313796
2017-09-20 19:03:37 +00:00
Vitaly Buka 55a27d3c14 Another attempt to fix warning discovered by r313487. [-Wunused-lambda-capture]
llvm-svn: 313521
2017-09-18 08:26:01 +00:00
NAKAMURA Takumi 7f10a34d88 Revert rL313511, "Fix a warning discovered by rL313487. [-Wunused-lambda-capture]"
It was incompatible to msc.

llvm-svn: 313513
2017-09-18 05:52:57 +00:00
NAKAMURA Takumi 0004057985 Fix a warning discovered by rL313487. [-Wunused-lambda-capture]
llvm-svn: 313511
2017-09-18 04:55:33 +00:00
NAKAMURA Takumi a5b348be9d Reformat.
llvm-svn: 313510
2017-09-18 04:55:31 +00:00
Vedant Kumar 403822deac Remove comment accidentally committed with D36642. NFC.
llvm-svn: 313446
2017-09-16 06:26:51 +00:00
Douglas Gregor f0b11de279 [Module map] Introduce a private module re-export directive.
Introduce a new "export_as" directive for top-level modules, which
indicates that the current module is a "private" module whose symbols
will eventually be exported through the named "public" module. This is
in support of a common pattern in the Darwin ecosystem where a single
public framework is constructed of several private frameworks, with
(currently) header duplication and some support from the linker.

Addresses rdar://problem/34438420.

llvm-svn: 313316
2017-09-14 23:38:44 +00:00
Ilya Biryukov 8f738ac6d4 Fix recording preamble's conditional stack in skipped PP branches.
Summary:
This fixes PR34547.
`Lexer::LexEndOfFile` handles recording of ConditionalStack for
preamble and reporting errors about unmatched conditionalal PP
directives.
However, SkipExcludedConditionalBlock contianed duplicated logic for
reporting errors and clearing ConditionalStack, but not for preamble
recording.

This fix removes error reporting logic from
`SkipExcludedConditionalBlock`, unmatched PP conditionals are now
reported inside `Lexer::LexEndOfFile`.

Reviewers: erikjv, klimek, bkramer

Reviewed By: erikjv

Subscribers: nik, cfe-commits

Differential Revision: https://reviews.llvm.org/D37700

llvm-svn: 313014
2017-09-12 08:35:57 +00:00
Vedant Kumar 3919a501f3 [Lexer] Report more precise skipped regions (PR34166)
This patch teaches the preprocessor to report more precise source ranges for
code that is skipped due to conditional directives.

The new behavior includes the '#' from the opening directive and the full text
of the line containing the closing directive in the skipped area. This matches
up clang's behavior (we don't IRGen the code between the closing "endif" and
the end of a line).

This also affects the code coverage implementation. See llvm.org/PR34166 (this
also happens to be rdar://problem/23224058).

The old behavior (report the end of the skipped range as the end
location of the 'endif' token) is preserved for indexing clients.

Differential Revision: https://reviews.llvm.org/D36642

llvm-svn: 312947
2017-09-11 20:47:42 +00:00
Sjoerd Meijer cc623ad071 Recommit "Add _Float16 as a C/C++ source language type"
This is a recommit of r312781; in some build configurations
variable names are omitted, so changed the new regression
test accordingly.

llvm-svn: 312794
2017-09-08 15:15:00 +00:00
Sjoerd Meijer 9aeedde7ff Revert "Add _Float16 as a C/C++ source language type"
The clang-with-lto-ubuntu bot didn't like the new regression
test, revert while I investigate the issue.

llvm-svn: 312784
2017-09-08 10:20:52 +00:00
Sjoerd Meijer ab36f33db8 Add _Float16 as a C/C++ source language type
This adds _Float16 as a source language type, which is a 16-bit floating point
type defined in C11 extension ISO/IEC TS 18661-3.

In follow up patches documentation and more tests will be added.

Differential Revision: https://reviews.llvm.org/D33719

llvm-svn: 312781
2017-09-08 09:42:32 +00:00
Richard Smith 056bf77faf Fix memory leak after r312467. The ModuleMap is the owner of the global module object until it's reparented under a real module.
llvm-svn: 312580
2017-09-05 21:46:22 +00:00
Erich Keane e916d54614 [Preprocessor] Correct internal token parsing of newline characters in CRLF
Correct implementation:  Apparently I managed in r311683 to submit the wrong
version of the patch for this, so I'm correcting it now.

Differential Revision: https://reviews.llvm.org/D37079

llvm-svn: 312542
2017-09-05 17:32:36 +00:00
Richard Smith dd8b5337e9 Implement Itanium name mangling support for C++ Modules TS.
This follows the scheme agreed with Nathan Sidwell, which can be found here:

  https://gcc.gnu.org/wiki/cxx-modules?action=AttachFile

This will be proposed to the itanium-cxx-abi list once we have some experience
with how well it works; the ABI for this TS should be considered unstable until
it is part of the Itanium C++ ABI.

llvm-svn: 312467
2017-09-04 05:37:53 +00:00
Boris Kolpackov d30446fd77 [modules] Add ability to specify module name to module file mapping (reapply)
Extend the -fmodule-file option to support the [<name>=]<file> value format.
If the name is omitted, then the old semantics is preserved (the module file
is loaded whether needed or not). If the name is specified, then the mapping
is treated as just another prebuilt module search mechanism, similar to
-fprebuilt-module-path, and the module file is only loaded if actually used
(e.g., via import). With one exception: this mapping also overrides module
file references embedded in other modules (which can be useful if module files
are moved/renamed as often happens during remote compilation).

This override semantics requires some extra work: we now store the module name
in addition to the file name in the serialized AST representation.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D35020

llvm-svn: 312220
2017-08-31 06:26:43 +00:00
Victor Leschuk db68911b07 Revert r312105 [modules] Add ability to specify module name to module file mapping
Looks like it breaks win10 builder.

llvm-svn: 312112
2017-08-30 11:31:56 +00:00
Boris Kolpackov 7a71b4b658 [modules] Add ability to specify module name to module file mapping
Extend the -fmodule-file option to support the [<name>=]<file> value format.
If the name is omitted, then the old semantics is preserved (the module file
is loaded whether needed or not). If the name is specified, then the mapping
is treated as just another prebuilt module search mechanism, similar to
-fprebuilt-module-path, and the module file is only loaded if actually used
(e.g., via import). With one exception: this mapping also overrides module
file references embedded in other modules (which can be useful if module files
are moved/renamed as often happens during remote compilation).

This override semantics requires some extra work: we now store the module name
in addition to the file name in the serialized AST representation.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D35020

llvm-svn: 312105
2017-08-30 08:45:59 +00:00
Erich Keane 5a2b322e0d [Preprocessor] Correct internal token parsing of newline characters in CRLF
Discovered due to a goofy git setup, the test system-headerline-directive.c 
(and a few others) failed because the token-consumption will consume only the 
'\r' in CRLF, making the preprocessor's printed value give the wrong line number 
when returning from an include. For example:

(line 1):#include <noline.h>\r\n

The "file exit" code causes the printer to try to print the 'returned to the 
main file' line. It looks up what the current line number is. However, since the 
current 'token' is the '\n' (since only the \r was consumed), it will give the 
line number as '1", not '2'. This results in a few failed tests, but more 
importantly, results in error messages being incorrect when compiling a 
previously preprocessed file.

Differential Revision: https://reviews.llvm.org/D37079

llvm-svn: 311683
2017-08-24 18:36:07 +00:00
Ilya Biryukov f315000613 Fixed a crash on replaying Preamble's PP conditional stack.
Summary:
The crash occurs when the first token after a preamble is a macro
expansion.
Fixed by moving replayPreambleConditionalStack from Parser into
Preprocessor. It is now called right after the predefines file is
processed.

Reviewers: erikjv, bkramer, klimek, yvvan

Reviewed By: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D36872

llvm-svn: 311330
2017-08-21 12:03:08 +00:00
Richard Smith b115e5dda2 Rename cxx1z -> cxx17 across all diagnostic IDs.
llvm-svn: 310805
2017-08-13 23:37:29 +00:00
Richard Smith 6c74e32139 [c++2a] Treat 'concept' and 'requires' as keywords, add compat warning for C++17 and before.
llvm-svn: 310803
2017-08-13 21:32:33 +00:00
Bruno Cardoso Lopes 4164dd9167 Revert "[Modules] Prevent #import to reenter header if not building a module."
This reverts commit r310605. Richard pointed out a better way to achieve
this, which I'll post a patch for soon.

llvm-svn: 310775
2017-08-12 01:38:26 +00:00
Bruno Cardoso Lopes fca5abc9d2 [Modules] Prevent #import to reenter header if not building a module.
When non-modular headers are imported while not building a module but
in -fmodules mode, be conservative and preserve the default #import
semantic: do not reenter headers.

rdar://problem/33745031

llvm-svn: 310605
2017-08-10 15:16:24 +00:00
Alexander Kornienko cf007a7614 [Lexer] Finding beginning of token with escaped new line
Summary:
Lexer::GetBeginningOfToken produced invalid location when
backtracking across escaped new lines.

This fixes PR26228

Reviewers: akyrtzi, alexfh, rsmith, doug.gregor

Reviewed By: alexfh

Subscribers: alexfh, cfe-commits

Patch by Paweł Żukowski!

Differential Revision: https://reviews.llvm.org/D30748

llvm-svn: 310576
2017-08-10 10:06:16 +00:00
Tim Northover 9710338a56 Reapply Sema: allow imaginary constants via GNU extension if UDL overloads not present.
C++14 added user-defined literal support for complex numbers so that you
can write something like "complex<double> val = 2i". However, there is
an existing GNU extension supporting this syntax and interpreting the
result as a _Complex type.

This changes parsing so that such literals are interpreted in terms of
C++14's operators if an overload is present but otherwise falls back to
the original GNU extension.

(We now have more robust diagnostics for implicit conversions so the
libc++ test that caused the original revert still passes).

llvm-svn: 310478
2017-08-09 14:56:48 +00:00
Tim Northover d1fafc8b05 Revert "Lexer: always allow imaginary constants in GNU mode."
This reverts r310423. It was committed by mistake, I intended to commit the
improved diagnostics for implicit conversions instead.

llvm-svn: 310426
2017-08-08 23:17:51 +00:00
Tim Northover 8fbb4c40b3 Lexer: always allow imaginary constants in GNU mode.
llvm-svn: 310423
2017-08-08 22:03:54 +00:00