Commit Graph

278 Commits

Author SHA1 Message Date
David Majnemer f2d3bc0474 Lex: Don't let annotation tokens get into macro expansion
We'd let annotation tokens from '#pragma pack' and the like get inside a
function-like macro.  This would lead to terror and mayhem; stop the
madness early.

This fixes PR22037.

llvm-svn: 224896
2014-12-28 07:42:49 +00:00
Serge Pavlov 07c0f04e08 Fixed warnings on redefine keywords and reserved ids.
Repared support for warnings -Wkeyword-macro and -Wreserved-id-macro.
The warning -Wkeyword-macro now is not issued in patterns that are used
in configuration scripts:

    #define inline

also for 'const', 'extern' and 'static'. If macro repalcement is identical
to macro name, the warning also is not issued:

    #define volatile volatile

And finally if macro replacement is also a keyword identical to the replaced
one but decorated with leading/trailing underscores:

    #define inline __inline
    #define inline __inline__
    #define inline _inline // in MSVC compatibility mode

Warning -Wreserved-id-macro is off by default, it could help catching
things like:

    #undef __cplusplus

llvm-svn: 224512
2014-12-18 11:14:21 +00:00
Nico Weber 92c14bb2ff Move -Wkeyword-macro into -pedantic, remove -Wreserved-id-macro.
As discussed on the post-commit review thread for r224012, -Wkeyword-macro fires
mostly on headers trying to set up portable defines and doesn't find much bad
stuff in practice.  But [macro.names]p2 does disallow defining or undefining
keywords, override and final, and alignas, so keep the warning but move it
into -pedantic.

-Wreserved-id-macro warns on

    #define __need_size_t

which is more or less public api for glibc headers. Since this warning isn't
motivated by a standard, remove it.

(See also r223114 for a previous follow-up to r224012.)

llvm-svn: 224371
2014-12-16 21:16:10 +00:00
Serge Pavlov 59da7b8a68 Do not warn on keyword undef
#undef a keyword is generally harmless but used often in configuration scripts.
Also added tests that I forgot to include to commit in r223114.

llvm-svn: 224100
2014-12-12 06:37:55 +00:00
Serge Pavlov 83cf078f8f Emit warning if define or undef reserved identifier or keyword.
Recommit of r223114, reverted in r223120.

llvm-svn: 224012
2014-12-11 12:18:08 +00:00
Serge Pavlov 376aee9ae7 Reverted r223114, it caused failure on on clang-native-arm-cortex-a9.
llvm-svn: 223120
2014-12-02 14:52:20 +00:00
Serge Pavlov 1ecb41c09b Emit warning if define or undef reserved identifier or keyword.
Summary:
This change implements warnings if macro name is identical to a keyword or
reserved identifier. The warnings are different depending on the "danger"
of the operation. Defining macro that replaces a keyword is on by default.
Other cases produce warning that is off by default but can be turned on
using option -Wreserved-id-macro.

This change fixes PR11488.

Reviewers: rnk

Reviewed By: rnk

Subscribers: rnk, cfe-commits

Differential Revision: http://reviews.llvm.org/D6194

llvm-svn: 223114
2014-12-02 11:06:09 +00:00
Richard Smith 3c1a41ad99 [modules] Track how 'header' directives were written in module map files,
rather than trying to extract this information from the FileEntry after the
fact.

This has a number of beneficial effects. For instance, diagnostic messages for
failed module builds give a path relative to the "module root" rather than an
absolute file path, and the contents of the module includes file is no longer
dependent on what files the including TU happened to inspect prior to
triggering the module build.

llvm-svn: 223095
2014-12-02 00:08:08 +00:00
Serge Pavlov d024f528b4 Use enumerators instead of hardcoded integers when processing macro names.
llvm-svn: 220572
2014-10-24 17:31:32 +00:00
Richard Smith 25d50758f3 [modules] Add support for #include_next.
#include_next interacts poorly with modules: it depends on where in the list of
include paths the current file was found. Files covered by module maps are not
found in include search paths when building the module (and are not found in
include search paths when @importing the module either), so this isn't really
meaningful. Instead, we fake up the result that #include_next *should* have
given: find the first path that would have resulted in the given file being
picked, and search from there onwards.

