Commit Graph

268 Commits

Author SHA1 Message Date
Richard Smith 9443d047e8 [c++1z] Support for u8 character literals.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221576 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-08 06:08:42 +00:00
Jay Foad f5f351f991 Fix warning in Altivec code when building with GCC 4.8.2 on Ubuntu 14.04.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220855 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-29 14:42:12 +00:00
Aaron Ballman fbc9c9f05e C++1y is now C++14!
Changes diagnostic options, language standard options, diagnostic identifiers, diagnostic wording to use c++14 instead of c++1y. It also modifies related test cases to use the updated diagnostic wording.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215982 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-19 15:55:55 +00:00
Rafael Espindola 1cb6d934f5 Use StringRef instead of MemoryBuffer&.
This code doesn't care where the data it is processing comes from, so a
StringRef is probably the most natural interface.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215448 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-12 15:46:24 +00:00
David Blaikie 9febd24345 Change MemoryBuffer* to MemoryBuffer& parameter to Lexer::ComputePreamble
(dropping const from the reference as MemoryBuffer is immutable already,
so const is just redundant - and while I'd personally put const
everywhere, that's not the LLVM Way (see llvm::Type for another example
of an immutable type where "const" is omitted for brevity))

Changing the pointer argument to a reference parameter makes call sites
identical between callers with unique_ptrs or raw pointers, minimizing
the churn in a pending unique_ptr migrations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215391 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-11 22:08:06 +00:00
Alp Toker 7225802bf9 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211005 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-15 23:30:39 +00:00
Alp Toker 1afad8c890 Remove historical Unicode TODOs
There's no immediate demand or plan to work on these.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209090 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-18 18:37:59 +00:00
Craig Topper da176c6d6a [C++11] Use 'nullptr'. Lex edition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209083 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-17 23:10:59 +00:00
Alp Toker 9db67864c5 Provide and use a safe Token::getRawIdentifier() accessor
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209061 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-17 04:53:25 +00:00
Roman Divacky dffd876205 Revert r205436:
Extend the SSE2 comment lexing to AVX2. Only 16byte align when not on AVX2.

        This provides some 3% speedup when preprocessing gcc.c as a single file.


The patch is wrong, it always uses SSE2, and when I fix that there's no speedup
at all. I am not sure where the 3% came from previously.

--Thi lie, and those below, will be ignored--

M    Lex/Lexer.cpp


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205548 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-03 18:04:52 +00:00
Roman Divacky 5de8d4d7a2 Extend the SSE2 comment lexing to AVX2. Only 16byte align when not on AVX2.
This provides some 3% speedup when preprocessing gcc.c as a single file.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205436 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-02 17:27:03 +00:00
Benjamin Kramer ba9fd9e97e [C++11] Replace llvm::tie with std::tie.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202639 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-02 13:01:17 +00:00
Richard Smith 008d8c0ad1 Fix a minor bug in lexing pp-numbers with digit separators: if a pp-number contains "'e+", the pp-number ends between the 'e' and the '+'.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202533 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-28 20:06:02 +00:00
Richard Smith 40de650390 PR18855: Add support for UCNs and UTF-8 encoding within ud-suffixes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201532 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-17 21:52:30 +00:00
Alp Toker ab3d595970 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199209 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-14 12:51:41 +00:00
Chandler Carruth 4b9be6e25f Sort all the #include lines with LLVM's utils/sort_includes.py which
encodes the canonical rules for LLVM's style. I noticed this had drifted
quite a bit when cleaning up LLVM, so wanted to clean up Clang as well.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198686 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-07 11:51:46 +00:00
Alp Toker e3c64cd067 Lexer: Issue -Wbackslash-newline-escape for line comments
The warning for backslash and newline separated by whitespace was missed in
this code path.

backslash<whitespace><newline> is handled differently from compiler to compiler
so it's important to warn consistently where there's ambiguity.

Matches similar handling of block comments and non-comment lines.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197331 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-14 23:32:31 +00:00
Alp Toker e3739cdb5f Fix raw lex crash and -frewrite-includes noeol-at-eof failure
Raw lexers don't have a preprocessor so we need to null check.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197245 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-13 17:04:55 +00:00
Justin Bogner fbfd6426e2 Lex: Don't restrict legal UCNs when preprocessing assembly
The C and C++ standards disallow using universal character names to
refer to some characters, such as basic ascii and control characters,
so we reject these sequences in the lexer. However, when the
preprocessor isn't being used on C or C++, it doesn't make sense to
apply these restrictions.