llvm-svn: 220177
2014-10-20 00:15:49 +00:00
Manuel Klimek 9af34aeac1 Correctly implement -include search logic.
According to the gcc docs, -include uses the current working directory
for the lookup instead of the main source file.

This patch gets rid of NormalizeIncludePath (which relied on an
implementation detail of FileManager / FileEntry for the include path
logic to work), and instead hands the correct lookup information down to
LookupFile.

This will allow us to change the FileEntry's behavior regarding its Name
caching.

llvm-svn: 215433
2014-08-12 08:25:57 +00:00
Yaron Keren 1801d1b12f Fix six tests are failing on Windows after r215241-r215243.
Clang :: Frontend/iframework.c
    Clang :: Frontend/system-header-prefix.c
    Clang :: Index/annotate-comments-objc.m
    Clang :: Index/annotate-module.m
    Clang :: Index/index-module.m
    Clang :: Index/index-pch-with-module.m
    Clang :: PCH/case-insensitive-include.c

Suprisingly the normalize_separators() was no-op when LLVM_ON_WIN32.
Its replacement native() does change path separators into \ as expected,
breaking these tests.

I had fixed the tests by #ifndef LLVM_ON_WIN32 on the native call,
to match the previous behaviour. 
If this logic is not used on Windows host, it might be completely
deleted as there should not be windows path seperators on Linux hosts.

I can't test on Linux but if someone can run tests on Linux after
commenting out the line

  llvm::sys::path::native(NormalizedPath);    

and the tests pass, the whole if (LangOpts.MSVCCompat) could be deleted.
  

llvm-svn: 215290
2014-08-09 18:13:01 +00:00
Rafael Espindola f600223754 Use llvm::sys::path::native instead of llvm::sys::fs::normalize_separators.
llvm::sys::path::native has a superset of the functionality and this was the
only use of llvm::sys::fs::normalize_separators.

llvm-svn: 215242
2014-08-08 21:31:04 +00:00
Richard Smith 06f621d349 Don't destroy MacroInfos if we find the macro definition is invalid; it'll get
destroyed on shutdown regardless. Fixes a double-delete.

llvm-svn: 214675
2014-08-03 23:41:04 +00:00
Richard Smith daa69e00f5 [modules] Substantially improve handling of #undef:
* Track override set across module load and save
 * Track originating module to allow proper re-export of #undef
 * Make override set properly transitive when it picks up a #undef

This fixes nearly all of the remaining macro issues with self-host.

llvm-svn: 213922
2014-07-25 04:40:03 +00:00
Richard Smith 73a29662b9 Simplify MacroInfo lifetime management. We don't need three different functions
to destroy one of these.

llvm-svn: 213837
2014-07-24 03:25:00 +00:00
Richard Smith ee0c4c1673 Remove unused Prev pointer from MacroInfo chain.
Remove pointless MICache: it only ever contained up to 1 object, and was only
non-empty when recovering from an error. There's no performance or memory win
from maintaining this cache.

llvm-svn: 213825
2014-07-24 01:13:23 +00:00
Ben Langmuir b537a3a651 Add stopgap option -fmodule-implementation-of <name>
This flag specifies that we are building an implementation file of the
module <name>, preventing importing <name> as a module. This does not
consider this to be the 'current module' for the purposes of doing
modular checks like decluse or non-modular-include warnings, unlike
-fmodule-name.

This is needed as a stopgap until:
1) we can resolve relative includes to a VFS-mapped module (or can
   safely import a header textually and as part of a module)

and ideally
2) we can safely do incremental rebuilding when implementation files
   import submodules.

llvm-svn: 213767
2014-07-23 15:30:23 +00:00
Craig Topper 9d5583ef0a Convert StringLiteralParser constructor to use ArrayRef instead of a pointer and count.
llvm-svn: 211763
2014-06-26 04:58:39 +00:00
Yaron Keren fdbb4a54d5 Fixed formatting.
llvm-svn: 211295
2014-06-19 19:12:02 +00:00
Alp Toker d4a3f0e894 Hide the concept of diagnostic levels from lex, parse and sema
The compilation pipeline doesn't actually need to know about the high-level
concept of diagnostic mappings, and hiding the final computed level presents
several simplifications and other potential benefits.

The only exceptions are opportunistic checks to see whether expensive code
paths can be avoided for diagnostics that are guaranteed to be ignored at a
certain SourceLocation.

This commit formalizes that invariant by introducing and using
DiagnosticsEngine::isIgnored() in place of individual level checks throughout
lex, parse and sema.

llvm-svn: 211005
2014-06-15 23:30:39 +00:00
Alp Toker e03e9e15f2 Preprocessor: make C++ operator names as macro identifiers a compatible extension
With recent changes, this is now a compatible language extension and can be
safely enabled with -ms-extensions instead of requiring the full
-ms-compatibility MSVC drop-in mode. As such we can now also emit an extension
warning under -Wmicrosoft to help users port their code.

llvm-svn: 209978
2014-05-31 16:32:22 +00:00
Alp Toker c5d194fcd3 Preprocessor: recover gracefully when C++ operator names are used as macro identifiers
This failure mode shows up occasionally when users try to include C headers in
C++ projects or when porting from Windows. We might as well recover in the way
the user expected, thus avoiding confusing diagnostic messages at point of use.

llvm-svn: 209963
2014-05-31 03:38:17 +00:00
Alp Toker f33619cb51 Preprocessor: don't exit early in CheckMacroName()
The checks below can hypothetically apply to converted operator name
identifiers.

In practice there are no builtin macros etc. with those names so there's no
behavioural change to test.

llvm-svn: 209962
2014-05-31 03:38:08 +00:00
Alp Toker 6521ecc083 Provide an aka for the C++ operator name macro diagnostic
llvm-svn: 209322
2014-05-21 21:23:39 +00:00
Alp Toker b05e0b53b9 Preprocessor: support defined() with operator names for MS compatibility
Also flesh out missing tests, improve diagnostic QOI and fix a couple of corner
cases found in the process.

Fixes PR10606.

llvm-svn: 209276
2014-05-21 06:13:51 +00:00
Craig Topper d2d442ca73 [C++11] Use 'nullptr'. Lex edition.
llvm-svn: 209083
2014-05-17 23:10:59 +00:00
Alp Toker 2d57cea256 Provide and use a safe Token::getRawIdentifier() accessor
llvm-svn: 209061
2014-05-17 04:53:25 +00:00
Ben Langmuir 71e1a64f91 Add -Wnon-modular-include* options
Warn on non-modular includes in various contexts.

-Wnon-modular-include
 -Wnon-modular-include-in-module
  -Wnon-modular-include-in-framework-module

Where each group is a subgroup of those above it.

llvm-svn: 208004
2014-05-05 21:44:13 +00:00
Manuel Klimek 98a9a6c667 Use the expansion location of the file name when finding the module.
The spelling location of stringified strings is not a file location.
Optimally, we'll want to solve the problem (as the FIXME states) by
handing in the right FileEntry of the #include location.

llvm-svn: 204220
2014-03-19 10:22:36 +00:00
Daniel Jasper 5c77e39f2d Don't verify module inclusions in assembler files.
llvm-svn: 203929
2014-03-14 14:53:17 +00:00
Saleem Abdulrasool 729b7d357d Lex: reduce buffer size, add a test
Reduce the stack usage as hopefully include paths are usually not too long.  Add
a test case for the path normalisation behaviour.