Notably, accepting these characters avoids issues with unicode escapes
when GHC uses the compiler as a preprocessor on haskell sources.

Fixes rdar://problem/14742289

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193067 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-21 05:02:28 +00:00
Richard Smith 9a17677bb8 Per updates to D3781, allow underscore under ' in a pp-number, and allow ' in a #line directive.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191443 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-26 18:13:20 +00:00
Richard Smith 859b622769 Implement C++1y digit separator proposal (' as a digit separator). This is not
yet approved by full committee, but was unanimously supported by EWG.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191417 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-26 03:33:06 +00:00
Richard Smith 6fde25e14e Avoid a signed/unsigned comparison warning with compilers that don't know how
to handle constant expressions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191336 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-24 22:13:21 +00:00
Richard Smith 06dd2b317a Handle standard libraries that miss out the space when defining the standard
literal operators. Also, for now, allow the proposed C++1y "il", "i", and "if"
suffixes too. (Will revert the latter if LWG decides not to go ahead with that
change after all.)


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191274 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-24 04:06:10 +00:00
Eli Friedman 0f238a61be Fix use-after-free in r190980.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190984 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-19 01:51:23 +00:00
Eli Friedman d2f9308220 Make Preprocessor::Lex non-recursive.
Before this patch, Lex() would recurse whenever the current lexer changed (e.g.
upon entry into a macro). This patch turns the recursion into a loop: the
various lex routines now don't return a token when the current lexer changes,
and at the top level Preprocessor::Lex() now loops until it finds a token.
Normally, the recursion wouldn't end up being very deep, but the recursion depth
can explode in edge cases like a bunch of consecutive macros which expand to
nothing (like in the testcase test/Preprocessor/macro_expand_empty.c in this
patch).

<rdar://problem/14569770>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190980 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-19 00:41:32 +00:00
Alexander Kornienko 263cea4485 Use new UnicodeCharSet interface.
Summary: This is a Clang part of http://llvm-reviews.chandlerc.com/D1534

Reviewers: jordan_rose, klimek, rsmith

Reviewed By: rsmith

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1535

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189583 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-29 12:12:31 +00:00
Eli Friedman a601579fa0 Fix "//" comments with -traditional-cpp in C++.
Apparently, gcc's -traditional-cpp behaves slightly differently in C++ mode;
specifically, it discards "//" comments.  Match gcc's behavior.

<rdar://problem/14808126>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189515 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-28 20:53:32 +00:00
Jordan Rose 7865b8e432 Respect -Wnewline-eof even in C++11 mode.
If the user has requested this warning, we should emit it, even if it's not
an extension in the current language mode. However, being an extension is
more important, so prefer the pedantic warning or the pedantic-compatibility
warning if those are enabled.

<rdar://problem/12922063>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189110 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-23 15:42:01 +00:00
Fariborz Jahanian f0dd853bb1 ObjectiveC migrator: More work towards
insertion of ObjC audit pragmas.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188733 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 00:07:23 +00:00
Richard Smith 4ac537b0f0 C++1y literal suffix support:
* Allow ns, us, ms, s, min, h as numeric ud-suffixes
 * Allow s as string ud-suffix


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186933 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-23 08:14:48 +00:00
Michael J. Spencer 9779fdd271 Replace Count{Leading,Trailing}Zeros_{32,64} with count{Leading,Trailing}Zeros.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182675 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-24 21:42:04 +00:00
Argyrios Kyrtzidis 3b7deda713 [modules] If we hit a failure while loading a PCH/module, abort parsing instead of trying to continue in an invalid state.
Also don't let libclang create a PCH with such an error.

Fixes rdar://13953768

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182629 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-24 05:44:08 +00:00
Argyrios Kyrtzidis c50c6ff49a [Lexer] Improve Lexer::getSourceText() when the given range deals with function macro arguments.
This is a modified version of a patch by Manuel Klimek.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182055 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-16 21:37:39 +00:00
Richard Smith 8f19003769 Typo and misc comment fix.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181583 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-10 02:36:35 +00:00
Argyrios Kyrtzidis 355dae6f1b [libclang] Make sure the preable does not truncate comments.
rdar://13647445

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179907 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-19 23:24:25 +00:00
Richard Smith d4bf760d05 Add -Wc99-compat warning for C11 unicode string and character literals.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176817 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-11 18:01:42 +00:00
Richard Smith 0093e12513 When lexing in C11 mode, accept unicode character and string literals, per C11
6.4.4.4/1 and 6.4.5/1.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176780 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-09 23:56:02 +00:00
Jordan Rose 693fdfa069 Preprocessor: don't consider // to be a line comment in -E -std=c89 mode.
It's beneficial when compiling to treat // as the start of a line
comment even in -std=c89 mode, since it's not valid C code (with a few
rare exceptions) and is usually intended as such. We emit a pedantic
warning and then continue on as if line comments were enabled.
This has been our behavior for quite some time.