llvm-svn: 203632
2014-03-12 02:26:08 +00:00
Saleem Abdulrasool 198034105d lex: improve include handling on Linux for Windows
Normalise the path separator character on non-windows platforms.  Although this
would work on Windows as well (most newer versions of Windows support either '/'
or '\' as a path separator character), it could potentially cause problems with
full UNC paths.  This change enables the use of the Windows SDK on Linux which
will not accept '\' as a path separator.

llvm-svn: 203614
2014-03-11 22:41:45 +00:00
Chandler Carruth 06dde92cd6 [C++11] Switch from LLVM_STATIC_ASSERT to static_assert now that we
require host toolchains which support this.

llvm-svn: 202640
2014-03-02 13:02:01 +00:00
Richard Smith 67294e253e Track the currently-being-built submodule inside the preprocessor (rather than
just storing a flag indicating if there was one), and include it in the 'end of
module' annotation. No functionality change.

llvm-svn: 200573
2014-01-31 20:47:44 +00:00
Alp Toker bfa3934f27 Rename language option MicrosoftMode to MSVCCompat
There's been long-standing confusion over the role of these two options. This
commit makes the necessary changes to differentiate them clearly, following up
from r198936.

MicrosoftExt (aka. fms-extensions):
 Enable largely unobjectionable Microsoft language extensions to ease
 portability. This mode, also supported by gcc, is used for building software
 like FreeBSD and Linux kernel extensions that share code with Windows drivers.

MSVCCompat (aka. -fms-compatibility, formerly MicrosoftMode):
 Turn on a special mode supporting 'heinous' extensions for drop-in
 compatibility with the Microsoft Visual C++ product. Standards-compilant C and
 C++ code isn't guaranteed to work in this mode. Implies MicrosoftExt.

Note that full -fms-compatibility mode is currently enabled by default on the
Windows target, which may need tuning to serve as a reasonable default.

See cfe-commits for the full discourse, thread 'r198497 - Move MS predefined
type_info out of InitializePredefinedMacros'

No change in behaviour.

llvm-svn: 199209
2014-01-14 12:51:41 +00:00
Will Wilson 0fafd34a6e Implement MSVC header search algorithm in MicrosoftMode.
Follows algorithm described here: http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx

llvm-svn: 198082
2013-12-27 19:46:16 +00:00
Daniel Jasper 92669ee45c Enable layering check in unavailable modules.
If a header file belonging to a certain module is not found on the
filesystem, that header gets marked as unavailable. Now, the layering
warning (-fmodules-decluse) should still warn about headers of this
module being wrongfully included. Currently, headers belonging to those
modules are just treated as not belonging to modules at all which means
they can be included freely from everywhere.

To implement this (somewhat) cleanly, I have moved most of the layering
checks into the ModuleMap. This will also help with showing FixIts
later.

llvm-svn: 197805
2013-12-20 12:09:36 +00:00
Daniel Jasper 4eaf0a6ca4 Modules: Let -fmodules-decluse ignore headers that aren't in a module
Includes might always pull in arbitrary header or data files outside of
modules. Among others, this includes builtin includes, which do not have
a module (story) yet.

Also cleanup implementation of ModuleMap::findModuleForHeader() to be
non-recursive.

llvm-svn: 197034
2013-12-11 12:13:00 +00:00
John Thompson 87f9fef5a5 Changed ConditionValue argument to PPCallbacks If and Elif callbacks to be a 3-state enum.
llvm-svn: 196648
2013-12-07 08:41:15 +00:00
Daniel Jasper 3cd34c7637 Allow string literals as module names.
In order to make the migration to modules easier, it seems to be helpful
to allow a 1:1 mapping between target names of a current build system
and the corresponding C++ modules. As  such targets commonly contain
characters like "-". ":" and "/", allowing arbitrary quote-escaped
strings seems to be a straightforward option.

After several offline discussions, the precise mechanisms for C++
module names especially regarding submodules and import statements has
yet to be determined. Thus, this patch only enables string literals as
names inside the module map files which can be used by automatic module
import (through #include).

Also improve the error message on missing use-declarations.

llvm-svn: 196573
2013-12-06 09:25:54 +00:00
John Thompson 17c357342a Enea Zaffanella's fix for the PPCallbacks Elif callback, with a slight re-org, and an update of the new PPCallbacks test (soon to be moved to clang from extra), rather the unittest.
llvm-svn: 196407
2013-12-04 20:19:30 +00:00
Daniel Jasper 88d8695ab4 Fix corner case in module-based layering warning.
Before, there SourceManager would not return a FileEntry for a
SourceLocation of a macro expansion (if the header name itself is
defined in a macro). We'd then fallback to assume that the module
currently being built is the including module. However, in this case we
are actually interested in the spelling location of the filename loc in
order to derive the including module.

llvm-svn: 196311
2013-12-03 20:30:36 +00:00
James Dennett 4a4f72d8d9 Documentation cleanup: Doxygen-ification, typo fixes, and changing some of
the duplicated documentation from .cpp files so that it's not processed by
Doxygen and hence doesn't generate duplicate output.

llvm-svn: 195799
2013-11-27 01:27:40 +00:00
Richard Smith 34f30516aa Generate a marker token when entering or leaving a submodule when building a
module. Use the marker to diagnose cases where we try to transition between
submodules when not at the top level (most likely because a closing brace was
missing at the end of a header file, but is also possible if submodule headers
attempt to do something fundamentally non-modular, like our .def files).

llvm-svn: 195543
2013-11-23 04:06:09 +00:00
Richard Smith ce587f5eb9 When we hit a #include directive that maps to a module import, emit a token
representing the module import rather than making the module immediately
visible. This serves two goals:
 * It avoids making declarations in the module visible prematurely, if we
   walk past the #include during a tentative parse, for instance, and
 * It gives a diagnostic (although, admittedly, not a very nice one) if
   a header with a corresponding module is included anywhere other than
   at the top level.

llvm-svn: 194782
2013-11-15 04:24:58 +00:00
David Majnemer 76faf1f525 Lex: Require that '#' be followed by a macro parameter name when preceded by '##'
After lexing a '##', we would look ahead and check to see if it was
followed by '__VA_ARGS__'.  After doing so, we would then go ahead and
lex the token.

However we would fail in the case where the '##' was followed by a '#'
followed by an identifier because we would have lexed the '#' separately
from the identifier, bypassing our parameter validation logic.

Instead, lex the tokens coming after the '##' later.

This fixes PR17804.

llvm-svn: 194059
2013-11-05 09:30:17 +00:00
Daniel Jasper 97da9178ce Allow a header to be part of multiple modules.
This patch changes two things:

a) Allow a header to be part of multiple modules. The reasoning is that
in existing codebases that have a module-like build system, the same
headers might be used in several build targets. Simple reasons might be
that they defined different classes that are declared in the same
header. Supporting a header as a part of multiple modules will make the
transistion easier for those cases. A later step in clang can then
determine whether the two modules are actually compatible and can be
merged and error out appropriately. The later check is similar to what
needs to be done for template specializations anyway.

b) Allow modules to be stored in a directory tree separate from the
headers they describe.

Review: http://llvm-reviews.chandlerc.com/D1951
llvm-svn: 193151
2013-10-22 08:09:47 +00:00
Richard Smith 7f2707a7f4 Per updates to D3781, allow underscore under ' in a pp-number, and allow ' in a #line directive.
llvm-svn: 191443
2013-09-26 18:13:20 +00:00
Daniel Jasper ba7f2f7110 Module use declarations (II)
Review: http://llvm-reviews.chandlerc.com/D1546.

I have picked up this patch form Lawrence
(http://llvm-reviews.chandlerc.com/D1063) and did a few changes.

From the original change description (updated as appropriate):
This patch adds a check that ensures that modules only use modules they
have so declared. To this end, it adds a statement on intended module
use to the module.map grammar:

  use module-id

A module can then only use headers from other modules if it 'uses' them.
This enforcement is off by default, but may be turned on with the new
option -fmodules-decluse.

When enforcing the module semantics, we also need to consider a source
file part of a module. This is achieved with a compiler option

-fmodule-name=<module-id>.

The compiler at present only applies restrictions to the module directly
being built.

llvm-svn: 191283
2013-09-24 09:14:14 +00:00