However, people use the preprocessor for things besides C source files.
In today's prompting example, the input contains (unquoted) URLs, which
contain // but should still be preserved.

This change instructs the lexer to treat // as a plain token if Clang is
in C90 mode and generating preprocessed output rather than actually compiling.

<rdar://problem/13338743>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176526 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-05 22:51:04 +00:00
Jordan Rose 6aad4a31b3 Preprocessor: preserve whitespace in -traditional-cpp mode.
Note that unlike GNU cpp we currently do not preserve whitespace in macros
(even in -traditional-cpp mode).

<rdar://problem/12897179>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175778 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-21 18:53:19 +00:00
Jordan Rose ed9c59f2ae Properly validate UCNs for C99 and C++03 (both more restrictive than C(++)11).
Add warnings under -Wc++11-compat, -Wc++98-compat, and -Wc99-compat when a
particular UCN is incompatible with a different standard, and -Wunicode when
a UCN refers to a surrogate character in C++03.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174788 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-09 01:10:25 +00:00
Jordan Rose 9893902ece Pull Lexer's CharInfo table out for general use throughout Clang.
Rewriting the same predicates over and over again is bad for code size and
code maintainence. Using the functions in <ctype.h> is generally unsafe
unless they are specified to be locale-independent (i.e. only isdigit and
isxdigit).

The next commit will try to clean up uses of <ctype.h> functions within Clang.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174765 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-08 22:30:22 +00:00
Jordan Rose 0ed4394874 Lexer: Don't warn about Unicode in preprocessor directives.
This allows people to use Unicode in their #pragma mark and in macros
that exist only to be string-ized.

<rdar://problem/13107323&13121362>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174081 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-31 19:48:48 +00:00
Jordan Rose 20afc2977c Fix r173881 to properly skip invalid UTF-8 characters in raw lexing and -E.
This caused hangs as we processed the same invalid byte over and over.

<rdar://problem/13115651>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173959 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-30 19:21:12 +00:00
Dmitri Gribenko cb5620c9b2 Move UTF conversion routines from clang/lib/Basic to llvm/lib/Support
This is required to use them in TableGen.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173924 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-30 12:06:08 +00:00
Jordan Rose 74c2498bb9 Don't warn about Unicode characters in -E mode.
People use the C preprocessor for things other than C files. Some of them
have Unicode characters. We shouldn't warn about Unicode characters
appearing outside of identifiers in this case.

There's not currently a way for the preprocessor to tell if it's in -E mode,
so I added a new flag, derived from the PreprocessorOutputOptions. This is
only used by the Unicode warnings for now, but could conceivably be used by
other warnings or even behavioral differences later.

<rdar://problem/13107323>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173881 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-30 01:52:57 +00:00
Jordan Rose 8094bac4e9 PR15067 (again): Don't warn about UCNs in C90 if we're raw-lexing.
Fixes a crash. Thanks, Richard.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173701 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-28 17:49:02 +00:00
Jordan Rose bfec916e5f PR15067: Don't assert when a UCN appears in a C90 file.
Unfortunately, we can't accept the UCN as an extension because we're
required to treat it as two tokens for preprocessing purposes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173622 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-27 20:12:04 +00:00
NAKAMURA Takumi b6c08a6414 Lexer.cpp: Fix a warning with ptrdiff_t on i686. [-Wsign-compare]
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173447 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-25 14:57:21 +00:00
Jordan Rose ae82c2b7b6 Clarify comment: "diagnose" is better than "warn" when emitting an error.
Thanks, Dmitri.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173400 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-25 00:20:28 +00:00
Jordan Rose b87672b124 Add a fixit for \U1234 -> \u1234.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173371 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-24 20:50:52 +00:00